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?
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.
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.