Programming Trouble with PING and IR Navigation
DrumBum535
Posts: 9
Hello,
I've been working on a custom Boe Bot for a Engineering project for quite some time now. I have it outfited with the Crawler Kit as well as the Gripper, and on top, I added an extra bread board on standoffs to raise up the IR sensors and PING sensors. The problem I am having though is with the programing. I think I have a solid foundation so far only using the PING and IRs along with the leg servos, but for some reason, I cant figure out whats up with its motion.
Basically, my project is to have this thing navigate a simple maze, pick something up at the end of it, and then turn around and come back out the way it came.I want the program so the IRs make decisions when there is nothing in their path along with the forward judgement of the PING. The PING is not on a servo because the gripper kit is in the way, so it sits up in front. The IRs are on the Left side and Right side of the Bot. When the program starts, the Bots servos move very choppy, almost in a constant back and forth motion and it barely moves anywhere. Ive added Pauses in between different parts of the program but they only delay the choppy-ness of the servos, or give them a constant, but very weak driving force which will make it sit still on the ground.
I am by no means a programmer because this is only the second program I've ever written, but I do have a pretty good understanding of PBASIC. I have been basing it off of the program RoamingWithPING-V1.0.bs2 so far. Unfortunately when i load that program on to the Bs2, it gives a very brief movement and the program constantly restarts itself with a loud beep from the Piezo. Even when i loaded up RoamingWithIR.bs2 the program constantly restarts and the Debug window says "Program Running!" every second.
So can someone please review my current program and point things out to me so I can finally get a smooth motion from the Crawler Bot?
Thanks
**Note: All programs I listed were changed to fit my Boe Bots specs including PINs and Constants. The Project Program's PINs are all correct, but the Variables may not be needed or incorrect.
Sorry, but I had trouble attaching the code, so I just pasted it over.
I've been working on a custom Boe Bot for a Engineering project for quite some time now. I have it outfited with the Crawler Kit as well as the Gripper, and on top, I added an extra bread board on standoffs to raise up the IR sensors and PING sensors. The problem I am having though is with the programing. I think I have a solid foundation so far only using the PING and IRs along with the leg servos, but for some reason, I cant figure out whats up with its motion.
Basically, my project is to have this thing navigate a simple maze, pick something up at the end of it, and then turn around and come back out the way it came.I want the program so the IRs make decisions when there is nothing in their path along with the forward judgement of the PING. The PING is not on a servo because the gripper kit is in the way, so it sits up in front. The IRs are on the Left side and Right side of the Bot. When the program starts, the Bots servos move very choppy, almost in a constant back and forth motion and it barely moves anywhere. Ive added Pauses in between different parts of the program but they only delay the choppy-ness of the servos, or give them a constant, but very weak driving force which will make it sit still on the ground.
I am by no means a programmer because this is only the second program I've ever written, but I do have a pretty good understanding of PBASIC. I have been basing it off of the program RoamingWithPING-V1.0.bs2 so far. Unfortunately when i load that program on to the Bs2, it gives a very brief movement and the program constantly restarts itself with a loud beep from the Piezo. Even when i loaded up RoamingWithIR.bs2 the program constantly restarts and the Debug window says "Program Running!" every second.
So can someone please review my current program and point things out to me so I can finally get a smooth motion from the Crawler Bot?
Thanks
**Note: All programs I listed were changed to fit my Boe Bots specs including PINs and Constants. The Project Program's PINs are all correct, but the Variables may not be needed or incorrect.
Sorry, but I had trouble attaching the code, so I just pasted it over.
' {$STAMP BS2} ' {$PBASIC 2.5} '------------------I/O Definitions------------------ Ping PIN 0 Piezo PIN 4 ColorPal PIN 6 IRsensors PIN 15 RightIRREC PIN 11 LeftIRREC PIN 10 LeftServo PIN 13 RightServo PIN 12 Gripper PIN 14 '---------------------CON------------------------------- baud CON 119 + 32768 '--------------------VARIABLES------------------------ irDetectLeft VAR Bit 'VAR for Left IR Input irDetectRight VAR Bit 'VAR for Right IR Input pulseCount VAR Byte 'Used for measuring turns distance VAR Word 'Current Distance objective counter VAR Word 'PING cycle counter task VAR Nib 'Current task '----------------------INTIALIZATION--------------- 'DO 'FREQOUT Piezo, 500, 3000 'FREQOUT Piezo, 500, 4500 'PAUSE 300 'LOOP '-------------------MAIN--------------------------- Main: FREQOUT IRsensors, 15, 40500 'Emit 40500Hz to Left/Right IR irDetectLeft= IN10 FREQOUT IRsensors, 15, 40500 irDetectRight= IN11 counter = counter + 1 ' Increment Passive Counter IF counter > 10 THEN GOSUB Ping_Out ' Activate PING))) ENDIF 'IF (distance > 10) THEN ' Is Object Farther Than 30 cm? ' GOSUB Keep_Straight ' If Yes Go Forward 'ELSEIF (distance < 10) THEN 'ENDIF 'Allow FOR IRs TO make descision IF (irDetectLeft = 0) AND (irDetectRight = 0) AND (distance > 10) THEN 'VARYING distance, calculate in Maze later GOSUB Keep_Straight ' Objects Detected via IR, Forward ELSEIF (irDetectLeft = 0) AND (distance > 10) THEN GOSUB Keep_Straight ' Object Detected via IR Left ELSEIF (irDetectRight = 0) AND (distance > 10) THEN GOSUB Keep_Straight ' Object Detected via IR Right ENDIF IF (irDetectLeft= 1) AND (irDetectRight= 0) AND (distance < 10) THEN GOSUB Turn_Left 'No wall next to LeftIR, Left Turn ELSEIF (irDetectLeft = 1) AND (distance < 10) THEN GOSUB Turn_Left ELSEIF (irDetectRight = 0) AND (distance < 10) THEN GOSUB Turn_Left ENDIF IF (irDetectLeft = 0) AND (irDetectRight = 1) AND (distance < 10) THEN GOSUB Turn_Right 'No wall next to RightIR, Turn Right ELSEIF (irDetectLeft = 0) AND (distance < 10) THEN GOSUB Turn_Right ELSEIF (irDetectRight = 1) AND (distance < 10) THEN GOSUB Turn_Right ENDIF IF (irDetectLeft = 1) AND (irDetectRight = 1) AND (distance > 10) THEN GOSUB Keep_Straight ELSEIF (irDetectLeft = 1) AND (distance > 10) THEN GOSUB Keep_Straight ELSEIF (irDetectRight = 1) AND (distance > 10) THEN GOSUB Keep_Straight ENDIF 'counter = counter + 1 ' Increment Passive Counter 'IF counter > 10 THEN 'GOSUB Ping_Out ' Activate PING))) 'ENDIF 'IF (distance > 10) THEN ' Is Object Farther Than 30 cm? ' GOSUB Keep_Straight ' If Yes Go Forward 'ELSEIF (distance < 10) THEN 'ENDIF 'Allow for IRs to make descision '-------------------SUBROUTINES----------------------------------------- Ping_Out: ' PING))) counter = 0 ' Reset Passive Delay Counter LOW Ping ' Force PING))) Line Low PULSOUT Ping, 5 ' Activate PING))) Pulse PULSIN Ping, 1, distance ' Receive Return Pulse distance = distance ** 2257 ' Calculate Distance RETURN Keep_Straight: PULSOUT LeftServo, 850 ' Left Servo Forward Pulse Value PULSOUT RightServo, 650 ' Right Servo Forward Pulse Value 'PAUSE 10 ' Refresh Delay RETURN Turn_Left: FOR pulseCount = 0 TO 10 ' Number Of Pulses To Turn, a little more than 45 degrees PULSOUT LeftServo, 650 ' Left Servo Left Pulse Value PULSOUT RightServo, 650 ' Right Servo Left Pulse Value 'PAUSE 10 ' Refresh Delay NEXT RETURN Turn_Right: FOR pulseCount = 0 TO 10 ' Number Of Pulses To Turn, a little more than 45 degrees PULSOUT LeftServo, 850 ' Left Servo Right Pulse Value PULSOUT RightServo, 850 ' Right Servo Right Pulse Value 'PAUSE 10 ' Refresh Delay NEXT RETURN Back_Up: FOR pulseCount = 0 TO 40 ' Number Of Pulses To Backup PULSOUT LeftServo, 650 ' Left Servo Backup Pulse Value PULSOUT RightServo, 850 ' Right Servo Backup Pulse Value 'PAUSE 10 ' Refresh Delay NEXT RETURN Turn_Around: 'About 180 degree Turn Around to the Right FOR pulseCount = 0 TO 170 PULSOUT LeftServo, 850 PULSOUT RightServo, 850 'PAUSE 10 NEXT RETURN
Comments
For a start, your program may be so long that it is not refreshing the wheel servos every 20ms.
You might want to consider off loading the wheel servo refresh to a servo pal which will refresh the wheel servos every 20ms irrespective of what your program loop time is.
Just a thought.
Regards,
TCIII
If your program is resetting, your batteries are likely weak and need to be replaced. But your piezo beeper FREQOUT commands are commented out in the code you posted, so I suspect that's not the exact code you're currently running.
Per prior replies, you need to refresh your servo pulsouts regularly. Your program may be long enough so that you don't need to add the traditional "PAUSE 20". Any DEBUG statements will slow crash your servo refresh and cause the jittery motion you describe.
BTW, the goal you describe isn't particularly easy. Keep plugging and advise of your progress!
Is this for a mechanical engineering senior design?
I'm not sure how the BS2 tokenizer handles short-circuiting IF statements, or how many cycles each evaluation takes up, but as Erco notes in his post, if you're getting a restart with the example program it probably means your power source just isn't up to the task of running servos.
How are you powering the servos? A set of 4 AA's should be okay. Depending on the vintage of your BOE, be sure to set the power block jumper for the servos to Vin, not Vdd. Use FRESH alkaline cells. Don't use a wall adapter, even if you think it delivers enough current (it probably doesn't). If you are getting tired of replacing the batteries, buy a set of rechargeable alkalines (and suitable recharger). These put out 1.5 volts like the non-rechargeable kind. Alternatively, you can use 1.2V rechargeable cells if you get the BOE-Boost 1-cell addon. Parallax sells it.
Start there first, using the example code in the BOE-Bot text. Then once you prove your robot is working properly and not resetting constantly, you can look to ways to trim your code to accommodate the extra cycles from the IF tests, and properly coding for the servo refresh.
-- Gordon
The code I was reffering to was the example code RoamingWithPING-V1.0 with the Initialization beeps. My Codes sounds Loop to mimic a Siren like a Search and Rescue Bot ( the name of my project). lol
And as for progress I will hopefully be able to get some pictures up here soon.
But as for needing to refresh the servo pulses, where would I put those instead of having Pauses?
No, I'm actually apart of an Engineering Program based out of a Defense Contractor for the military.
I am using the standard 4 AA batteries, but the Jumper is currently on the side closest to label Vdd. Problem?? Ill change this if it is. I have tried to cut down the code into parts as well to diagnose but havent gotten satisfactory results, due in part to the Servo movement. Still not to sure how to allow the servos to refresh though...
Edit it as you please, theres still a lot to be done with this project. I need to incorporate a ColorPal to identify a "Victim" and also have the Gripper Pick up this "Victim". Any Suggestions?
Heres a picture of it, the ColorPal is just wraped around the back, you can see the loose wires on the side. It wont stay like that though!
Question:
Is there a way to get the Gripper to stay closed once it closes? I cant seem to figure it out. It just pulses closed every 10 counts and then lets up the power for a few seconds. I need it to hold on to something once the ColorPal recognizes it.
A few options for you: the ServoPal Mike already suggested, which can offloads the overhead of continuous pulsing for two servos, or change your servo to a high torque/lower speed type. It will have lower gearing, which won't backdrive as easily and will keep a tighter grip even if you stop sending pulsouts to it.
Gripper_Close:
FOR pulseCount 1 TO 20
PULSOUT 14, 650
PAUSE 20
NEXT
RETURN
This would hold the gripper shut?
One workaround is to add a spring or rubber band to the gripper to help close it. That way, the gripper works harder to open up (stretching the spring/band) but the spring keeps some grip on even when the servo is off.
So ive been pretty successful with programming so far, but ive come to a problem with what i want the Boe Bot to do.
Currently, I have the bot navigate a maze with the PING and IRs, and if the bot gets too close to a wall, it is set to BACK UP for a few counts and turn to the RIGHT for another few counts. The problem is that the maze has only one way in and the bot needs to turn around to leave the maze. When it does this then, I need the bot to BACK UP and turn LEFT for the same amount of counts instead of turning RIGHT which would send it back the opposite direction.......I really cant wrap my brain around this one and its been bothering me! Thanks for the help though.
**Note that Subroutine: Navigation2 was just an attempt to fix this problem and anything reamed out is unecessary at this point....unless you think it could fix the problem. :blank: