Arduino Bot has a mind of its own?

Object_Avoidance_Servo_Ping_Led.pde (5754Bytes)

Hello,
    My bot seems to have a mind of its own. code seems to be working but at times it react to an object thats not there??? its set to find a better path after coming within 30 cm of an object but sometimes theres nothing there and it looks for a better path? can this be from the ping returning false values, or i think it might be from the 9v battery draining quickly. Any ideas?? Thanks oh, I'm using Arduiino Duemilanove. Code is attached

https://www.youtube.com/watch?v=SiXvlV6-0S8

Can you post some side

Can you post some side views?  It looks like your ping))) sensor is blocked by the bumper.  I’m sure you didn’t build it that way. 

OK, I’m pretty new at this

OK, I’m pretty new at this level of knowledge of the Arduino, but I think this is something to try.

Your code uses analogWrite for PWM on pins 10 (leftSpeedPin) and 11 (rightSpeedPin).  The Arduino Duemilanove has six pins that work with PWM. This post was pretty informative. PWM uses different processor timers for different pins.

Pin 10 uses Timer 1 and pin 11 uses Timer 2. Timer 2 is also used by pin 3, if you use analogWrite on that pin. Since it is OK (in fact, good) to have your two motors run at a shared frequency for PWM, you will use less resources if you move leftSpeedPin to pin 3.

Now both of your PWM pins will use Timer 2. This should free up some timer resources, and may help.

I have to run now. Can you try this and see if it help? I’ll try to check back later.

Maybe someone more knowledgable than I can assist too.

It not, check out this pic,

It not, check out this pic, i thought that was the problem too but nope. Thanks 

http://i59.photobucket.com/albums/g309/elijah504/IMG00533-20110403-1138.jpg

I see your point. Thanks

I see your point.  Thanks for the pic.  Maybe looking at the readings the ping))) is giving you would be more helpful?  I would suggest increasing the delays and having it return the readings via serial connection (xbee?).  The delays will give you time to coorelate the reading with the position.

I tried switching the pins

I tried switching the pins around like this:

#define servoPin     13         // Servomotor on pin D12.

  #define pingpin      12         // Ping ultrasonic sensor on pin D13.

  #define redled        11         // 2 drive motors, motor driver SN754410NE

  #define whiteled      10

 

  #define leftSpeedPin   5       // Left motor speed control

  #define leftmotorpin1  2        // Left motor direction 1 

  #define leftmotorpin2  4        // Left motor direction 2

 

  #define rightmotorpin1 7        // Right motor direction 1

  #define rightmotorpin2 8        // Right motor direction 2

  #define rightSpeedPin  6       // Right motor speed control

It had the same problems, i tried putting left speed pin to pin 3 and same thing. darn

Not really helpful but…

With both the Sharp IR sensor on my SHR+ bot and the EZ4s on my current project I occasionally receive high values randomly. With the SHR it stops and looks around, just like yours. The programming with the EZ4s just make a servo twitch. Both are driven by PICAXEs. I’ll be watching this thread expectantly.

Cant afford an xbee right

Cant afford an xbee right now, i saw on the another forum somebody said echos might be causing an error to maybe add a 50 ms delay between pulses from the ping? wat do you think? http://arduino.cc/forum/index.php/topic,58378.0.html

A pause after each range

A pause after each range pulse would be good. 10 ms may be adequate.

Another thing I just noticed is that you are “rolling your own” servo controls. Why not just use include the servo library and use those commands?

.

.

How wud I add this delay btw

How wud I add this delay btw pulses… thinking of adding the line delay(10) after nodanger() and before “else” in the loop mayb? not using the servo library b/c im not too familiar with it yet, more comfortable doing it manually. still learning programming

You need to do what I call a

You need to do what I call a “Sanity check”.   basically its telling you 2+2 does not equal 4.    you need to see inside the running program so you can see what it sees.   you need more feedback from your code.

try this:

make an led blink slowly, where the number of times it blinks equals the number of centimeters it thinks it finds, or if you dont want to count to 30, make it blink X / 10.   so if it finds 30cm, it blinks 3 times.  

or perhaps a small speaker could be used to beep instead of led blinking.  different pitch beeps can mean different things.  I think the FREQOUT command will do this easily in some languages, not sure about arduino.   plus, and most importantly, it would make Fritz happy.

either way, you’ll get feedback on what your bot thinks he sees.

(If I was programming something like this in the Windows world, I would put up a msgbox or dialog box displaying the CM’s it find.)

added “delay(10);” after

added “delay(10);” after “readdistance();” got it working right, finally!

Ive been experimenting with

Ive been experimenting with serial monitor all day,  i added a “delay(10);” after “readdistance()” and it seems to have solved the problem… for now at least.