qtdragon mod
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 56
- 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
- Away
- Moderator
-
Less
More
- Posts: 7239
- Thank you received: 2107
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: 56
- 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
- Away
- Moderator
-
Less
More
- Posts: 7239
- Thank you received: 2107
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
- Away
- Moderator
-
Less
More
- Posts: 7239
- Thank you received: 2107
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: 56
- 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: 56
- 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
- Away
- Moderator
-
Less
More
- Posts: 7239
- Thank you received: 2107
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.
- Mr. Mass
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 56
- Thank you received: 36
21 Nov 2025 12:09 #338881
by Mr. Mass
Replied by Mr. Mass on topic qtdragon mod
I came back to this topic again, and I had a new idea. I want to make a semaphore thingy using RGB LEDs. I used 3 OUT FLOAT, which I connected to PWM LEDs. The hardware works fine, the colors change, but I'm stuck on how to write the function correctly. Here's what I came up with:
It seems to work, but only once at startup. How can I make this function run continuously?
def init_pins(self):# status LED pins
pin = QHAL.newpin("led-red", QHAL.HAL_FLOAT, QHAL.HAL_OUT)
pin.value_changed.connect(lambda: self.status_led_changed())
pin = QHAL.newpin("led-green", QHAL.HAL_FLOAT, QHAL.HAL_OUT)
pin.value_changed.connect(lambda: self.status_led_changed())
pin = QHAL.newpin("led-blue", QHAL.HAL_FLOAT, QHAL.HAL_OUT)
pin.value_changed.connect(lambda: self.status_led_changed())
def status_led_changed(self):
if STATUS.is_man_mode():
print("status is manual mode", STATUS.is_man_mode())
self.h["led-red"] = 255
self.h["led-green"] = 0
self.h["led-blue"] = 0
elif STATUS.is_auto_mode():
print("status is auto mode", STATUS.is_auto_mode())
self.h["led-red"] = 0
self.h["led-green"] = 255
self.h["led-blue"] = 0It seems to work, but only once at startup. How can I make this function run continuously?
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
-
Less
More
- Posts: 7239
- Thank you received: 2107
21 Nov 2025 17:20 - 21 Nov 2025 17:27 #338911
by cmorley
Replied by cmorley on topic qtdragon mod
Setting 'value-changed' callback functions on output pins is not the thing to do.
'value-changed' only makes sense with input pins.
You should create a STATUS callback for manual and auto mode changes that change the LEDS.
Here is some details:
linuxcnc.org/docs/devel/html/gui/gstat.h...tension_code_pattern
Something like this:
'value-changed' only makes sense with input pins.
You should create a STATUS callback for manual and auto mode changes that change the LEDS.
Here is some details:
linuxcnc.org/docs/devel/html/gui/gstat.h...tension_code_pattern
Something like this:
def init_pins(self):# status LED pins
pin = QHAL.newpin("led-red", QHAL.HAL_FLOAT, QHAL.HAL_OUT)
pin = QHAL.newpin("led-green", QHAL.HAL_FLOAT, QHAL.HAL_OUT)
pin = QHAL.newpin("led-blue", QHAL.HAL_FLOAT, QHAL.HAL_OUT)
STATUS.connect("mode-manual",lambda w: self.set_manual_leds())
STATUS.connect("mode-auto",lambda w: self.set_auto_leds())
def set_manual_leds(self):
print("status is manual mode", STATUS.is_man_mode())
self.h["led-red"] = 255
self.h["led-green"] = 0
self.h["led-blue"] = 0
def set_auto_leds(self):
print("status is auto mode", STATUS.is_auto_mode())
self.h["led-red"] = 0
self.h["led-green"] = 255
self.h["led-blue"] = 0
Last edit: 21 Nov 2025 17:27 by cmorley.
Please Log in or Create an account to join the conversation.
Moderators: cmorley
Time to create page: 0.147 seconds