#!/usr/bin/tclsh # Author: Ferdi Franceschini (ffr@ansto.gov.au) # Creates fake DMC configuration files based on the instrument # configuration file. # Use this to create an array of named parameters to initialise motors. proc params {args} { upvar 1 "" x; if [info exists x] {unset x} foreach {k v} $args {set x([string tolower $k]) $v} } proc usage {} { puts "mkSimAxes.tcl INSTNAME"; puts "INSTNAME is the instrument name (eg wombat, echidna)" } source loadConfig.tcl # This implementation of the "Motor" command stores the # configured motor parameters in an array named # after the motor. proc Motor {name type par} { global motors; upvar #0 $par arr upvar #0 $name param_arr upvar #0 ${name}_status status array set param_arr [array get arr] array set status [list position "" home "" upperLim "" lowerLim "" homeTest NOTDONE limitTest NOTDONE] lappend motors $name } proc mkSimMotor {args} { foreach m $args { upvar #0 $m axis; puts $axis(host); } } proc mkSimAxes {instrument} { global IPtoContName motors ContList simConts; puts [array get IPtoContName]; puts $motors; foreach c $ContList { set simFile($c) [open ${c}_sim.tcl w]; } foreach m $motors { upvar #0 $m motor; set nm $motor(axis); set ${nm}Pos 0; set ${nm}stepsperx 20125; set speed [expr $motor(stepsperx) * $motor(maxspeed)] set acc [expr $motor(stepsperx) * $motor(maxaccel)] set dec [expr $motor(stepsperx) * $motor(maxdecel)] set lolim $motor(hardlowerlim) set uplim $motor(hardupperlim) if [ info exists motor(absenc) ] { set enPos $motor(absenchome); set enCnts $motor(cntsperx); } else { set enPos 0; set enCnts $motor(stepsperx); } # MVTYPE = PA (move to target),PR (relative move), JG (move until limswitch or stop cmd) puts $simFile($IPtoContName($motor(asyncqueue)-$instrument)) "array set $nm \[\list SC 1 TD 0 TP $enPos BG 0 ST 0 SP $speed AC $acc DC $dec cntsperx $enCnts stepsperx $motor(stepsperx) PA 0 TS 44 MVTYPE unknown LOLIM $lolim UPLIM $uplim ABSHOME $enPos ATLIM false\]"; # eval "lappend $IPtoContName($motor(host))_motors $m"; } foreach c $ContList { close $simFile($c); } } proc main {instrument args} { cd ../sics/server; loadConfig $args; cd ../../fakeDMC; mkSimAxes $instrument; } if {$tcl_interactive==0} { puts "arguments = $argv" main $argv config/motors/motor_configuration.tcl; }