How do I read current system variable into my Gcode program?

More
13 Feb 2018 02:58 #105809 by waxelson
I am trying to write a mirror polishing program that moves the polishing head on the Z-axis up and down based on the current angle of the rotating platform holding the optic to be polished. The rotating platform is Axis 6, designated as U.

I can see the DRO value of u_pos_fb update accurately. However, when I try to read the same value using #<_u> or #5426, it does not update in real time. I can read it once and after that it always has the same value. Is there a way to read u_pos_fb directly into my code?

I have configured my ini.file ENCODER_SCALE so it reads 1 for each revolution. The HAL configuration watch screen displays u_pos_fb developing a cumulative total as it runs, incrementing by one each revolution. Then I try to convert the cumulative decimal reading to degrees using this block in my program, "#<Theta> = [#<_u> - FIX[#<_u>] * 360]. I capture the decimal "tail" of the current decimal angle and multiply it it by 360 degrees. This works.

However, it only works once. No matter how many other times the block is executed in my program, it always yields the same result, even though u_pos_fb has moved on to a very different value.

Please, what am I doing wrong?

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

More
13 Feb 2018 22:17 #105841 by Grotius
Hi Waxelson,

For your question, here you see a text entry box (variable) in glade. And later i write a g-code commando in python.
 def on_y_set_position_pressed(self, widget, data=None):  
            self.entry2 = self.widgets.y_offset_label
            self.y = float(self.entry2.get_text())
            self.command.mode(linuxcnc.MODE_MDI)
            self.command.wait_complete()
            command = "G10 L20 P1 Y{0}".format(self.y)              
            self.command.mdi(command)
            print " y position set "       

next example is spindespeed variable :
def on_torch_on_pressed(self, widget, data=None):    
       self.command.mode(linuxcnc.MODE_MDI)
       self.command.wait_complete()

       command = "M3 S{0}".format(self.widgets.plasma_power.get_value())
       self.command.mdi(command)
       print " Torch on "  
       #Now it is nice to turn a torch led on.
       self.widgets.torch_on_led.set_active(True)

However, it only works once. No matter how many other times the block is executed in my program, it always yields the same result, even though u_pos_fb has moved on to a very different value.

Mostly g-code commands works only once. What i know i that for speed it wil change if you use a g-code variable.
In my project i am also testing different things with g-code variable.

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

More
13 Feb 2018 23:18 #105844 by waxelson
I think I must be caught in the divide between the realtime EMCMOT module and the non-realtime EMCIO... or more likely the non-realtime EMCTASK module where Gcode is evaluated. See the attach diagram from the LinuxCNC Developer Manual.

Simply because I can see a parameter on the AXIS display being updated "rapidly", does not necessarily mean I can read that value in realtime and act on the value via gcode, right?

I was assuming LinuxCNC would run my gcode program like a PLC would run its program: looping continuously through the code as fast as the scan time will allow and branching to different sections of the code based on the value of the central realtime parameter, in this case the value of the U-axis, the rotating optics platform.

Is there anyway to access the realtime value of a parameter in the EMCMOT module and use it to guide the

This browser does not support PDFs. Please download the PDF to view it: Download PDF

control another axis, like the Z-axis?
Attachments:

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

More
13 Feb 2018 23:45 - 14 Feb 2018 00:16 #105846 by Grotius
@Waxelson,

I did a few test's tonight. This is a button for go to home position with a variabele on the speed in the g-code.

For example, a normal user would do this for the button code : G1 X0 Y0 Z0 F5000

See example :
def on_goto_zero_pressed(self, widget, data=None): 
       self.command.mode(linuxcnc.MODE_MDI)
       self.command.wait_complete()
       
       self.widgets.program_speed.get_value()
       command = "G1 X0 Y0 Z0 F{0}".format(self.widgets.program_speed.get_value())
       
       self.command.mdi(command)       
       print " goto zero pressed "

For the widget :
def on_program_speed_value_changed(self,widget,value):   
        self.command.maxvel(self.widgets.program_speed.get_value()/60)

This code is interacting real time with command.maxvel.
So during the execution of this g-code mdi command it's real time changing.
So you can do it also on other commands.

Linux is running trough the code rapidly. But you have to use the right commands that are used for interacting with g-code.
I also mentioned, when you leave the widget's unchanged in glade you have the best output. When you describe the widget initial value's in python, you have to describe everething will it be interacting real time.

Maybe a idea for you :
I know your project is polishing mirror's. if you have a optical distance sensor like IFM sensors. (sometimes you can set the distance with a button on the sensor, this one is expensiver) then you can use also the THCUD function. I have tested this for a long time with
up and down signal. This works really good and is real time. If you need a special THCUD edition, I can compile something for you.
You can do that also yourself. The document's about that are good to do.

Is this info good for now? or not good info?

Here a list of things of what i think, you can manipulate real time without problems in your gcode :
set_adaptive_feed(int)

    set adaptive feed flag
