Shop OBEX P1 Docs P2 Docs Learn Events
Weird Servo Startup sequence — Parallax Forums

Weird Servo Startup sequence

KroqigaterKroqigater Posts: 7
edited 2010-11-09 09:05 in BASIC Stamp
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

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-11-03 15:49
    Try adding a 4.7K pull-down resistor to P0. This will prevent errant data from going to the servo when the Stamp is in reset during startup.

    -Phil
  • KroqigaterKroqigater Posts: 7
    edited 2010-11-03 15:55
    Awesome thank you! I will try that. Any suggestions for a fix with the coding?
  • ercoerco Posts: 20,256
    edited 2010-11-04 13:11
    In addition to Phil's resistor, you'll want your code to "park" your servos at powerdown to the same initial position they expect to be at powerup. At powerup, they will rapidly slew from wherever they are to the first commanded position in your code. Avoid that ugly jump by making sure that everything starts and finishes in the same "home" position.

    Otherwise, "wouldn't you rather wait and be surprised"? :)
  • KroqigaterKroqigater Posts: 7
    edited 2010-11-04 17:19
    well the thing is this setup is going to be turned on and off at the whim of these retail people. so I am not sure as to how the chip will be able to "park" if it is just turned off whenever they are leaving.

    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.
  • ercoerco Posts: 20,256
    edited 2010-11-04 17:57
    P0 to ground for a pulldown resistor.

    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.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-11-04 19:21
    Erco,

    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
  • ercoerco Posts: 20,256
    edited 2010-11-04 19:30
    @PhiPi: Thanks, I did miss the part where Kroqigator said he was using the SSC-II. As always, thanks for keeping me on my toes! And an excellent call on the power down sequence. Another alternative to homing the servos at power down would be to WRITE their current locations to EEPROM at power down, then READ them back at powerup.
  • schillschill Posts: 741
    edited 2010-11-04 19:46
    If there's a significant amount of torque applied to the servos when power is off, they may shift away from their original off location (creep) before it's turned on again (this depends a lot on the servos in addition to the load). This would mean that the stored values would no longer be valid. It all depends on the mechanics of the actual device.
  • ercoerco Posts: 20,256
    edited 2010-11-04 20:20
    @schill: Good point, the no-power static holding torque varies between servos. Even servos of similar size can have different internal gearing, which affects this. If the static load from gravity or other forces back-drives the servo, then choosing a home location at the eventual likely rest position (lowest point, servo travel limit or mechanical stop) would be a good choice for powerup & power down.
  • Mike GMike G Posts: 2,702
    edited 2010-11-05 07:33
    This is always a concern with standard RC servos since standard servos do not know their angular position or at least they can't tell the microcontroller.

    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.
  • KroqigaterKroqigater Posts: 7
    edited 2010-11-05 13:35
    Ok this is all great advice, thanks guys!

    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!
  • KroqigaterKroqigater Posts: 7
    edited 2010-11-05 13:53
    Or maybe I should use PULSEIN?
  • KroqigaterKroqigater Posts: 7
    edited 2010-11-05 14:25
    ok i made some changes but I am not sure if this format will behave as I expect it to. could someone please check it out and let me know what you think?

    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
  • Mike GMike G Posts: 2,702
    edited 2010-11-07 07:49
    It looks like your code will always executes "powerdown1:" unless you have something connected to PIN 0 besides the SSC.

    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.
  • KroqigaterKroqigater Posts: 7
    edited 2010-11-09 09:05
    Mike G wrote: »
    It looks like your code will always executes "powerdown1:" unless you have something connected to PIN 0 besides the SSC.

    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.
Sign In or Register to comment.