Society of Robots - Robot Forum
Software => Software => Topic started by: pomprocker on August 24, 2008, 12:18:09 PM
-
My robot is jerking around the floor
I figured out it is because I am calling the sharpIR servo scanning function followed by my parallax ping sonar function.
How can I sort this out so that calling these two functions constantly in a while loop won't cause my robot to jerk around?
heres the code
while(1)
{
ping();
//Object Avoider
if (PingVal > 8) {
scan();
//if (sharp_IR_reading > scan_thresh) {
//object on left
// if(scan_angle > 456) // 57 * 8
// robot_turn_right();
//object on right
// else if(scan_angle < 328) // 41 * 8
// robot_turn_left();
// } // end if
//object is centered
//else
robot_go_straight();
} // end if
else {
while (PingVal < 16) {
robot_go_back();
ping();
} // end while
} // end else
even with lots of stuff commented out it does it, thats how i narrowed the problem down to the actual function calls.
would it be better to attach the function calls to interrupts?
-
This is called robot oscillation. Basically, when your robot oscillates, it is stuck between PingVal of 15 and 16. When its 15, it goes in reverse, and when its 16 after going in reverse, it immediately goes forward causing PingVal to drop to 15 again. Basically its an infinite loop.
Your code:
robot_go_straight();
else
while (PingVal < 16)
robot_go_back();
ping();
Here is one of many solutions:
robot_go_straight();
else
while (PingVal < 16)
robot_go_back();
delay_ms(500);//give it time to go in reverse
robot_rotate_left();//if it doesn't turn, it just goes forward into object again
ping();
-
it does the going backwards part very smooth and just fine, because in that while loop its not calling ping and scan, only ping.
Its only with going forward that causes it to jerk.
I tried attaching it to a timer, but you can't use functions that receive or return values.
-
You haven't thought out the software flow properly.
Basically, you need to read all sensors, process them all, together, and then decide how to move. If you move based on the first one, then move based on the second one, then again the first one, oscillation, as you experience, is extremely likely to occur.
So, read the parallax sonar, then the sharp IR, then decide what to do based on both values. You could do a complete sweep (if any sensor is mounted on a servo) and use the mapped result to decide how to move.
Even if you think your program based on interrupts, it's not really going to help, since the flow will be the same - you analyze sensors separately.
-
Its only with going forward that causes it to jerk.
So if you comment out the reverse function, it doesn't jerk?
Or perhaps your sensor is very noisy (look at sensor values with serial)? Or that the sonar is sometimes detecting the ground (try aiming the sonar up higher)?
I tried attaching it to a timer, but you can't use functions that receive or return values.
What do you mean?
-
@ izua
I had already tried combining the two at the very beginning of the while loop, example:
while(1) {
ping();
scan();
...
Same problem, and besides the $50 robot w/ sharp IR source code doesn't do a full servo sweep before moving and it works just fine w/o jerking around.
@ Admin
-The functionality of throwing it in reverse works fine, no jerkiness there.
Its only with the first part that causes it (specifically calling the two functions)
while(1)
{
ping();
//scan();
if (PingVal > 8) {
scan();
robot_go_straight();
} // end if
...
-using only ping or scan in the code by themselves and it works fine.
-The timerAttach documentation in the header file timerx8.h states that.
00235 // myOverflowFunction must be defined with no return value and no arguments:
-
hey i just realized, isnt fuzzy the omniwheeled robot doing scanning and sonar at the same time?
-
using only ping or scan in the code by themselves and it works fine.
So both of these work fine?
while(1)
{
ping();
//scan();
while(1)
{
//ping();
scan();
But not this?
while(1)
{
ping();
scan();
hey i just realized, isnt fuzzy the omniwheeled robot doing scanning and sonar at the same time?
Yeap, 3 sonar and 3 sharp IR ;D
Although it was written for the PIC16F877, it shouldn't be hard to take code from it.
-
I THINK I figured this out, but then I wasnt able to program the board anymore....this episode is to be continued...