#%TITLE% mvc.mac
#%NAME%
# Move a motor continuously towards its limit switches
#
#%CATEGORY% Positioning
#%END%
def mvc '{
local motmne direction which_limit key
if ($# < 2) {
print "Usage: mvc motor direction"
print " direction could be + (or 1, upper limit) or - (or 0, lower limit)"
exit
}
motmne = "$1"
direction = "$2"
motnum = motor_num(motmne)
if (motnum == -1) {
print "Invalid Spec motor : " motmne
exit
}
if (direction == "+" || direction > 0) {
direction = 1
which_limit = "upper limit"
} else if (direction == "-" || direction <= 0) {
direction = 0
which_limit = "lower limit"
} else {
print "Invalid direction ; should be + (or 1, upper limit) or - (or 0, lower limit)"
exit
}
printf("hit any key to start move to %s\n", which_limit)
while( (key=input(-1)) == "" ) {}
sleep(1)
_mvc(motmne, direction, key)
}'
def _mvc(motmne, direction, key) '{
global _MVC_CONTINUE_MOVING
local motnum backlash pos waitkey
motnum = motor_num(motmne)
if (motnum == -1) {
return
}
_MVC_CONTINUE_MOVING = 1
backlash = motor_par(motnum, "backlash") / motor_par(motnum, "step_size")
if (direction == 1) {
# upper limit
pos = user(motnum, get_lim(motnum, 1)) - backlash
} else {
pos = user(motnum, get_lim(motnum, -1)) + backlash
}
if (key != "") {
waitkey = 1
} else {
waitkey = 0
}
A[motnum] = pos
move_em
while ((_MVC_CONTINUE_MOVING == 1) && (wait(0x20))) {
if (waitkey == 1) {
key = input(-1)
if (key == "") {
break
}
while (input(-1)) {}
print "."
}
sleep(0.1)
}
stop(1)
}'
|