***Problem with Parallax BOE Bot for Arduino RoamingwithIR code
I am using the following setup:
1) Arduino SMD edition
2) Parallax Shield Bot kit for Arduino
3) "RoamingWithIr" code from Chapter 7 Activity 4
Problem description:
I upload the code and the robot starts to move towards an obstacle. When the robot initially detects the obstacle, it stops, then backs up BUT then it gets stuck in a never ending spin which ultimately results in a reset of the board.
I have triple checked the circuits and they are fine and work well with the test programs provided. All of the other code from the previous chapters has worked fine except for this one. I also checked for additional IR interference and there was none.
Has anyone else experienced this problem?
Thanks for any insight that you can provide.
1) Arduino SMD edition
2) Parallax Shield Bot kit for Arduino
3) "RoamingWithIr" code from Chapter 7 Activity 4
Problem description:
I upload the code and the robot starts to move towards an obstacle. When the robot initially detects the obstacle, it stops, then backs up BUT then it gets stuck in a never ending spin which ultimately results in a reset of the board.
I have triple checked the circuits and they are fine and work well with the test programs provided. All of the other code from the previous chapters has worked fine except for this one. I also checked for additional IR interference and there was none.
Has anyone else experienced this problem?
Thanks for any insight that you can provide.
Comments
Another pair of eyes can't be bad, right ?
http://learn.parallax.com/node/306
Here it is as well:
/* * Robotics with the BOE Shield - RoamingWithIr * Adaptation of RoamingWithWhiskers with IR object detection instead of * contact switches. */#include <Servo.h> // Include servo library Servo servoLeft; // Declare left and right servosServo servoRight; void setup() // Built-in initialization block{ pinMode(10, INPUT); pinMode(9, OUTPUT); // Left IR LED & Receiver pinMode(3, INPUT); pinMode(2, OUTPUT); // Right IR LED & Receiver tone(4, 3000, 1000); // Play tone for 1 second delay(1000); // Delay to finish tone servoLeft.attach(13); // Attach left signal to pin 13 servoRight.attach(12); // Attach right signal to pin 12} void loop() // Main loop auto-repeats{ int irLeft = irDetect(9, 10, 38000); // Check for object on left int irRight = irDetect(2, 3, 38000); // Check for object on right if((irLeft == 0) && (irRight == 0)) // If both sides detect { backward(1000); // Back up 1 second turnLeft(800); // Turn left about 120 degrees } else if(irLeft == 0) // If only left side detects { backward(1000); // Back up 1 second turnRight(400); // Turn right about 60 degrees } else if(irRight == 0) // If only right side detects { backward(1000); // Back up 1 second turnLeft(400); // Turn left about 60 degrees } else // Otherwise, no IR detected { forward(20); // Forward 1/50 of a second }}int irDetect(int irLedPin, int irReceiverPin, long frequency){ tone(irLedPin, frequency, 8); // IRLED 38 kHz for at least 1 ms delay(1); // Wait 1 ms int ir = digitalRead(irReceiverPin); // IR receiver -> ir variable delay(1); // Down time before recheck return ir; // Return 1 no detect, 0 detect} void forward(int time) // Forward function{ servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise servoRight.writeMicroseconds(1300); // Right wheel clockwise delay(time); // Maneuver for time ms}void turnLeft(int time) // Left turn function{ servoLeft.writeMicroseconds(1300); // Left wheel clockwise servoRight.writeMicroseconds(1300); // Right wheel clockwise delay(time); // Maneuver for time ms}void turnRight(int time) // Right turn function{ servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise servoRight.writeMicroseconds(1700); // Right wheel counterclockwise delay(time); // Maneuver for time ms}void backward(int time) // Backward function{ servoLeft.writeMicroseconds(1300); // Left wheel clockwise servoRight.writeMicroseconds(1700); // Right wheel counterclockwise delay(time); // Maneuver for time ms}
Thanks for looking at it!
The Shield Bot uses an Arduino.
Check your batteries because this often causes strange behavior.
Check your Arduino library version because it might be older.
2) Per Genetix, replace your batteries with brand new ones.
3) Double check your wirong going to your IR LEDs & receivers (sensors).
4) Try manually blocking just the left sensor (not both), then just the right sensor to note response and report back.
BTW, did your bot work properly with the "Roaming with Whiskers" program? Because the code & response is identical between the two programs, except that the sensor variable names have been changed to protect the innocent, for example:
wLeft became irLeft,
wRight became irRight
I will try all of those things.
Note that the Roaming with Whiskers code worked well for me, so not sure why this variant is not working well - will check more this weekend when I get a chance and report back.
Popped in some new batteries and all works as expected now
Thanks again everyone for all of the helpful suggestions!
Weak batteries cause all kinds of strange behavior because Servos use quite a bit of power and can drain batteries quickly. The Boe-Bot uses the Piezo-Speaker as a Start-Reset indicator.The Board of Education (BOE) on which the Boe-Bot is based also has a green power LED that lights up whenever the 5V regulator is working.
Does the Shield Bot have anything like that?
If you use your Bot a lot you might want to consider getting this:
http://www.parallax.com/product/28988
Thanks!
I hope this is the right forum section to post my question.
My BOE Shield-Bot running on Arduino Uno R3, connected by USB cable to laptop running Win 10 and running the sketch "RoamingWithIr" in:
http://learn.parallax.com/node/306
After the sketch has been uploaded in Arduino IDE, the robot moves forward for a few cm, then moves backward and turns right ~60degrees continuously.
Why is it that only the below code is executed?
else if(irLeft == 0) // If only left side detects
{
backward(1000); // Back up 1 second
turnRight(400); // Turn right about 60 degrees
}
I have reset it many times, but same thing persist.
*1st i typed out the codes, then when I encountered the problem above, I copy and paste the codes onto Arduino IDE, then uploaded and executed, but still the problem persist.
Appreciate your help.
Thank you
Edit -- I shouldn't post answers when I should be asleep. I knew your problem was with the ir sensor not the whiskers. But then I didn't.
Tom
else if(irLeft == 1) // If only left side detects
Also, get a multimeter and measure the voltage at pin 10, which is (should be) connected to IR receiver output. It should normally be high (5V).
Here's what I did next:
1) Swapped the IR LEDs > same thing, no change > moves backward and turns right ~60 degrees continuously.
2) Swapped sensors > some thing DIFFERENT happened > moves backward and turns right ~60degrees for 4 times, then moves backward and turns LEFT ~60degrees once, then repeats everything over again.
3) Dip switch at "2" position, I uploaded the sketch again, the same thing as 2) happens. Repeated 3) thrice > 2) happens.
Then at 4th try, it just moves backward and turns right ~60degrees continuously.
4) I followed 1) & 2) again > still, it only moves backward and turns right ~60degrees continuously.
Qn. 1) Chris, what's the reason that by swapping the IR LEDs and sensors, the outcome happened above?
Qn. 2) why are things back to normal?
Qn3. something wrong with sensors?
* In a room, where plenty of sun shines in.
** Both sensors do work > when I placed my hand on the left sensor, it turned right. When I placed my hand on the right sensor, it turned left.
Q. Does that offer some glue to my concerns above?
When something detected by left & right sensors > the left & right LEDs will light up and hold still for the short duration.
Perhaps post some photos of the sensors on the robot and a video of what is happening?
Agreed, something's hinky here. One of ivanhoe's previous comments says that the bot responds properly, turning left & right in response to hand gestures. Yet the problem persists...
I've said it before and I'll repeat here. Having the IR LED & receiver dangling off the Boebot breadboard invites inconsistent function. Any bump or collision changes the alignment. I think it's high time to make a bracket (3D printed or otherwise) that holds the IR LED and IR receiver in the proper orientation to each other, aiming them parallel and making sure that the receiver picks up reflected IR but not IR directly from the LED. A small black (IR-tight) bracket like that would cost pennies, but would yield priceless dividends.
As has been mentioned, the IR LEDs are a finicky so you might have to play with them to get them set properly.
I've attached the Sketch that works in my config in case you find it helpful. NOTE: You need to use the external power supply and not the USB power to run the Bot with servos.
"Hinky"? Is that a Fugitive reference?
Cheers,
Jon