X2 with servos

I have my code set up as one of the three push buttons to do the function listed below and for some reason.When the button is pushed it justs does the top servo button off the button pressed once. After multiple times pushed it slowly has the bottom servo creak slowly to its position. And I want it to do it in one motion just like he top servo and the same time the button is pressed for the top servo.but when the top servo comes down,which it does after the delay_ms(1650)

void servodown()
{
   //delay_ms( 10 );



       
            // Two servos
            unsigned char bottom,top;
         int i=0;
            // Initialize the servo system
            servo_init();

            // Define our servos to use PD7 and PD6
            bottom  = servo_define(_SFR_IO_ADDR(DDRD), _SFR_IO_ADDR(PORTD), 7);
         
            top  = servo_define(_SFR_IO_ADDR(DDRD), _SFR_IO_ADDR(PORTD), 6);
            // Turn them both on
         servo_active(top);
            servo_set(top, 2100);        //go down to get block
         delay_ms( 1650);
         servo_inactive(top);
            servo_active(bottom);
         servo_set(bottom, 1000); //close arm on block
         delay_ms( 1650);
         servo_inactive(bottom);
         

           
            
         

      
   // delay_ms( 10 );

   
}

How are you powering your servos and have you read my post to you about servo power in your programming problems thread?

There’s an easy way narrow down what the issue might be:

  1. Run your code with only the bottom servo plugged in (i.e. unplug the top servo from your X2). Does it do what it’s supposed to when the button is pushed? This test is successful, it is an indication that you are having a power issue. The X2’s onboard voltage regulator is not really designed to power servos, especially if they are straining.

  2. If not, unplug the bottom servo and plug in the top servo where the bottom one was. Does this servo behave as you would expect the bottom servo to behave when the button is pushed? If this test is successful, it might be an indication that you have a problem with your bottom servo.

If neither servo works well while plugged into the bottom servo’s port, then it’s possible there’s a problem with your code, but I don’t want to spend much time looking for a problem in your code until there’s a strong reason to think one might be there.

- Ben

I replaced the bottom servo code part with the top servo name and I/O.And it did the same thing. It went up slowly.When the button was pressed it moved only 1/3 of its requested distance, so I increased the delay and it went smoothly like this

  // initiatlize servos
           unsigned char top;
			// Initialize the servo system
            servo_init();

            // Define our servo to use PD6
            top  = servo_define(_SFR_IO_ADDR(DDRD), _SFR_IO_ADDR(PORTD), 6);
            // Turn them both on
			servo_active(top);
            servo_set(top, 510);        //go up with block
			delay_ms( 10050);
			servo_inactive(top);

To add to that the bottom servo is very smaller. So do you know if something similar has to be done or since the servor is smaller, that the range values from min to max must be different?

I have no idea, it all depends on your particular servo. Some servos can rotate more than one turn. You need to either do some tests on your servos or find some specs on them. You should also figure out how much current your servos are pulling because, given the absence of your response to my questions, I suspect you are not powering them correctly and this could be the source of your problems. You could spend hours trying to debug perfect code if your power supply is insufficient (and the X2 in its default state is probably insufficent for powering two straining servos).

- Ben

Well I switch the code up and was just powering one servo and that was the top servo and it went in one motion fine, just had to extend the delay. But then I just changed the port to the other servo pin(which is a much smaller servo,but with metal gears instead of plastic) and it didn’t happen in one motion. You think that is a power issue?

You were right it was a power issue. For some reason when I tried the button this morning. It worked without any problems. But our batter was recharged overnight.