Programming ping with servos
fahad
Posts: 14
Hi i am making a boe bot for a simple navigation such as avoiding obstacles(I am only using ping sensor for this). I am using the following code. But the thing is that when I use this code in the main loop the boe bot with shaky movement and not that fast when the servos turn in left_turn: . How can I avoid this shaky and slow movement in the main loop. I want the boebot to move(fast) as well as detect changes in distance in real time. I think this is the reason why the robot is becoming slow and shaky because the robot is just reading one command at a time, the delay due to the reading changes in sensor affects the rate at which the servos turn...I wanna know how do i avoid this...I am new to programming and am making a boe bot foe navigation in a maze.
main_loop:
DO
PULSOUT leftservo, 850 'move forward
PULSOUT rightservo, 650
PAUSE 20
PULSOUT 0, 5
PULSIN 0, 1, distance3 'ping right activate
PAUSE 20
distance3 = distance3 ** 900
DEBUG HOME, DEC3 Distance3, " cm"
IF (distance3 < 5) THEN
GOSUB left_turn
ENDIF
LOOP
left_turn:
FOR pulscount= 0 TO 100
PULSOUT rightservo, 850
PULSOUT leftservo, 850
PAUSE 20
NEXT
RETURN
main_loop:
DO
PULSOUT leftservo, 850 'move forward
PULSOUT rightservo, 650
PAUSE 20
PULSOUT 0, 5
PULSIN 0, 1, distance3 'ping right activate
PAUSE 20
distance3 = distance3 ** 900
DEBUG HOME, DEC3 Distance3, " cm"
IF (distance3 < 5) THEN
GOSUB left_turn
ENDIF
LOOP
left_turn:
FOR pulscount= 0 TO 100
PULSOUT rightservo, 850
PULSOUT leftservo, 850
PAUSE 20
NEXT
RETURN
Comments