Testing Ardumobo
In order to test Ardumobo, I wrote a small Arduino sketch that changes the direction of the robot when the distance to the obstacle is less than 10cm. Here is the code:
#include "HCSR04.h"
#include "DRI0017.h"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
setupHCSR04();
setupDRI0017();
int frontDistance = 0;
int rearDistance = 0;
int moveDirection = Forward;
while (1) {
frontDistance = readFrontSensor();
rearDistance = readRearSensor();
if (frontDistance < 10){
moveDirection = Backward;
}
if (rearDistance < 10) {
moveDirection = Forward;
}
if (moveDirection == Forward){
setMotorDirection(M1, Forward);
setMotorSpeed(M1, 100);
delay(10);
setMotorSpeed(M1, 70);
} else {
setMotorDirection(M1, Backward);
setMotorSpeed(M1, 100);
delay(10);
setMotorSpeed(M1, 70);
}
delay(100);
}
}
Here is a short movie of Ardumobo detecting obstacles in front and rear and then changing moving direction after obstacle detection. The front wheels are a bit wobbly, I will try to tighten them up and adjust the wheel alignment. (There is a plastic screw labeled "wheel adjustment" under the front wheel assembly of the truck: I will see if it works.)
Next blog: obstacle detection outdoors.