Log in

View Full Version : how do you code a servo to run continuously


tjakowenko
05-02-2011, 17:27
We are using a servo to move an arm and want to command the servo to turn until triggered to stop. We're not sure how to do this using either set() or setAngle. Those commands will move the motor a fractional rotation, but not spin continuosly. Can someone provide a little insight as to command a servo from a pwm output to turn continuously, at different rates of speed and in different directions?

Thanks in advance...

BornaE
05-02-2011, 19:03
There are 2 types of servo's,
Standard ones, and Continuous rotation servos.

Standard servos can only do ~180 degrees of motion.(some have more range some have less)
so each PWM value corresponds to a position of the servo horn.

Continuous rotation servos, as the name implies, can rotate continuously. Each PWM servo corresponds to a rotation speed.

There is no way of making a regular servo rotate continuously.

McGurky
05-02-2011, 19:10
well there are actually ways to modify the servo to rotate continuously.


Unfortunately due to <R47>, you may not legally modify a servo.

however, you may infact be able to find a continuous rotation servo on servocity.com or other sites that meets the 4W power requirements.


Good luck

ianonavy
06-02-2011, 15:28
http://www.wbrobotics.com/javadoc/edu/wpi/first/wpilibj/PWM.html

My team was having a similar issue. We decided to replace the continuous servo with a motor, but we had an untested idea to program a continuous rotation servo. I believe that there is a setSpeed(double speed) method in the PWM class, which the Servo class extends. If there isn't one, you'll have to play around with setRaw(int value). This is the code I found in the library itself:


final void setSpeed(double speed) {
// clamp speed to be in the range 1.0 >= speed >= -1.0
if (speed < -1.0) {
speed = -1.0;
} else if (speed > 1.0) {
speed = 1.0;
}

// calculate the desired output pwm value by scaling the speed appropriately
int rawValue;
if (speed == 0.0) {
rawValue = getCenterPwm();
} else if (speed > 0.0) {
rawValue = (int) (speed * (getPositiveScaleFactor()) +
(getMinPositivePwm()) + 0.5);
} else {
rawValue = (int) (speed * (getNegativeScaleFactor()) +
(getMaxNegativePwm()) + 0.5);
}

// send the computed pwm value to the FPGA
setRaw(rawValue);
}


This method is actually meant to be used with speed controllers, but in theory it should work with a continuous rotation servo. Once again, we've never tested this, so it's up to you whether or not you want to try it. If you do, please post the results as I think it could benefit a lot of people.

Good luck!

tjakowenko
06-02-2011, 22:00
Thanks for the insight. We have been able to usine the HiTech motor on a application that only move 120 degrees.