Lab 8¶
Objective¶
The goal of Lab 8 was to perform a controlled stunt with our car, choosing between a flip or a drift. For the flip stunt, the car needed to start at least 4 meters from the wall, accelerate forward, perform a flip upon hitting the sticky mat, and then return to the starting line.
Implementation¶
I chose to perform the flip stunt, primarily because it allowed for open-loop control. Since speed is an important factor, using my linear and orientation PID controllers would have slowed down my execution. Open-loop control enabled faster stunts.
I implemented a Bluetooth command, FLIP, for the stunt. The command controlled the duration of maximum forward acceleration, which was immediately followed by maximum reverse acceleration and then braking. During this sequence, the car logged distance and PWM data for analysis.
Initially, the car struggled to complete the flip. To address this, I repositioned the microcontroller battery to the front of the car and added a small weight. These adjustments significantly increased the flip success rate. Before landing on this approach I experimented with several other methods. First, I tried accelerating forward at full speed and then braking, this was not successful. Next, I tried reverse acceleration followed by forward acceleration thinking that the mass distribution of my car would be more conducive for this approach, but it also did not work. Finally, I tried a full-speed forward acceleration immediately followed by full-speed reverse acceleration. I observed that upon entering into the reverse the rear wheels were lifting off the ground. After adding a front weight and moving my microcontroller battery this method proved effective, resulting in consistent flips.
Using this python command I am able to send the forward and reverse time duration to the motors.
ble.send_command(CMD.FLIP, "900|1400")
This command is handled in Arduino using this code:
case FLIP:
float time_1, time_2;
success = robot_cmd.get_next_value(time_1);
if (!success) return;
success = robot_cmd.get_next_value(time_2);
if (!success) return;
sensor2.startRanging();
start_time_1 = millis();
while (millis() - start_time_1 < time_1) {
analogWrite(AIN1, 0);
analogWrite(BIN2, 0);
analogWrite(AIN2, 255);
analogWrite(BIN1, 255);
if (index < max_len) {
unsigned long now = millis();
time_stamps[index] = now;
pwm_vals[index] = 255;
if (sensor2.checkForDataReady()) {
last_distance = sensor2.getDistance();
distances[index] = last_distance;
sensor2.clearInterrupt();
} else {
distances[index] = last_distance;
}
index++;
}
}
start_time_1 = millis();
while (millis() - start_time_1 < time_2) {
analogWrite(AIN1, 255);
analogWrite(BIN2, 255);
analogWrite(AIN2, 0);
analogWrite(BIN1, 0);
if (index < max_len) {
unsigned long now = millis();
time_stamps[index] = now;
pwm_vals[index] = -255;
if (sensor2.checkForDataReady()) {
last_distance = sensor2.getDistance();
distances[index] = last_distance;
sensor2.clearInterrupt();
} else {
distances[index] = last_distance;
}
index++;
}
}
start_time_1 = millis();
while (millis() - start_time_1 < 1250) {
analogWrite(AIN1, 255);
analogWrite(BIN2, 255);
analogWrite(AIN2, 255);
analogWrite(BIN1, 255);
if (index < max_len) {
unsigned long now = millis();
time_stamps[index] = now;
pwm_vals[index] = 0;
if (sensor2.checkForDataReady()) {
last_distance = sensor2.getDistance();
distances[index] = last_distance;
sensor2.clearInterrupt();
} else {
distances[index] = last_distance;
}
index++;
}
}
sensor2.stopRanging();
###Transmit Data###
break;
Flip¶
Flip 1 Completion Time: 3.52s¶

Flip 2 Completion Time: 3.60s¶

Flip 3 Completion Time: 3.20s¶

In all the plots, we observe that the distance measurements trend toward zero or near-zero values. This is due to the Time-of-Flight (ToF) sensor collecting data during the flip, primarily detecting the floor. In two of the three plots, a large spike is visible, this likely corresponds to the sensor measuring the floor while the car is at an angled position near the end of its rotation, capturing a brief reading from the floor ahead. After the flip is completed, the ToF distance readings remain low, which is consistent with behavior seen in previous labs when no objects are within range.
Blooper¶
Refrences¶
In lab 8 I consulted other students in the course about various elements of the assignment. These students included Annabel Lian and Becky Lee. I also referenced Annabel Lian's webpages. I used ChatGPT to help with debugging, text editing, as well as some code generation for plotting data and command implementation.