#!/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)]}
}
