The goal of this lab is combine what we've learned to have the RC car perform a stunt.
The stunt we attempted was to drive at a wall and at ~3ft away, have the robot spin 180 degrees and drive back. We used a PID controller to control the orientation and simply had the robot drive forwards based on the ToF readings. The PID gains were the same as lab 6 for the orientation control. Below is the code used to control the robot. We first set the goal angle to be 180 from the current angle. Then we drive forwards until we are 1500mm away, then we initiate the rotation, and then drive forwards. From there, we send a command to stop from the laptop.
"// if the set point has not been updated, update
if (y_g == 0.0 && standard_point == false){
updateGyro();
point = y_g + 180;
standard_point == true;
}
updateGyro();
PIDcontrol();
ToFSensorGetData(distanceSensor1, distance_1);
if (turned == true){
speed = 200;
right_speed = 0.80 * speed;
move_forwards();
}
else {
// ToFSensorGetData(distanceSensor1, distance_1);
// if far from wall, keep going straight
if (((distance_1 > 1500) && (reached == false)) || distance_1 == 0){
speed = 200;
right_speed = 0.80 * speed;
move_forwards();
}
else { // initiate turn, set bool
// stop_car();
reached = true;
// if err positive, turn right, if negative turn left
if (err > 1){
speed = min_speed + PID;
if (speed > 255){
speed = 255;
}
if (speed < min_speed){
speed = min_speed;
}
right_speed = 0.85 * speed;
turn_right();
}
else if (err < -1){
speed = min_speed - PID;
if (speed > 255){
speed = 255;
}
if (speed < min_speed){
speed = min_speed;
}
right_speed = 0.85 * speed;
turn_left();
}
else { //angle is 180
turned = true;
}
}
}"
We performed 2 trials due to a hardware failure(ToF snapped) while trying to complete the 3rd trial. The stunts were relatively successful, but the turning radius is larger than expected. The videos and requesite graphs are below.