View Single Post
  #4   Spotlight this post!  
Unread 06-02-2011, 15:28
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
Re: how do you code a servo to run continuously

http://www.wbrobotics.com/javadoc/ed...ilibj/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:

Code:
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!
Reply With Quote