Shop OBEX P1 Docs P2 Docs Learn Events
***Problem with Parallax BOE Bot for Arduino RoamingwithIR code — Parallax Forums

***Problem with Parallax BOE Bot for Arduino RoamingwithIR code

jimtjimt Posts: 5
edited 2014-09-15 11:36 in Robotics
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.

Comments

  • ValeTValeT Posts: 308
    edited 2014-09-09 17:03
    I don't work with this specifically, but if you could post your code, I would love to take a look at it.

    Another pair of eyes can't be bad, right :)?
  • jimtjimt Posts: 5
    edited 2014-09-09 17:07
    Code is directly from kit documentation found here:

    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!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-09-10 10:35
    attachment.php?attachmentid=78421&d=1297987572
  • GenetixGenetix Posts: 1,749
    edited 2014-09-10 11:50
    The Boe-Bot uses a BASIC Stamp 2, not an Arduino.
    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.
  • ercoerco Posts: 20,256
    edited 2014-09-10 16:19
    1) Double check your code (especially variable names, brackets and semicolons) inside void loop(). Best to copy & paste than type in manually.
    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
  • jimtjimt Posts: 5
    edited 2014-09-11 09:57
    thanks folks!

    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.
  • jimtjimt Posts: 5
    edited 2014-09-13 19:00
    Turns out that my batteries were running low which in turn caused the strange behavior and board reset.

    Popped in some new batteries and all works as expected now :)

    Thanks again everyone for all of the helpful suggestions!
  • GenetixGenetix Posts: 1,749
    edited 2014-09-13 19:19
    jimt wrote: »
    Turns out that my batteries were running low which in turn caused the strange behavior and board reset.

    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-09-15 08:26
    The Piezo and startup code are the better solution. The LED will be on even when the batteries are too low to run the microcontroller.
  • jimtjimt Posts: 5
    edited 2014-09-15 11:36
    I've got a Piezoelectric speaker in the circuit as well for just that purpose, so I am all set for future brownouts :)

    Thanks!
  • Hi Guys,

    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
  • twm47099twm47099 Posts: 867
    edited 2016-04-14 16:20
    Just a guess (based on my experience), check the wiring of the whiskers. Particularly that the left whisker is not touching the pin or part of the frame of the bot.

    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

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    It looks like that code is triggered by the IR Sensors, so I would check the wiring on the infrared sensors. You can also try swapping the sensors and the IR LEDs to see if the problem follows.
  • ercoerco Posts: 20,256
    edited 2016-04-14 16:35
    Per Chris, look for a wiring error. Remember that those IR sensors are active low=0. Meaning that they are normally high=1 unless they receive an IR signal, in this case a reflection of the IR LED signal from a nearby object. Be sure that the black 3-pin IR receiver doesn't receive the IR LED signal directly. The IR LED needs to have a shielding tube around it and/or be behind the receiver so the receiver can't "see" the LED directly. Once you've verified that, try removing the IR LED briefly for a test. After that, modify the code. Just for fun try

    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).

  • It looks like that code is triggered by the IR Sensors, so I would check the wiring on the infrared sensors. You can also try swapping the sensors and the IR LEDs to see if the problem follows.
    Hi Chris, thanks for your advise. I checked the wiring again, all is well.
    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.
  • More info: now at http://learn.parallax.com/tutorials/robot/shield-bot/robotics-board-education-shield-arduino/chapter-7-navigating-infrared-8 > when nothing is detected > the left LED blinks very fast continuously, while the right LED does not blink.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2016-04-22 15:06
    Usually if you swap an IR LED or Detector and the problem follows the change the part is the problem. But now I am wondering if it isn't more about the lighting conditions and perhaps orientation of the LEDs and sensors.

    Perhaps post some photos of the sensors on the robot and a video of what is happening?
  • ercoerco Posts: 20,256
    But now I am wondering if it isn't more about the lighting conditions and perhaps orientation of the LEDs and sensors.

    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.

  • Yeah, I had issues with the initial code when I put together a BOE Bot for Arduino Shield and I made a few adjustments to the code to correct this. Basically I took out where it was doing a backward motion and something like a turn. Also, I reduced the delay time to 10 and I changed the checks for (irLeft == 0) and (irRight == 0 )to !irLeft and !irRight. This seemed to correct the odd behavior of the Shield Bot spasms.

    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
Sign In or Register to comment.