The objective of this lab is to complete the “Drift Much?” stunt at the highest possible speed by combing all the techniques learned in previous labs, especially lab 6 and 7. I had been looking forward to lab 8 for a while and had lots of fun doing this lab!
For this section of the lab, the robot should perform the “Drift Much?” stunt with the rules specified in the lab handout. I first started by running the PID control code from Lab 6 for completing a 180 degree turn while moving forward. I tuned the Kp and Kd coefficients as well as the motor speed calibration for this environment (battery, floor, updated IMU positioning on the robot).
Next, I polled the ToF sensor values while the robot was moving straight and started the PID control if the robot was less than 750 m from the wall. I chose a higher threshold as the robot moves forward while implementing the turn as well. This part of the code was adapted from the step response execution in Lab 7. The ToF sensor on my robot cannot measure distances correctly beyond 2m and starts outputting random values. This is unusual, I plan on changing the sensor before the next lab. As the robot was starts 4m away from the wall, the first distance measured was less than 750mm, so the robot would not move. I avoid this tried moving the robot forward for 500 msec and then checking for the ToF sensor measurements. While implementing this part, my robot crashed into the wall pads a few times. Having suffered multiple such crashes in from Lab 7, it was already in a fragile position. The right set of wheels stopped moving; Using a multimeter, I realized that the motor driver’s connections were broken. Given the inaccurate sensor readings and broken motor driver, I used Krithik Ranjan, another classmate’s robot to execute my stunt. He had already completed the lab, so I used his robot to complete my lab.
Using a new robot, meant recalibrating everything again. I repeated the above steps with the new robot. I did use Krithik’s A, B and covariant matrices from Lab 7 for the Kalman Filter as they were calculated for his robot. The sensor readings on this robot were better, so I did not have to use the trick above.
The sampling rate for the sensor readings is about 90-110msec, as the sensor is running in long distance range. As the goal of the lab is to complete the stunt as fast as possible, the robot might crash into the wall while waiting for sensor readings. We can overcome this by adding a high enough threshold, so the robot starts turning earlier. As we need to touch the 0.6m line, this is not an option. We will need to use the Kalman Filter from Lab 7 to estimate the distance when the sensor readings are not available
The Kalman Filter has two steps – Prediction Step and Update Step. In the prediction step, the filter produces an estimate for the distance and in the update step it uses the sensor measurement to update its estimate based on the sensor measurement and noise covariance matrices. The code currently runs in a constant loop until it is too close to the wall. Instead of waiting till a sensor reading is available, I modified it to use the sensor reading if available, if not use the Kalman Filter Estimate by just running the prediction step. If either the sensor reading or the estimate is less than the threshold, then the PID turn is implemented.
In the graph below, we can see that the Kalman filter estimate with just the predict step are used about once between sensor readings. The Kalman filter predictions overshoot a lot more than the sensor readings. I am not able to understand the reason for this. It is closer to the sensor readings in the beginning and end. The graph below is for a filter that trusts it sensor readings much more than the model (sigma_1 = 50, sigma_2 = 50, sigma_3 = 10).
Next, I tried the Kalman filter with sigma_1 = 5, sigma_2 = 10, sigma_3 = 20, trusting the model more than the sensor values. I used the previous tuning as it worked better in practice.
Please note that the graphs above are from tuning my robot, not krithik's.
The PID controller has a control timer as well as a break if the error is within 2 degrees and it fluctuates between negative and positive more than 2 times. Adding this helped reduce the car from oscillating multiple times after making the turn as seen in Lab 6. Apart from this, not changes were made to the PID control logic from Lab 6. Once the PID controller stops, the robot moves forward for the same amount of time it moved forward previously (before starting PID). As the robot has turned around, it completes the stunt by moving back to the starting line.
Next, I kept increasing the speed and the PWM output range for the PID control to perform the stunt at maximum possible speed. The video below shows the best iteration my controlled stunt.
My robot’s motor driver was broken; Eli Zhang, another student, was having issues programming his robot. Due to the lack of time, we collaborated with each other, using Eli’s robot and my laptop. We decided to do simple stunts involving turns and rotations at a high speed, instead of flips to avoid crashing and breaking the robot.
For the first stunt, we wanted to rotate the robot on the spot at a high speed, avoiding any drifts from its starting position. To do so, we rotated the right wheels of the robot in the forward direction and the left wheels in the opposite direction. We noticed that using the same PWM value for both sets of wheels resulted in drift, due to different calibrations of the motor drivers. We tuned the PWM values given to each motor to have minimal drift. The video below shows three iterations of the stunt, with the robot on a fully charged battery.
For the second student, we wanted to improvise on robot and make a pattern. We chose to have the robot make the digit 8, as this was lab 8. The goal was to achieve the pattern with a smooth turn, no jerks. To do so, we first moved right wheels forward with a very high speed (180) and the left wheels backward with a minimum speed (75) for 1.75 seconds. Next, we did the opposite, moving the left forward and right back. We had to tune the speed ratios and timing for each turn to achieve a perfect 8.
I really enjoyed this lab but was very anxious about destroying my robot. I am very grateful to my classmates for helping me out, when my robot stopped working. I would like to try out some more risky stunts, towards the end of the semester once the robot is not required for other labs. Suggestion: we could do a robot stunt competition / show down at the end of the semester!