qtdragon mod
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 55
- Thank you received: 36
24 Apr 2025 06:01 #326984
by Mr. Mass
qtdragon mod was created by Mr. Mass
Trying to modify qtdragon a bit and add hal pins for slides. Found an example on the forum for analog, but I need to do for encoders. Tried to redo the code, at first glance everything seems ok, values change, sliders react. But the problem appears if we change the value by encoder, say by 50%, then press the button 100%, and if after that we reduce the value by encoder again, it immediately jumps to 40% (I specified a step of 10%). As far as I understand the problem is that absolute values are used, but it is necessary to use relative values. But I am completely stuck on how to implement it in the code.
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
-
Less
More
- Posts: 7883
- Thank you received: 2131
24 Apr 2025 16:41 - 25 Apr 2025 00:29 #327002
by cmorley
Replied by cmorley on topic qtdragon mod
The problem is that the 'on_counts_value_changed' function uses the 'value' (encoder counts) as an absolute value (as you said), but you could use it as a relative value.
if new value is higher then the last value, then move up 10% higher then the current rate.
if new value is less then the last value then move down 10% from the current rate
The current rate you can get from STATUS or from the appropriate widget.
I'm sure there will be some minor details to adjust to.
if new value is higher then the last value, then move up 10% higher then the current rate.
if new value is less then the last value then move down 10% from the current rate
The current rate you can get from STATUS or from the appropriate widget.
I'm sure there will be some minor details to adjust to.
Last edit: 25 Apr 2025 00:29 by cmorley.
The following user(s) said Thank You: Mr. Mass
Please Log in or Create an account to join the conversation.
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 55
- Thank you received: 36
25 Apr 2025 14:28 #327044
by Mr. Mass
Replied by Mr. Mass on topic qtdragon mod
Found the STATUS and values for the widgets, thanks.
But how can I add the previous encoder value? I tried adding a variable and assigning the encoder value to it so that I can compare them before calling the function. But it seems that I have not figured out where exactly this variable can be written. The “init_pins” function seems to be called only once at startup. And the “_on_counts_value_changed” function is triggered only when the encoder value changes and it can be passed only the current value. Or do I think wrong and there is another way?
But how can I add the previous encoder value? I tried adding a variable and assigning the encoder value to it so that I can compare them before calling the function. But it seems that I have not figured out where exactly this variable can be written. The “init_pins” function seems to be called only once at startup. And the “_on_counts_value_changed” function is triggered only when the encoder value changes and it can be passed only the current value. Or do I think wrong and there is another way?
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
-
Less
More
- Posts: 7883
- Thank you received: 2131
26 Apr 2025 03:07 #327075
by cmorley
Replied by cmorley on topic qtdragon mod
Initialize a variable as 0 at startup.
Update that variable with the current encoder count after checking if it is higher or lower.
I think if you look at the master version 9f qtdragon you will see encoder input code with a similar idea. I am on the road so can't go in more detail right now.
Update that variable with the current encoder count after checking if it is higher or lower.
I think if you look at the master version 9f qtdragon you will see encoder input code with a similar idea. I am on the road so can't go in more detail right now.
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
-
Less
More
- Posts: 7883
- Thank you received: 2131
26 Apr 2025 21:19 #327103
by cmorley
Replied by cmorley on topic qtdragon mod
Here the initial last count variable:
github.com/LinuxCNC/linuxcnc/blob/master...ragon_handler.py#L95
here you see how it calculates the count difference:
github.com/LinuxCNC/linuxcnc/blob/master...gon_handler.py#L1927
here it decides up or down based on the calculated difference:
github.com/LinuxCNC/linuxcnc/blob/master...gon_handler.py#L1956
At the end of the function the last count is set:
github.com/LinuxCNC/linuxcnc/blob/master...gon_handler.py#L1986
github.com/LinuxCNC/linuxcnc/blob/master...ragon_handler.py#L95
here you see how it calculates the count difference:
github.com/LinuxCNC/linuxcnc/blob/master...gon_handler.py#L1927
here it decides up or down based on the calculated difference:
github.com/LinuxCNC/linuxcnc/blob/master...gon_handler.py#L1956
At the end of the function the last count is set:
github.com/LinuxCNC/linuxcnc/blob/master...gon_handler.py#L1986
The following user(s) said Thank You: Mr. Mass
Please Log in or Create an account to join the conversation.
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 55
- Thank you received: 36
27 Apr 2025 06:03 #327127
by Mr. Mass
Replied by Mr. Mass on topic qtdragon mod
Please Log in or Create an account to join the conversation.
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 55
- Thank you received: 36
27 Apr 2025 06:51 #327130
by Mr. Mass
Replied by Mr. Mass on topic qtdragon mod
One more question about HAL pin for fast/slow button. In the example there was this function to call, but it doesn't work as toggle, but as momentary.
Is it possible to make it toggle or is it only done in hal? And how can I know the status of this button? I want to change the step depending on the speed, because now at low speed the step is too big.
def togle_jog_range_l(self, state):
self.w.btn_jog_l_slow.setChecked(state)
self.w.btn_jog_l_slow.clicked.emit(state)
Is it possible to make it toggle or is it only done in hal? And how can I know the status of this button? I want to change the step depending on the speed, because now at low speed the step is too big.
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
-
Less
More
- Posts: 7883
- Thank you received: 2131
27 Apr 2025 17:18 - 27 Apr 2025 17:20 #327175
by cmorley
Replied by cmorley on topic qtdragon mod
Try this:
def togle_jog_range_l(self, state):
state = not self.w.btn_jog_l_slow.isChecked()
self.w.btn_jog_l_slow.setChecked(state)
self.w.btn_jog_l_slow.clicked.emit(state)
Last edit: 27 Apr 2025 17:20 by cmorley.
Please Log in or Create an account to join the conversation.
Moderators: cmorley
Time to create page: 0.079 seconds