Society of Robots - Robot Forum
Software => Software => Topic started by: Miles on January 30, 2009, 05:25:49 AM
-
Hi, i have built the $50 robot and all is fine, but i just want to know something in relation to the code.
To make the robot go forward is:
servo_left(25);
servo_right(44);
But what number do i have to replace either number to make to servos stop rotating? e.g Servo_left(???)
Thanks,
-
if you want to stop the servo, just don't call the function [servo_left\right] =)
or try to send 35 or 34 to the function. e.g servo_left(35)
-
Ok thanks, i think taking out the command may be easier.
This is my situation:
LED_on();//turn LED on
while(1)
if(sensor > 90)
{//go forward
servo_left(25);
servo_right(44);
}
else if(sensor < 80)
{//go backward
servo_left(44);
servo_right(25);
else
{//do nothing
servo_left(35);
servo_right(35);
}
Could i just replace the last bit with
else
{
LED_off();
}
or something like that? If i were to have the LED_off() in the last bit would i need to move the LED_on() bit at the start to somewhere below the while(1) part?
-
you dont need the last 'else' because if sensor data between 80-90 the robot do nothing.
if you want that the led will turn off when your robot stops and led on when robot in moving, try next code..
sorry about my English, i hope you understand me.
while(1)
{
if(sensor > 90)
{//go forward
servo_left(25);
servo_right(44);
LED_on();
}
else if(sensor < 80)
{//go backward
servo_left(44);
servo_right(25);
LED_on();
}
else
{//do nothing
LED_off();
}
}
-
If you put the servos to their center positions they will stop. Please try using the forumla included in the code at the bottom
-
Great, thanks for all of the replies you really helped me out