Society of Robots - Robot Forum

Software => Software => Topic started by: Gertlex on April 17, 2012, 11:12:25 PM

Title: Toggling power to a servo with Axon
Post by: Gertlex on April 17, 2012, 11:12:25 PM
I am powering an HS-55 micro servo directly via the Axon's regulated 5V and hardware PWM.  The servo in action can be seen below (sound not recommended :D )
 linky (http://www.youtube.com/watch?v=Bo5a3qFCYS8#)

It works except for one detail... there's enough resistance on the pushrods that are being actuated such that the servo doesn't usually get all the way back to its intended position after it's done moving.  It'll be like a single degree off and keep trying to get to center, but not able to overcome friction.  This is bad as it's wasting current, and possibly shortening the life of the servo.

What I would like to do is be able to toggle the power supply to the servo via software.  As the vid shows, the servo goes back and forth 3 times (when I press a button).  It seems I should be able to turn power on/off for the duration of this actuation.

From the Axon datasheet, I evidently do not want to use the digital IO pins (they supply 10 mA or so; servo takes about 150 mA in no-load movement).  Is there some other pin to toggle purely in software?

I suspect what will work is to have a transistor somewhere.  A digital IO going to the transistor's base (http://upload.wikimedia.org/wikipedia/commons/thumb/d/dc/Transistor2.svg/500px-Transistor2.svg.png), and splice collector/emitter into the 5V wire for the servo.  Or do I want to splice into the ground wire?

Any insights? Thanks!

Edit: It was brought to my attention that I ought to be able to disable the PWM temporarily... will have to look into this as well.

Edit2: Can the PWM be disabled by setting the pulse-width to 0? (and setting the limit to that in Project Designer as well)
It seems I might be able to pin_low(E3);... Going to test this.

Edit3: I found that the following does not work - when the button is pressed, the servo still holds position.  Do I need to disable the timer?
Code: [Select]
if(SWITCH_pressed(&button)){
// pressed
pin_low(E5);
}

if(SWITCH_released(&button)){
// released
:
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing
if(now >= (int16_t)5000){ // Goes from 0ms...5000ms
now = (int16_t)10000 - now; // then 5000ms...0ms
}

DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
act_setSpeed(&servo,speed);

}

Edit4: I found that pwmOff(E3) works, but can't turn it back on... so I'm looking at the PWM duty cycle methods.
Title: Re: Toggling power to a servo with Axon
Post by: Webbot on April 18, 2012, 06:41:44 PM
If its just a standard servo then you can stop sending it pwm, and turn it back on again, using the act_setConnected command (see the manual: for C - http://webbot.org.uk/WebbotLibDocs/27168.html#obj_27238 (http://webbot.org.uk/WebbotLibDocs/27168.html#obj_27238) for C++ then http://webbot.org.uk/WebbotLibDocs2/43888.html  (http://webbot.org.uk/WebbotLibDocs2/43888.html))

The only times this doesn't work is if there is a 3rd party board in-between your controller and the servos. Mainly coz they don't provide a similar cmd for WebbotLib to give them.
Title: Re: Toggling power to a servo with Axon
Post by: Gertlex on April 18, 2012, 06:50:20 PM
If its just a standard servo then you can stop sending it pwm, and turn it back on again, using the act_setConnected command (see the manual: for C - http://webbot.org.uk/WebbotLibDocs/27168.html#obj_27238 (http://webbot.org.uk/WebbotLibDocs/27168.html#obj_27238) for C++ then http://webbot.org.uk/WebbotLibDocs2/43888.html  (http://webbot.org.uk/WebbotLibDocs2/43888.html))
Thanks!

Quote
The only times this doesn't work is if there is a 3rd party board in-between your controller and the servos. Mainly coz they don't provide a similar cmd for WebbotLib to give them.
I had read you mention similar before... and then my brain forgot the external controllers part, and so I never tried the connection methods  :-X