set_analog_output(int, float)

    set analog output pin to value
set_block_delete(int)

    set block delete flag
set_digital_output(int, int)

    set digital output pin to value
set_feed_hold(int)

    set feed hold on/off
set_feed_override(int)

    set feed override on/off
set_max_limit(int, float)

    set max position limit for a given axis
set_min_limit()

    set min position limit for a given axis
set_optional_stop(int)

    set optional stop on/off
set_spindle_override(int)

    set spindle override flag

Maybe there are more. you can search : linuxcnc.org/docs/2.6/html/common/python-interface.html
Last edit: 14 Feb 2018 00:16 by Grotius.

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

More
14 Feb 2018 02:50 #105853 by waxelson
Grotius,
Thank you for your input. I haven't yet used any python code with my system; you have given me a lot to think about.

Do you think in python, code could be written to read the linuxcnc.stat object and parse it for the angular position of my rotating U-axis and then cause the Z-axis to move up and down fixed distances at specific angular trigger points?

Alternately, I could install flags on my rotating platform and then mount slot switches to trigger off the flags. One flag would make Z go up and the other would make it go down. Could I configure the Z-axis to be triggered into motion based on the state of a couple of digital inputs?

On a different topic: when I am using the AXIS GUI and I have a (PRINT, message) statement in my Gcode, where does the message show up? The documentation says it goes to "stderr", but where is that when I launched the program from a link on my Linux desktop?

Thanks for your help.
Wayne

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

More
14 Feb 2018 03:26 - 14 Feb 2018 03:47 #105854 by Grotius
Hi Waxel,

In Python you can begin with : self.stat = linuxcnc.stat()
This will bring an first eye to the linuxcnc status channel.

I have posted a clean linuxcnc template yesterday. You can start with this to do some tests.
I can help you to set things up with a few command's and test's

After that you can ask the linux status channel for every command the status channel has in it's library.
So you can ask the current position for a certain axis and set this into variable, no problem so far.

The second thing you want is to move the rotating axis U, related to the stat input value.
Okey this is a realtime accident. So you have to use a THCud function, or something like that. There are expert's walking around here that can do huge more code writing than my tiny brains would do. Then your axis is rotating. You can tune this axis, no problem.

In Python you can do everething with i/o command's. You can make a interpolation to move the z axis up and down.
So in python you can make the www. (world wide web)

On a different topic: when I am using the AXIS GUI and I have a (PRINT, message) statement in my Gcode, where does the message show up? The documentation says it goes to "stderr", but where is that when I launched the program from a link on my Linux desktop?


What i think you want to have is a confirmation (good or not good) of your output code?
If you start halmeter of halshow you can see all the variable's you have made in python for your program.
If you start linuxcnc with terminal (linux startup icon, right mouse click) , you can also see message's. They are important for
fast program execution. If there are no errors you have fast program. If you have errors, program execution wil be slower, because program does not like bug's.

"stderr" This says me nothing, never seen before hihi.
Last edit: 14 Feb 2018 03:47 by Grotius.

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

More
14 Feb 2018 04:44 #105856 by Todd Zuercher
The print command will pop up a message box at the lower right corner of the screen. And it will print in the terminal window if you started Linuxcnc from the command line.

You do realize python scripts are never real time. It probably isn't appropriate for controlling an axis. Maybe what you are trying would be better accomplished with real time hal components.

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

More
14 Feb 2018 10:42 #105910 by rodw

Do you think in python, code could be written to read the linuxcnc.stat object and parse it for the angular position of my rotating U-axis and then cause the Z-axis to move up and down fixed distances at specific angular trigger points?


The other thing that might do this (on the bleeding edge of LinuxCNC development) is the experimental external offsets branch
github.com/LinuxCNC/linuxcnc/tree/dgarr/external_offsets

I would envisage you would write a component (in C, not python) that monitored the angular position of U and changed the Z axis position via an offset. There are several example sims for you to play with but you will need to compile from source.
The following user(s) said Thank You: waxelson

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

More
14 Feb 2018 13:38 #105917 by Todd Zuercher
The external offsets branch is probably an excellent idea. However it isn't always nessisary to compile recently updated branches from source. Most new experimental builds can be installed from Buildbot using the scratch repositories. buildbot.linuxcnc.org/dev.html Usually the last 10 or so branches that have been compiled can still be easily installed with Synaptic using the Force Version option. The External Offsets Branch is still on the list right now. Here is a link to the deb files for Wheezy with the RTAI kernel.
buildbot.linuxcnc.org/dists/wheezy/scrat...fsets~a764ff2.tar.gz

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

More
14 Feb 2018 18:14 - 14 Feb 2018 18:14 #105938 by Grotius
@Hi,

I did my first test with gcode and variable. But the variable name is the problem, see error message.
Do someone knows the mistype?

Attachments:
Last edit: 14 Feb 2018 18:14 by Grotius.

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

Time to create page: 0.165 seconds
Powered by Kunena Forum