Servo control library
Wildatheart
Posts: 195
In the servo control library, servo_angle works to set the angle for standard servos. Also, servo_speed works to set the speed for the continuous rotation servos, and servo_speed(x,0) stops CR servo rotation.
If the CR servo cycle has ended, then the standard servo cycle started, the CR servo begins non stop rotation.
I am wondering if anyone has example code for both standard servo and continuous rotation servo code operating in the same program.
if((x > 100) && (x < 201) && (y > 100) && (y < 201)) // Position 12 - 3 { //if(Set == 1) return; high(20); servo_speed(5, 200); pause(900); servo_speed(5,-1); pause(900); servo_speed(5,0); pause(200); Set = 1; return; } if((x > 100) && (x < 201) && (y >= 0) && (y < 100)) // Position 3 - 6 { //if(Set == 1) return; high(21); servo_angle(1,100); pause(100); servo_angle(1,200); pause(10); Set = 1; return; }
If the CR servo cycle has ended, then the standard servo cycle started, the CR servo begins non stop rotation.
I am wondering if anyone has example code for both standard servo and continuous rotation servo code operating in the same program.
Comments
Let's try a test. This code is working fine on my ActivityBot, with the continuous rotation servo and standard servos working independently of each other. Try updating the pin numbers, and let's see if it works on your setup. Here is the expected sequence (with all servo motions separated by 1/2 second pauses for verification).
(1) P26 light on
(2) Continuous rotation (CR) servo counterclockwise.
(3) CR clockwise
(4) P27 on
(5) Standard (STD) servo to 30 degrees
(6) Std servo to 150 degrees
(7) P26 light off
(8) CR servo to zero speed
(9) P27 light off
(10) Std servo to 90 degrees
If you call servo_stop, it should stop the cog, and all servo signals go away. If you call anything else with servo_ in the name after that, it'll restart the cog, and resume where it left off.
If you want to disable the control signal to a servo connected to a particular pin but leave the rest running, you can use servo_set(pin, 0) ...where pin is the number of the I/O pin connected to the servo you want to release.
Andy
P.S. For releasing the servo, make sure to use servo_set(pin, 0), not servo_speed(pin, 0).