User Defined M-code M1xx Help

More
20 Mar 2015 23:40 #57035 by Todd Zuercher
I am really proving to myself that I have no programing skills what so ever.

I am trying to build a custom M-code that will read the current value of 2 hal pins, subtract one from the other, then setp the difference between them to "offset.0.offset."

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

More
21 Mar 2015 01:44 #57039 by dgarrett
An example script follows.
Notes:
1) the M file must be named with a capital M
2) the M file must be executable (chmod +x Mfilename)
3) the M file must be located according to the rules
see the info on [RS274NGC]USER_M_PATH
in:
www.linuxcnc.org/docs/2.7/html/config/ini_config.html
4) the M file must exist before starting LinuxCNC
Edits:
1) replace pin1_name with the name of your pin1 input
2) replace pin2_name with the name of your pin2 input
3) replace outpin_name with the name of your output pin (offset.0.offset)
4) remove or comment out the 'puts' lines when it is tested and working
#!/usr/bin/tclsh
set inpin_1  pin1_name
set inpin_2  pin2_name
set outpin   outpin_name
#----------------------------------------------------------
package require Hal
set inpin_1_value [hal getp $inpin_1]
set inpin_2_value [hal getp $inpin_2]
set diff [expr $inpin_1_value - $inpin_2_value]

puts "inpin_1= $inpin_1  inpin_1_value= $inpin_1_value"
puts "inpin_2= $inpin_2  inpin_2_value= $inpin_2_value"
puts "outpin = $outpin   outpin before=[hal getp $outpin]"
hal setp $outpin $diff
puts "outpin = $outpin   outpin after=[hal getp $outpin]"

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

More
21 Mar 2015 02:39 #57040 by Todd Zuercher
It works, thank you.

Just curious, what do the puts do?

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

More
21 Mar 2015 02:48 #57041 by dgarrett

Just curious, what do the puts do?


puts --> print to stdout, you will see them if you start from a terminal which is
almost always the best way to debug

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

Time to create page: 0.066 seconds
Powered by Kunena Forum