connect to scale

More
12 Nov 2015 20:22 #65185 by markder13
connect to scale was created by markder13
for a new project with vision I'm working with openCV an linuxcnc. I'm able to reconise the markers and control based upon the location of the markers with the pyton linuxcnc command
				c.mode(linuxcnc.MODE_MDI)
				c.wait_complete() # wait until mode switch executed
				c.mdi('G0 X%d Y%d Z.5' % (x_g/10, y_g/10))

However I would like to control the setting of opencv by gladevcp. How do I read the values of my scales in python file. See attached screen shot of gladevcd. the pin that are in use. I do not understand the what needs to be change in the exampel file
def on_button_press(self,widget,data=None):
        '''
        a callback method
        parameters are:
            the generating object instance, likte a GtkButton instance
            user data passed if any - this is currently unused but
            the convention should be retained just in case
        '''
        print "on_button_press called"
     
        self.nhits += 1 
        self.builder.get_object('hits').set_label("Hits: %d" % (self.nhits))

Any guidance would be helpful to get the readings for use in python.

Mark
Attachments:

Please Log in or Create an account to join the conversation.

More
13 Nov 2015 01:34 #65193 by cmorley
Replied by cmorley on topic connect to scale
Did you assign a signal callback in glade to call on_button_press()?

also a scale widget needs an adjustment widget assigned to it (with appropriate settings).
Does your scale have an adjustment?

Chris M

Please Log in or Create an account to join the conversation.

More
13 Nov 2015 05:55 #65196 by markder13
Replied by markder13 on topic connect to scale
Hi Chris,

The scale has adjustment attached. The change max value can be seen in the HAL configuration watch section. The code for this adjustment:
<object class="GtkAdjustment" id="adjustment3">
    <property name="upper">179</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>

I think the problem is with the signal callback. I tried to modify the hitcounter.py example to get reading. But this was not successful. the added scale has the following name:
<object class="HAL_HScale" id="HighH_b">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="adjustment">adjustment3</property>
                <property name="round_digits">1</property>

An modified hitcounter.py reflecting this callback function would be highly appreciated.

Please Log in or Create an account to join the conversation.

More
13 Nov 2015 16:13 - 13 Nov 2015 16:15 #65206 by newbynobi
Replied by newbynobi on topic connect to scale
Hallo Mark, (correct Name?)

with glade make a callback the adjustment of your slider to its changed value signal
and in your code get the value like this:
def on_adj_High_b_value_changed(self, widget, data = None):
    value = widget.get_value()

Maybe you have to convert the value to be used within opencv.
Does this answer your question?

May I email you if I have questions to opencv, as i am just in a middle of a project for shooting target evaluation.

Norbert
Last edit: 13 Nov 2015 16:15 by newbynobi.

Please Log in or Create an account to join the conversation.

More
13 Nov 2015 19:39 #65209 by markder13
Replied by markder13 on topic connect to scale
Dear Norbert,

Thanks for your feedback. I think I can not connect the callback in glade. Which property do I need to select. (see screen dump).
I tried several options but I did not get it working. (I use the HAL_Hscale and not the HALIO_Hscale)

I have add the UI and PY file

On openCV if you have a question please let me know, if can help

Thanks.

Mark
Attachments:

Please Log in or Create an account to join the conversation.

More
14 Nov 2015 08:01 #65229 by cmorley
Replied by cmorley on topic connect to scale
value_changed is the one to use

Please Log in or Create an account to join the conversation.

More
15 Nov 2015 08:55 #65271 by markder13
Replied by markder13 on topic connect to scale
It Works.

the correct code for pyton is:
def on_HighHb_value_changed(self, widget, data = None):
        value = widget.get_value()

Note that the _adj is not there.

My lesson learned: (and hopefully also for other newbies') the text in glade under Signals -> GtkRange -> value change in Handler box is: on_<name of widget>_value_changed is to be repeated in the python file.
See screen shoot.

Mark
Attachments:

Please Log in or Create an account to join the conversation.

More
15 Nov 2015 11:26 - 15 Nov 2015 11:28 #65276 by newbynobi
Replied by newbynobi on topic connect to scale
Hallo Mark,

glad you got it working, but your comment, the adjust is not there is not correct.
A Scale is not able to work without an adjustment!
In your ui file, you have the scale HighH_b controlling the adjustment3.

My recommendation is to rename that one to adj_HighH_b and connect your handler to the signal of the adjustment!
You may ask why, as the connection you made does work. This is only my personal experience from the work with gmoccapy. I had some strange behaviors connecting to the scale instead to the adjustments. After changing the signals handler connection from the scale to the adjustment, everythink worked as expected.

Another recommendation is to rename all widgets to "speeking" names, as in your code adjustment1, adjustment2, etc. will result in difficulties in reading and understanding it. But remember window1 must remain window1!

I attached a simple example to show what I mean.
Check the code and you will see, that all widgets and functions do have clear names, to be recognized better in code.

Norbert
Attachments:
Last edit: 15 Nov 2015 11:28 by newbynobi.
The following user(s) said Thank You: markder13

Please Log in or Create an account to join the conversation.

More
16 Nov 2015 07:52 #65313 by markder13
Replied by markder13 on topic connect to scale
Norbert,

thx. It worksfine.

Now all makes prefect sense.

Mark

Please Log in or Create an account to join the conversation.

Moderators: mhaberlerHansU
Time to create page: 0.108 seconds
Powered by Kunena Forum