I am trying to write a script that controls a servo based on the input from a sensor.
The servo is supposed to slowly decrease until the sensor shows a specific voltage. then it should hold that position. if the voltage dips it should continue decreasing.
what happens is that it all works. it will slowly decrease til the voltage is reached and holds the position. when the voltage drops instead of continuing to decrease until the voltage increases it suddenly reports nothing for the position of the servo and so the minus puts 100 instead of the servo position minus 100. The servo will not have moved.
stepping through the program shows that the correct position is being put on the stack then it is replaced with nothing when the minus command is passed. so the next number on the stack is 100.
restarting and going through the sequence repeats.
5 is an analog voltage sensor 0 to 5 volts
0 is the servo
100 6000 0 servo #sets the starting position begin 5 get_position 800 less_than if 0 get_position minus 100 #take the servo position subtract 100 returns a negative value over negate #makes the servo position positive 0 servo else 0 get_position dup 0 servo endif rot drop repeat