LAB 8: Stunts!

April 8thth, 2025
The purpose of Lab 8 is to use the Kalman Filter implemneted in Lab 7 to execute a stunt. The stunt will involve driving the car towards a wall, performing a flip, and driving back across the start position.

Software Implementation

Bluetooth Interface

A command FLIP is added. The command takes in arguments for the speed, the distance threshold to perform the flip, flags for recording data, the TOF sensor's timing budget, and the time to reverse after the flip is performed.

A second command SEND_FLIP_DATA is added. This command iterates through the FlipControlDataBuffer array and sends data over Bluetooth. The data is then parsed by a listener within Jupyter Lab. The initialization of FlipControlDataBuffer, its contents, and the definition of the listener is shown below.

FLIP EXECUTION

The flip is executed by driving forward at a fast speed until the distance from the wall is less than a set distance threshold. The car then drives in reverse at a fast speed for a set time. The rapid change in speed causes the car to flip.

To keep track of the current stage of the flip, an enum FlipState is created. The FlipState enum has three states: FLIP_FORWARD, FLIP_BACKWARD, and FLIP_STOP.

If we have a new TOF sensor reading, the Kalman Filter performs an update and prediction step. Otherwise, only a prediction step is performed. This is the same implementation as Lab 7. If we are in the FLIP_FORWARD state, the car will drive forward at a fast speed. If the distance from the wall is less than the distance threshold, the car will stop and enter the FLIP_BACKWARD state. The car will then drive backward for a set time before entering the FLIP_STOP state. The car will then stop and wait for a new command.

Open loop control is selected for the flip execution to prevent any slowdown from a closed-loop controller as the car approaches the wall. This is important as the car's speed is a large factor in the flip's success.

Demonstrations

The three demonstrations are shown below. The first two videos show imbalanced flips caused by uneven motor power and uneven weight distribution. The third video shows a balanced flip after adding a motor offset. However, in each example, the car is able to drive back across the starting line (the car may get blocked by obstacles but the car would reach the starting line had it not hit them).

Figure 1: Flip 1 (slightly imbalanced)
Figure 2: Flip 2 (imbalanced)
Figure 3: Flip 3 (balanced)

The time-series plots of the Kalman Filter's predicted distance from the wall and the TOF sensor data, and motor input for each run are shown below. The Kalman Filter and TOF sensor data after the flip is not accurate due to the use of the delay(..) function during the reverse section. During this time, no new TOF readings are measured. The linear region is due to only one TOF sensor reading being measured before the car enters the FLIP_STOP state.

mac_address
Figure 4: Flip 1 Kalman Filter and TOF Sensor Data
mac_address
Figure 5: Flip 2 Kalman Filter and TOF Sensor Data
mac_address
Figure 6: Flip 3 Kalman Filter and TOF Sensor Data

Challenges

Some time when into tuning the distance threshold to execute the flip at the correct distance from the wall. The run below shows an instance when the distance threshold was too large and the car flipped early.

The weight distribution of the car is also adjusted. The battery is moved to the front of the car instead of the back.

Figure 7: Flip 4 (early flip)

Blooper

Figure 8: Disaster