Ping and servo question
I just picked up a BS2 homework board kit·about a month ago, went through the book and then decided to just try and·"wing" it and·throw together a robot so to speak. I think that I have done pretty well so far, I bought the boe-bot chassis,·tank tread kit, ping sensor, and fabricated my own stationary bracket for the ping.·Right now I have the robot travelling forward, when the time from ping is less than 1100 it will turn right and continue going straight. I have some other sub·routines written in my program, but are not using them yet. My problem is that my servos seem to pulse with the "radar" portion of my program. When the light on the ping sensor comes on, my servos seem to lose some power. It is not too noticeable, but you can hear it pulse and it adds a slight jerking movement. Is it because you can only run one command at a·time and thats the slight pause between running "radar" and·moving?·Sorry for·such the long post, but I appreciate the help. Also if anybody has any suggestions for how I am writing my program that would be great as this is the first one I have done.
Thanks!·
Thanks!·
Comments
'{$stamp BS2}
'{$Pbasic 2.5}
'
Variables
right PIN 1
left PIN 0
ping PIN 14
counter VAR Word
Time VAR Word
'
Initialize
PAUSE 3500
'
Main Routine
DO
GOSUB radar
IF (time > 1700) THEN
GOSUB forward 'Go Forward
GOSUB radar
ELSEIF (time < 1700) THEN
GOSUB turn_right
GOSUB radar
ENDIF ' and check again
GOSUB radar
LOOP
'
Subroutines
Back_Up:
FOR counter = 1 TO 20
PULSOUT right, 765
PULSOUT left, 500
PAUSE 20
NEXT
RETURN
Forward:
GOSUB radar
FOR counter = 1 TO 50
PULSOUT right, 500
PULSOUT left, 800
PAUSE 20
NEXT
RETURN
Radar:
PULSOUT ping, 5
PULSIN ping, 1, time
RETURN
Turn_right:
FOR counter = 1 TO 130
PULSOUT right, 740
PULSOUT left, 800
PAUSE 20
NEXT
RETURN
DO
· GOSUB Radar
· IF (time <????) THEN
··· GOSUB Back-Up
· ELSEIF (time< 1700) THEN
··· GOSUB Turn_right
· ELSE
··· GOSUB Forward
· ENDIF
LOOP·
· P.S.· I think that your code formatting is just fine and is easy to follow.· Good work so far.
Post Edited (Mikerocontroller) : 12/20/2008 6:29:26 AM GMT
Jax
'What's a microcontroller .bs2
'{$stamp BS2}
'{$Pbasic 2.5}
'
Variables
right PIN 1
left PIN 0
ping PIN 14
counter VAR Byte
Time VAR Word
'
Initialize
PAUSE 3500
'
Main Routine
Main:
GOSUB radar ' check distance
IF time > 1700 THEN GOSUB Forward ' if distance is clear go Foward
IF time <= 1700 AND time > 700 THEN GOSUB Turn_Right ' if object is detected then turn right
IF time <= 700 THEN GOSUB Back_UP ' backup if object is in front of Bot
GOTO Main
'
Subroutines
Back_Up:
FOR counter = 1 TO 20
GOSUB radar
IF time > 900 THEN GOTO Main ' return to main and make a right turn if conditions are right
PULSOUT right, 765
PULSOUT left, 500
PAUSE 18
NEXT
RETURN
Forward:
DO WHILE Time > 1700 ' keep moving until Ping senses something in the way
GOSUB radar
IF Time <= 1700 THEN GOTO Main ' keep checking distance while moving foward
PULSOUT right, 500
PULSOUT left, 800
PAUSE 18
LOOP
Radar:
PULSOUT ping, 5
PULSIN ping, 1, time
RETURN
Turn_right:
FOR counter = 1 TO 130 ' keep moving for 130 pulses
GOSUB radar
IF Time > 1700 THEN GOTO Main ' keep checking distance while turning
PULSOUT right, 740
PULSOUT left, 800
PAUSE 18
NEXT
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..
Jax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If a robot has a screw then it must be romoved and hacked into..