Need help with Bash M-code
- spumco
- Offline
- Platinum Member
-
Less
More
- Posts: 2002
- Thank you received: 823
31 Mar 2026 16:14 #344995
by spumco
Need help with Bash M-code was created by spumco
Working on a switchable kinematics for my lathe, using the millturn example on GH.
(more here: forum.linuxcnc.org/10-advanced-configura...r-than-x-axis#344888 )
One part of the switchkins process are a pair of M-codes: M128 and M129. I gather these are used to change the axis max/min limits when the respective joints are swapped.
Problem is I don't understand the Bash language/terms/syntax well enough to make sure I'm modifying it appropriately for my config.
Here's the full M128:
#!/usr/bin/tclsh
# change axis limits to MILL limits
set switchkins_pin 3 ;# agree with inifile
set coords "x y z" ;# agree with inifile
package require Linuxcnc ;# must be before Hal
emc_init -quick
package require Hal
parse_ini $::env(INI_FILE_NAME)
# Check if correct kinematic is active
if {[hal getp kinstype.is-0] == "FALSE"} {
puts "kinematic does not match! Are you calling M128 instead of M428?"
exit 1
}
# RESTORE INI axis limits
foreach l $coords {
set L [string toupper $l]
catch {hal setp ini.$l.min_limit [set ::AXIS_[set L](MIN_LIMIT)]}
catch {hal setp ini.$l.max_limit [set ::AXIS_[set L](MAX_LIMIT)]}
catch {hal setp ini.$l.min_velocity [set ::AXIS_[set L](MAX_VELOCITY)]}
catch {hal setp ini.$l.max_acceleration [set ::AXIS_[set L](MAX_ACCELERATION)]}
}
Question(s):
1. Do I need to change (INI_FILE_NAME) to my particular ini file name, or is this some sort of 'points to the configuration's INI file regardless of name' programming thing?
2. Under #RESTORE, there is the foreach | $coords... part.
- Does this call, or otherwise ensure, everything below applies to all values after set coords "x y z" at the top?
- Does set L [string toupper $l] somehow change the lowercase "x y z" to upper-case for use in the ::AXIS_[set L]... part?
- What is "catch"?
3. Could this have been written more simply?
like: hal setp ini.x.min_limit [set ::AXIS_X(MIN_LIMIT)]
and repeated for desired axes? With no "set coords" or "foreach" or "set L" needed?
Bonus Question:
- Other than to confuse non-programmers, what purpose does this complication serve? Is the intent to make it so the end-user only has to change the coords "n n n" values and everything still works?
(more here: forum.linuxcnc.org/10-advanced-configura...r-than-x-axis#344888 )
One part of the switchkins process are a pair of M-codes: M128 and M129. I gather these are used to change the axis max/min limits when the respective joints are swapped.
Problem is I don't understand the Bash language/terms/syntax well enough to make sure I'm modifying it appropriately for my config.
Here's the full M128:
Warning: Spoiler!
#!/usr/bin/tclsh
# change axis limits to MILL limits
set switchkins_pin 3 ;# agree with inifile
set coords "x y z" ;# agree with inifile
package require Linuxcnc ;# must be before Hal
emc_init -quick
package require Hal
parse_ini $::env(INI_FILE_NAME)
# Check if correct kinematic is active
if {[hal getp kinstype.is-0] == "FALSE"} {
puts "kinematic does not match! Are you calling M128 instead of M428?"
exit 1
}
# RESTORE INI axis limits
foreach l $coords {
set L [string toupper $l]
catch {hal setp ini.$l.min_limit [set ::AXIS_[set L](MIN_LIMIT)]}
catch {hal setp ini.$l.max_limit [set ::AXIS_[set L](MAX_LIMIT)]}
catch {hal setp ini.$l.min_velocity [set ::AXIS_[set L](MAX_VELOCITY)]}
catch {hal setp ini.$l.max_acceleration [set ::AXIS_[set L](MAX_ACCELERATION)]}
}
Question(s):
1. Do I need to change (INI_FILE_NAME) to my particular ini file name, or is this some sort of 'points to the configuration's INI file regardless of name' programming thing?
2. Under #RESTORE, there is the foreach | $coords... part.
- Does this call, or otherwise ensure, everything below applies to all values after set coords "x y z" at the top?
- Does set L [string toupper $l] somehow change the lowercase "x y z" to upper-case for use in the ::AXIS_[set L]... part?
- What is "catch"?
3. Could this have been written more simply?
like: hal setp ini.x.min_limit [set ::AXIS_X(MIN_LIMIT)]
and repeated for desired axes? With no "set coords" or "foreach" or "set L" needed?
Bonus Question:
- Other than to confuse non-programmers, what purpose does this complication serve? Is the intent to make it so the end-user only has to change the coords "n n n" values and everything still works?
Please Log in or Create an account to join the conversation.
Time to create page: 0.058 seconds