qtdragon mod

More
1 year 6 months ago #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 to join the conversation.

More
1 year 6 months ago #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.

Please Log in to join the conversation.

More
1 year 6 months ago #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?

Please Log in to join the conversation.

More
1 year 6 months ago #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.

Please Log in to join the conversation.

More
1 year 6 months ago #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

Please Log in to join the conversation.

More
1 year 6 months ago #327127 by Mr. Mass
Replied by Mr. Mass on topic qtdragon mod
Oh thanks a lot, your code example was very helpful. I just started learning python and my level so far is “monkey see, monkey do” Without a concrete example it's hard for me to understand exactly how to do it. Now I can find my mistake, I tried it for one slider, the values are changed and saved.

Please Log in to join the conversation.

More
1 year 6 months ago #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.
Code:
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 to join the conversation.

More
1 year 6 months ago #327175 by cmorley
Replied by cmorley on topic qtdragon mod
Try this:
Code:
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)

Please Log in to join the conversation.

More
11 months 1 week ago #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:
Code:
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"] = 0

It seems to work, but only once at startup. How can I make this function run continuously?

Please Log in to join the conversation.

More
11 months 1 week ago #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:

Code:
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

Please Log in to join the conversation.

Time to create page: 0.055 seconds
Powered by Kunena Forum