Lab 8: Stunts
Lab Objective
The purpose of this lab is to combine the work done in previous labs to control the robot in a high speed stunt. For the the controlled stunt, I chose to do orientation task which involves turning the car quickly and drive back to were it came from.
Task B: Orientation Control
For this lab, I was tasked with turning the robot at a specified distance from the wall. More specifically, the goal was to drive the robot forward as fast as possible starting at a distance of less than 4 m from the wall. Then, at a distance of 3 feet the robot will turn 180 degrees and head back to the starting line. There are two key components in successfully completing this lab. The first one is to quickly and correctly estimate the distance from the wall such that the robot initiates the turn on time, and secondly is to make the 180 degree turn correctly and quickly.
I’m not using the Kalman filter to estimate the distance but I am using linear interpolation which helps the robot to estimate the distance to the waller quicker than if I only used the ToF sensor readings.
Implementation
The task is divided into four different sections.
- Drive fast forward until the robot is 3 feet from the wall.
- Quickly turn the car 180 degrees.
- Drive back to the starting line.
- Send data over Bluetooth.
To accomplish this a new case “STUNT” was created, see this below.
Below is the logic of my main loop as well as the “doStunt” function. These were the two main components of the implementation. Additional functions worked as helper functions. Notice that “doStunt” is getting called right away from the loop. When the desired position is reached, it calls the reverse function, which activates my orientation PID. Finally, the car accelerates back from where it came from.
Two main challenges arose when completing this lab. The first one was to set flags at the right time and make sure different functions and cases didn’t block each other. One example is when I tried to turn the car I had some issues. Most of these were solved by creating a “STUNT_RUN” flag and setting it to false when I needed to use the orientation control. The second issue involved getting the car to turn exactly 180 degrees and do so fast. Because I wanted minimum delay, the car span a little bit even after it was supposed to be done turning. This was solved by testing the right delay times and having it stop turning a little before reaching 180 degrees.
Results
The videos below shows that my stunt is working well. The robot travels fast and initiates the turn at the right distance before quickly driving back to the starting line.
And here is the collected data of the change in angle over the run.