keyError in python code with linuxcnc axis dictionary

More
26 Apr 2018 15:06 #109660 by tripwire
The following is taken exactly from the linuxcnc python interface example:
import linuxcnc
s = linuxcnc.stat()
s.poll()
print 'Axis 1 homed: ', s.axis[1]['homed']

But when I run this on the command line (with linuxcnc/axis running) I get the following error:
dave@DavesCNCMachine ~/linuxcnc/configs/test $ python test.py
Axis 1 homed: 
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    print 'Axis 1 homed: ', s.axis[1]['homed']
KeyError: 'homed'
dave@DavesCNCMachine ~/linuxcnc/configs/test $ 

According to the docs, 'homed' is indeed a key in the axis dictionary.
Probably a naive error, but I'm stumped.
Thanks in advance for any help!

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

More
26 Apr 2018 16:05 #109664 by dgarrett
2.7:
print "Axis 1 homed: ", s.axis[1]["homed"]
Ref: linuxcnc.org/docs/2.7/html/config/python-interface.html


master (2.8~pre):
print "Joint 1 homed: ", s.joint[1]["homed"]
Ref: linuxcnc.org/docs/master/html/config/python-interface.html


The unreleased master branch (2.8~pre) and the current branch (2.7.x)
differ. In the master branch, homing is clearly distinguished
as a joint attribute.


Users of the master branch should review:
linuxcnc.org/docs/devel/html/getting-sta...dating-linuxcnc.html

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

More
26 Apr 2018 19:41 #109684 by tripwire
Thanks very much for your reply and info! I *am* using v2.8 pre.

But...what if I need to home a gantry axis, consisting of 2 joints? (or perhaps homing the master will automatically home the slave as well?)

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

More
26 Apr 2018 19:51 #109685 by dgarrett
The following user(s) said Thank You: tripwire

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

More
27 Apr 2018 14:34 #109714 by tripwire
Thanks again for the info!

I'm again stumped on another issue in my python code. I'm getting the following error on my jog-x-plus button click.
JOG_CONT command.com !teleop bad joint_num cmd=47

Here's my python code: (Note, the JOG_CONTINOUS line throws the error while the JOG_STOP code works fine.)
 def on_jog_x_plus_pressed(self,widget,data=None):
       print 'jogging X+'
       self.c.jog(self.cnc.JOG_CONTINUOUS, False, 0, 1.0)

    def on_jog_x_plus_released(self,widget,data=None):     
       self.c.jog(self.cnc.JOG_STOP,False, 0)
       print 'stopped jogging X+'

I am using v2.8~pre so the 4 arguments should be correct
Thanks in advance for any help on this!

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

More
27 Apr 2018 15:09 #109718 by dgarrett
JOG_CONT command.com !teleop bad joint_num cmd=47

The message is poor but it means you have attempted to jog an
axis coordinate but are not in the *required* teleop mode.

In the master branch (2.8~pre) axis coordinates and joint numbers
must be handled properly for the current teleop mode.

In many situations, joint jogging is never required as one
homes the machine and all subsequent axis coordinate jogs
can be done in teleop mode.

The python interface provides:
teleop_enable()
to set/unset teleop mode.
Ref: linuxcnc.org/docs/master/html/config/python-interface.html

Commit to improve message:
github.com/LinuxCNC/linuxcnc/commit/8259...dc46e30136c6979c8e25

Note:
Some guis (notably axis) hide the distinctions of joints and
axis coordinates when using identity kinematics. When using
trivkins (identity kinematics), setting kinstype=Both can help
to clarify joint/axis coodinate usage.

For a demonstration using identity kinematics with multiple
joints assigned to a single axis coordinate (XYZY), run and
experiment with the simulation config:
Sample Configurations/sim/axis/gantry
The following user(s) said Thank You: tripwire

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

More
27 Apr 2018 15:34 #109722 by tripwire
Thanks again, dgarrett! (I did discover that if I set the joint flag to True for 'joint' the code worked. (As the teleop issue explains.)

Now I have to figure out how to get the currently-set velocity for jogging. I've tried the following which have all returned 0.0:
(s is the stat object)

self.s.current_vel
self.s.axis[0]
self.s.joint[0]

I haven't tried teleop_enable() yet. Maybe that will help.

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

More
27 Apr 2018 21:51 #109733 by newbynobi
As far as i know you can not get the jog velocity from stat.
It is a value you have to provide.

In gmoccapy i am using a glade widget to get this information from the user.

Norbert

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

More
27 Apr 2018 21:59 #109734 by tripwire
Thanks for your input, Norbert! After fiddling with this for another couple of hours, I actually *just* came to that same conclusion! Glad to have a confirmation on it.

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

More
29 Apr 2018 13:36 #109802 by tripwire
Just to make it clear for others, my working solution is the following:
In Glade, I added a HAL_HScale named "jog_speed" to set the jog speed and I have the following in my python code to access the value:
self.c.jog(linuxcnc.JOG_CONTINUOUS, 0, 0, (self.builder.get_object('jog_speed').get_value()/60))

Hope it helps.

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

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