Weird Servo Startup sequence
Kroqigater
Posts: 7
Hello,
I have recently just gotten into working with the basic stamp. I am working on fairly simple project but as a beginner things are more difficult than they should be.
I have put together a small circuit linking the BS2 to the mini SSC II servo controller with wall warts for power. This is working out alright except that when the circuit is powered on there is a startup sequence that is a rather quick and jerky motion. I cannot have this as it will damage the art piece it is attached to when it is all assembled.
Essentially the code is supposed to be an endless loop where the servo cycles between 0 and 65 degrees, and pauses for 5 seconds at each end. However, since this is going in a storefront window it needs to power down over night. I am worried that every morning it is turned back on, the servo will freak out and possibly damage something.
I am considering a button that will put the system into sleep mode or something similar so that the startup sequence can be avoided or maybe some defensive coding that will prevent the start up sequence from even happening. Hopefully someone could give me their input as to what they would do in this situation.
Here is my code:
' {$STAMP BS2}
' Program: Scan.BS2
svo CON 0
sync CON 255
duration CON 5000
pos VAR Byte
n24n CON $418D
again:
FOR pos = 0 TO 181 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
FOR pos = 181 TO 0 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
GOTO again
I have recently just gotten into working with the basic stamp. I am working on fairly simple project but as a beginner things are more difficult than they should be.
I have put together a small circuit linking the BS2 to the mini SSC II servo controller with wall warts for power. This is working out alright except that when the circuit is powered on there is a startup sequence that is a rather quick and jerky motion. I cannot have this as it will damage the art piece it is attached to when it is all assembled.
Essentially the code is supposed to be an endless loop where the servo cycles between 0 and 65 degrees, and pauses for 5 seconds at each end. However, since this is going in a storefront window it needs to power down over night. I am worried that every morning it is turned back on, the servo will freak out and possibly damage something.
I am considering a button that will put the system into sleep mode or something similar so that the startup sequence can be avoided or maybe some defensive coding that will prevent the start up sequence from even happening. Hopefully someone could give me their input as to what they would do in this situation.
Here is my code:
' {$STAMP BS2}
' Program: Scan.BS2
svo CON 0
sync CON 255
duration CON 5000
pos VAR Byte
n24n CON $418D
again:
FOR pos = 0 TO 181 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
FOR pos = 181 TO 0 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
GOTO again
Comments
-Phil
Otherwise, "wouldn't you rather wait and be surprised"?
do you think a button linked to a sleep function would be better?
and also a function that returns the value of the servos position and starts motion from there?
last thought, for the pull down resistor, should I put it inline on P0? or should it tie P0 to ground?
Thanks again guys you have been very helpful.
Can't easily read the servo's position. One possibility to help tame the violent initial slew is to initially send long PAUSE 1000 s to your servos, such as:
for b0=1 to 10
pulsout 1,750' send servo to initial position
pause 1000
next
That will move the servo in smaller steps to the start position.
That's not the way the SSC II servo controller works, though. It takes commands via SEROUT and does the servo pulsing itself.
Kroqigator,
My approach here would be to have a push-button input to the Stamp that requests a power-down sequence. That way you have control over it and can park the servos wherever you want them. Then the Stamp program can kill its own power via, for example, an external relay.
-Phil
Suggestions
Come up with a process for parking and starting. Remember that you have control of servo power. Even though the SSC is sending a signal the servos can be off until your project is ready.
Keep track of the angular position by adding encoders to your project.
Use a servos that tracks angular position like the AX-12 or Open Servo.
This what I'm thinking:
could possibly add a second servo or maybe a pot to track position but that may be overly complicated as this is just a simple little device.
instead, i would like to add a button of some type linked to P1 and an if then sequence that checks the value of the button at the end of each travel. There is a point in the travel that would be ideal for power down because everything will be at rest. This is at the pos = 0 point.
so maybe my code could be something like,
' {$STAMP BS2}
' Program: Scan.BS2
svo CON 0
sync CON 255
duration CON 5000
pos VAR Byte
n24n CON $418D
p1 VAR Bit
again:
IF p1 = 0 THEN powerdown1
ELSE
FOR pos = 0 TO 181 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
IF p1 = 0 THEN powerdown2
FOR pos = 181 TO 0 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
GOTO again
powerdown1:
SLEEP 5
IF p1 = 1 THEN again
GOTO powerdown1
powerdown2:
FOR pos = 181 TO 0 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
GOTO powerdown1
do you guys think it is redundant?
should I have a pull up resistor on the button and link it to either my 9V logic supply or 5V servo supply?
Thanks again all have been so helpful and I cannot thank you enough!
I will be picking up my circuit from the shop later to actually test it, but I would still like to know what you think.
here it is:
' {$STAMP BS2}
' Program: Scan.BS2
' {$PBASIC 2.5}
svo CON 0
sync CON 255
duration CON 5000
pos VAR Byte
n24n CON $418D
p1 VAR Word
again:
PULSIN 0, 1, p1
IF p1 = 0 THEN powerdown1
FOR pos = 0 TO 181 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
PULSIN 0, 1, p1
IF p1 = 0 THEN powerdown2
FOR pos = 181 TO 0 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
PAUSE duration
GOTO again
powerdown1:
SLEEP 5
PULSIN 0, 1, p1
IF p1 <> 0 THEN again
GOTO powerdown1
powerdown2:
FOR pos = 181 TO 0 STEP 1
SEROUT 0, n24n, [sync,svo,pos]
NEXT
GOTO powerdown1
You can try using "pos" and an a bit variable "dir" to save the state of your device. When the program enters the 0-181 FOR LOOP, set dir to 1. Set dir to 0 when in the 181-0 FOR LOOP. pos will always contain the current position.
The state will be saved in "pos" and "dir" as long as the BS2 has power. Save the variables to EEPROM if you want to save the state when the BS2 is powered down.
Your right Mike, I do see a couple typos and ultimately your solution is more elegant. I will begin researching how to store variables to EEPROM. Thank you so much for taking the time to look at my code and thank you to everyone else for your suggestions. They are all greatly appreciated.