Shop OBEX P1 Docs P2 Docs Learn Events
Servo control library — Parallax Forums

Servo control library

WildatheartWildatheart Posts: 195
edited 2014-03-27 15:29 in Learn with BlocklyProp
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((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

  • edited 2014-03-26 15:33
    Sorry for the slow reply.

    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
    #include "simpletools.h" 
    #include "servo.h"
    
    int main()
    {  
      high(26);
      servo_speed(12, 100);
      pause(500); 
      servo_speed(12,-100);
      pause(500);
    
      high(27);
      servo_angle(16,300);  
      pause(500);
      servo_angle(16,1500);
      pause(500);
      
      low(26);
      servo_speed(12, 0);
      pause(500);
      
      low(27);
      servo_angle(16, 900);
      pause(500);  
    }
    
  • WildatheartWildatheart Posts: 195
    edited 2014-03-26 17:25
    Thanks, Andy. Changed your pin 12 to pin 5 and your pin 16 to pin 1 on the QS board. Also increased pause(500) to pause(1000). My LED 20 & 21 operate as expected. Cycles are completed as expected but CR continues to rotate after both LED's are off. Using a good 9V battery for both the QS and the servos.
  • edited 2014-03-26 17:33
    Did the CR servo stay still for 1 second after (P26 in my code) turned off? Did it start moving again when (P27 in my code) turned off?
  • WildatheartWildatheart Posts: 195
    edited 2014-03-26 17:38
    Mostly RESOLVED. Trimmer was not properly adjusted to stop servo on servo_speed(x,0). Confusion resulted when using servo_stop(). It was thought that servo_stop() would remove all power/pulses to the CR servo and result in free wheeling, but the servo seems to continue receiving pulses that (could, if not properly trimmed) cause continuous rotation in spite of issuing a servo_stop()?
  • edited 2014-03-27 15:29
    Thanks for the update.

    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).
Sign In or Register to comment.