Datasheet
Robot Control with Distance Detection • Chapter 8
Robotics with the BOE Shield-Bot • 267
Project Solution
1. One quick and simple solution would be to average the driveLeft
and
driveRight values in the FollowingShieldBot sketch. The resulting single
value can be applied both left and right speed parameters in the maneuver call.
void loop() // Main loop auto-repeats
{
int irLeft = irDistance(9, 10); // Measure left distance
int irRight = irDistance(2, 3); // Measure right distance
// Left and right pr67oportional control calculations
int driveLeft = (setpoint - irLeft) * kpl;
int driveRight = (setpoint - irRight) * kpr;
int drive = (driveLeft + driveRight)/2; // Average drive levels
maneuver(drive, drive, 20); // Apply same drive to both
delay(10); // 0.1 second delay
}