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 or Create an account to join the conversation.

More
1 year 6 months ago - 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.
Last edit: 1 year 6 months ago by cmorley.
The following user(s) said Thank You: Mr. Mass

Please Log in or Create an account 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 or Create an account 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 or Create an account 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
The following user(s) said Thank You: Mr. Mass

Please Log in or Create an account 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”image missing /media/kunena/emoticons/smile.png 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 or Create an account to join the conversation.

Moderators: cmorley
Time to create page: 0.061 seconds
Powered by Kunena Forum