I am part of FTC Team 7828 the Robo Ducks. I have been not able to figure out how to program servos during autonomous. Anyone know how to do that? If, so how would you program that for RobotC?
First of all you need to know if you’re using standard servos or continuous rotation servos. And then make sure you define them accordingly in your motor and servo setup. If you’re unsure, you can tell by manually turning the servo. If it only goes part way around, it’s a “standard” servo. If you can spin it all the way around continuously, then it’s a continuous rotation servo.
To move a standard servo to particular position, you simply assign a position to the servo like this:
servo[servo1] = 160; // changes the position of servo1 to 160
A continuous rotation servo is a little different. The value for a continuous rotation servo is actually a speed and direction indication.
A value of 127 is “neutral”. Values 0 - 126 indicate the reverse speed, and 128 - 255 indicate forward speed. I believe you need to get several values away from 127 before the servo actually starts to turn though.
servo[servo1] = 90; // spin in reverse fairly slowly
servo[servo1] = 150; // spin forward fairly slowly
servo[servo1] = 127; // stop spinning
Note that continuous rotation (CR) servos will not hold their position when you “stop” them. So if, for example, you were using it to wind something up, once you assign a value of 127, it would allow the mechanism to unwind if there is a force applied.
Also, in autonomous programming, you’ll want to wait a short time after setting a standard servo value to give it time to reach its position. Experimentation can tell you how long to wait, but waiting for 1 second is a good starting point.
And, always remember that the help in RobotC can be very helpful.