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