Motor Control

i will get straight to the point. When I use this loop:
while(1)
{
int mot1,mot2;
mot1 = 255;
mot2 = -255;
set_motors(mot1,mot2);
delay_ms(1000);
set_motors(0,0);
delay_ms(1000);
mot1 = -255;
mot2 = 255;
set_motors(mot1,mot2);
}

the robot doesn’t turn the other way after it stops. Is there any way to make the 3pi turn the other way, or is there something wrong with my robot?

Hello.

There is no delay after you set the motors turning the other direction, so the command doesn’t have time to do anything before you jump back to the start of your while loop. Try:

while(1)
{
int mot1,mot2;
mot1 = 255;
mot2 = -255;
set_motors(mot1,mot2);
delay_ms(1000);
set_motors(0,0);
delay_ms(1000);
mot1 = -255;
mot2 = 255;
set_motors(mot1,mot2);

// new code:
delay_ms(1000);
set_motors(0,0);
delay_ms(1000);
}

- Ben

Thank you very much.