BOEBOT W/PING
EGGHEAD
Posts: 26
in BASIC Stamp
Trying to make boebot drive forward until ping gets within 10 inches of an object. Not sure how to get both running together. They work fine when separated.
' {$STAMP BS2}
' {$PBASIC 2.5}
InConstant CON 890 'sets InConstant as a constant (890)
inDistance VAR Word 'sets InDistance as a variable (word)
time VAR Word 'sets label_time as a variable (word)
'counter VAR word
'FOR counter = 1 TO 122
DO
HIGH 0 'sets pin 3 high
PULSOUT 0, 500 'output pulse pin 3
LOW 1 'sets pin 4 low
PULSOUT 1, 500 'output pulse pin 4
GOSUB My_Subroutine
PAUSE 100
LOOP
My_Subroutine:
DO
LOW 15 'sets pin 15 low
PULSOUT 15, 5 'outputs a pulse on pin 15
PULSIN 15, 1, time 'recieves a pulse on pin 15
inDistance = inConstant ** time
DEBUG CR, DEC3 inDistance, " inch"
PAUSE 100
LOOP UNTIL (inDistance <= 10)
' {$STAMP BS2}
' {$PBASIC 2.5}
InConstant CON 890 'sets InConstant as a constant (890)
inDistance VAR Word 'sets InDistance as a variable (word)
time VAR Word 'sets label_time as a variable (word)
'counter VAR word
'FOR counter = 1 TO 122
DO
HIGH 0 'sets pin 3 high
PULSOUT 0, 500 'output pulse pin 3
LOW 1 'sets pin 4 low
PULSOUT 1, 500 'output pulse pin 4
GOSUB My_Subroutine
PAUSE 100
LOOP
My_Subroutine:
DO
LOW 15 'sets pin 15 low
PULSOUT 15, 5 'outputs a pulse on pin 15
PULSIN 15, 1, time 'recieves a pulse on pin 15
inDistance = inConstant ** time
DEBUG CR, DEC3 inDistance, " inch"
PAUSE 100
LOOP UNTIL (inDistance <= 10)
Comments
If you put the code between code flags,
Thank you for posting.
I think this could be accomplished a couple of ways, but I favor a sub routine approach. Break up each operation into subroutines; first a routine to check the Ping distance against the constant 10, then a routine for the servo pulse if distance is < 10. You can use another routine to stop if you want, or just use the END command.
?
Totally. You have to send a continuous string of pulses to the servo(s) to keep them turning. And when your BS-2 enters My_Subroutine, the servo pulses stop because it never exits the subroutine. Here is a pointer to an example that combines a Ping with a BoeBot.
Not really. And the BS-2 can only do one thing at a time. No parallel processing like the Propellor.
The battery voltage could be a potential issue; do you have a multi-meter to check the battery pack? Looking at the code above, I didn't see PAUSE 20(ms), which is customary for smooth servo control. This might be a dumb question too, but have you centered the servos? Sometimes they will move around instead of stopping if they have not been adjusted.
The BoeBot does not have encoders.
https://www.parallax.com/sites/default/files/downloads/28125-Robotics-With-The-Boe-Bot-v3.0.pdf
I will do that.
+1E6
I Agree, Robotics WithThe Boe-Bot is a great introduction to using BASICS language and robotics in general. A+ material
Activity #4 : Centering the Servos starting on page 49 will help make sure that the servo that your using are centered. There is code on Page 51 that is nice to save; if you have any continuous servos in a project, you can center them before getting started. I have had a robot slowly roll away because of incorrectly centered servos. haha
I will center the servo's and try again JD. By the way my program has now completely changed from what I posted originally, so don't worry about that being my issue now. What I do not understand is if I write the code:
DO
LOW 5
PULSOUT 5, 500
HIGH 6
PULSOUT 6, 500
LOOP
compile and run this code the servo's work great, so what eludes me is why when I add the PING code the servo's behave completely different.
I just wanted to give special thanks to JD, tomcrawford , and Publison. I'm new at this and frankly started a bit late in life but I'm having a lot of fun.
Everyone on this forum has went above and beyond what they need to and it is much appreciated, your contributions are definitely noticed.
FWIW, it is never too late to start. Welcome to the forum. As long as you keep trying, we'll keep helping.
You're welcome we are all happy to help. Tom said it perfectly, it's never to late and always feel free to ask.
Controlling a servo smoothly is all about timing, a 1-2ms pulse depending on direction and speed, with a 20ms pause between each pulse. The 20ms is needed so a microcontroller doesn't flood the servo with pulses create a jerky motion. I have added where you would want to add the 20ms pulses in the code below. A good method is anytime a servo is sent a pulse, wait 20ms before sending it another pulse.
1. Since you set I/O6 HIGH, PULSOUT will generate a negative-going pulse on a normally high signal. Parallax servos all like normally low signals with active high pulses.
2. You aren't leaving enough time between pulses. Each pulse should happen every 20 msec (that is, 50 Hz). Your program runs at about 300 Hz as written.
3. A pulse width value of 500 will produce a pulse of 1000 usec (that is, 1 msec.). The servos like 1300 to 1700 usec.
All in all, I am surprised your servos are doing anything.
Here is something I tried. I moved the servos to 14 and 15 since I have a Board of Education. Also, since I am using high speed servos (#900-00025), I made sure the board was jumped for Vin at the servo pins.
This keeps the pulses at just about 50 Hz, which is ideal for these servos. You don't have to set the pins high or low; they will come up LOW which is what you want. The program will ramp from medium fast one way through zero through medium fast the other way.
Edit: JD, I didn't see your comment before I wrote mine. Sorry, didn't mean to step on you.
No worries, we both are helping. There is more than one way to get a program to run, but I think pause between servo pulses will help.
No worry's. For now I have been running the program https://www.parallax.com/sites/default/files/downloads/28015-Roaming-With-PING-Simple-BASIC-Stamp-Code-v1.0.zip
I'm going to rewrite my code completely because of yours, JD's,and Publison's help I have a much better foundation to start from, but I digress. While running the above code I was still seeing that jerky motion out of the servos and when I went through the process to center the servos after connecting everything the boebot was just turning in circles. I used a small screwdriver while the program was running and turned the Pot's on the servos and it started going in the right direction. This entire time the servos were still jerky, But
If I run
DO
LOW 5
PULSOUT 5, 500
HIGH 6
PULSOUT 6, 500
LOOP
then the servos run as smooth as rain. Go figure.
Normally the BOE-Bot uses P12 and P13 for the wheel servos but in your first program you are using P0 and P1 and then you use P5 and P6 in a later program.
Is your BOE-Bot wired like on page 81 of Robotics with the BOE-Bot?
Also did you add the Piezospeaker on page 89?
I assume that you have your Ping mounted on a Ping Bracket so what pin is that servo using P15?
You might also want to check the voltage of your batteries because servos can suck them dry faster than you might think.
Robotics with the BOE-Bot, never read it. Not sure how the BOE-Bot is wired on page 81.
I looked up data sheets on the components and board and proceeded from there. My BOE-Bot has three servos, 2 continuous and one standard. My Ping which is in a Ping bracket is mounted to the standard servo which is placed in the front of the BOE-Bot.
I'm not using the code that I posted originally, I'm using code that Tomcrawford turned me onto and I'm re-writing my code, but I still am having issues with both the continuous servos and my Ping sensor not working even with correct code. I've tested both the servos and the Ping independently and they work fine, but not together.
' {$PBASIC 2.5}
Ping PIN 15
PingServo PIN 14
LeftServo PIN 13
RightServo PIN 12
rawDist VAR Word
sweepcount VAR Word
x VAR Byte
pulseCount VAR Byte
Main:
FOR sweepcount = 350 TO 1150 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
FOR sweepcount = 950 TO 550 STEP 200
FOR x = 0 TO 5
PULSOUT 14, sweepcount
PAUSE 20
NEXT
GOSUB GetSonar
NEXT
GOTO Main
GetSonar:
LOW Ping
PULSOUT Ping, 5
PULSIN Ping, 1, rawDist
IF (rawDist < 600) THEN
IF (sweepcount < 750) THEN
GOSUB Turn_Left
ELSEIF (sweepcount > 750) THEN
GOSUB Turn_Right
ELSE
GOSUB Back_Up
ENDIF
ELSE
GOSUB Forward_Pulse
ENDIF
RETURN
Forward_Pulse:
FOR pulsecount = 0 TO 5
PULSOUT LeftServo, 850
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Left:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 650
PULSOUT RightServo, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 10
PULSOUT LeftServo, 850
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 3
PULSOUT LeftServo, 750
PULSOUT RightServo, 750
PAUSE 20
NEXT
FOR pulseCount = 0 TO 7
PULSOUT LeftServo, 650
PULSOUT RightServo, 850
PAUSE 20
NEXT
RETURN