Lab 8: Stunts (Drift)
In this lab, I combined previous control strategies to perform a fast drift maneuver.
1. Objective
The goal of this lab was to perform a fast stunt by combining concepts from previous labs. I chose Task B (Drift), where the robot drives toward a wall, performs a 180° turn at a set distance, and then drives away.
2. Approach and Planning
I initially attempted to use the Kalman Filter from Lab 7, but I found that it was not reliable enough at high speeds for this stunt.
Because of this, I chose to rely primarily on tuned ToF distance thresholds and IMU-based orientation control.
I implemented a state machine to manage the transitions between driving, drifting, and exiting the maneuver.
3. Drift State Machine
Drift State Variable
int drift_state = 0;
// 0 = drive toward wall
// 1 = drift (turn)
// 2 = drive away
This structure allowed me to separate the control strategies for each phase and transition between them more cleanly.
4. Driving Toward the Wall
The robot drives forward at a constant speed until it reaches a threshold distance from the wall.
Drive to Threshold
if (drift_state == 0 || drift_state == 2) {
if (ToF_Sensor_1.checkForDataReady()) {
int distance1 = ToF_Sensor_1.getDistance();
ToF_Sensor_1.clearInterrupt();
distance1_in = distance1 * 0.0393701f;
error1P_drive = distance1_in - drive_threshold;
// State 0: keep driving until threshold is reached
if (error1P_drive > 0 && drift_state == 0) {
drive_forward(70);
}
else if (error1P_drive < 0 && drift_state == 0) {
drift_state = 1;
}
}
}
I initially set this threshold to 12 inches, but
I found that there was not enough space because the robot
continued drifting forward during the turn. Because of this, I
increased the trigger distance to 18 inches to
allow enough space for a full drift.
12 in Trigger Attempt
5. Drift (180° Turn)
During the drift phase, I used IMU yaw measurements and a PID controller to rotate the robot by 180°.
Drift Control
if (drift_state == 1) {
icm_20948_DMP_data_t data;
myICM.readDMPdataFromFIFO(&data);
// DMP calculations
Gyro_yaw = (float)atan2(t3, t4) * 180.0 / PI + 3.8;
float deadband_ori = 2.0;
if (fabs(error1P_ori) <= deadband_ori) {
stop_motors();
dutystate_ori = 0;
ori_finish = 1;
drift_state = 2;
}
else {
ori_finish = 0;
if (error1P_ori > 0) {
drift_right(duty2);
dutystate_ori = 1;
}
else {
drift_left(duty2);
dutystate_ori = -1;
}
}
}
One key observation was that large PWM values caused the robot to overshoot significantly. Since the largest change in rotational velocity happens when the robot has to turn the full 180°, I had to drastically decrease the PWM signal to prevent over-rotation and improve stability.
Higher PWM Overshoot Trial
I also found that using the same PWM signal for both motors did not make the robot drift well. To make the motion look more realistic and controlled, I lowered one motor relative to the other instead of keeping them equal.
Uneven Motor PWM Trial
6. Driving Away
After completing the turn, the robot drives away from the wall to complete the stunt and clearly show successful reorientation.
Exit Motion
drift_state = 2;
if (drift_state == 2) {
drive_backward(70);
}
7. Results
Below is a video of a successful drift run.
Successful Drift Run
This plot shows the ToF distance and yaw angle during the drift.
Drift Plot
8. Blooper: The Peepee Dance
One of the more interesting failure modes I observed was what I call the “peepee dance,” where the robot would spin in place uncontrollably and then drive off unpredictably. In one case, it went directly toward my bathroom.
Blooper Video
Blooper Plot
9. Discussion
This lab highlighted how difficult it is to control fast dynamic motion. Small changes in distance thresholds or PWM values had a large effect on performance.
While the Kalman Filter worked well in Lab 7, it was not reliable enough at high speeds for this stunt, so direct sensor tuning provided better results.
Overall, this lab brought together concepts from previous labs and demonstrated how estimation and control interact in real-world robotics systems.
10. Acknowledgments
I used ChatGPT to help debug code and structure this report.
I also used Akinfolami Akin-Alamu’s Spring 2025 work to help structure my report, since there was not much structure in the Lab 8 handout.