A few friends and I have been attempting to build an autonomous robot for our project using:
Arduino - Duemilenove
Adafruit - Motorshield
Sparkfun - Bluesmirf
Parallax - Ping sensor
We were able to configure the robot such that it is able to run autonomously. We also tried implementing some code in processing to show where an object is detected and how far it is from the ping sensor; it looks similar to a radar.
The problem we are experiencing is when adding the code that interfaces with the processing sketch. Inside the loop, I have the following code:
void loop()
{
LookAhead();
//Serial.print(inches);
//Serial.println(" inches"); // Prints a line in the serial monitor
if(inches >= minSafeDist) /* If the inches in front of an object is greater than or equal to the minimum safe distance (11 inches), react*/
{
AllForward(); // All wheels forward
delay(110); // Wait 0.11 seconds
}else // If not:
{
AllStop(); // Stop all motors
for (int i=0; i<180; i=i+1) {
PingServo.write(i);
delay(50);
ping();
delay(50);
Serial.print("X");
Serial.print(i);
Serial.print("V");
Serial.println(inches*2);
}
LookAround(); // Check your surroundings for best route
if(rightDist > leftDist) // If the right distance is greater than the left distance , turn right
{
turnRight();
}else if (leftDist > rightDist) // If the left distance is greater than the right distance , turn left
{
turnLeft();
}else if (leftDist&&rightDist<minSafeDist) // If the left and right distance is smaller than the min safe distance (11 inch) go back
{
GoBack();
}
}
}
The problem area is in bold. When the line of code is removed, the servo pans and receives information just fine. When observing the serial monitor, I can see that the distances from the ping sensor and the object show the correct distances. When we add that line of code to link to processing, it will start to pan really slow. It takes approximately 18 seconds for it to pan, but processing is able to receive the information and translate it. Adjusting the delay doesn't work, and the servo exhibits some kind of jitter. Any help would be appreciated. Thanks