Lab 8
Net ID: pp386
Objective: Stunts
This lab is a culmination of previous labs and the end goal of this lab is to make our robot do cool stunts.
Acknowledgements
This lab was a joint collaborative effort by Priyam Patel, Swapnil Barot and Nikhil Satheesh Pillai.
Lab Procedure
Task A- Open Loop Flip
To make the car flip, essentially what we need is an instantaneous change in PWM inputs of very high magnitude to the motors. Let us say our car was running towards the wall with a fixed PWM value of 255. If we want to make it flip, we need to use active braking (Making all PWM inputs 255) and then instantly give it a high PWM value in the opposite direction. This will make the car do a vertical flip.
Task A- Closed loop stunt flip
Having flipped the car using open loop, it became increasingly easy to implement a closed loop system with ToF sensor readings as the input. This was implemented as shown below.
void stunt_func(){
distanceSensor2.startRanging();
distance = distanceSensor2.getDistance();
distanceSensor2.clearInterrupt();
distanceSensor2.stopRanging();
if (distance > 925) {
forward();
}
else {
counterrr++;
if (counterrr==1){
stopMotor();
backward();
}
else{
backward();
}
}
}
void forward(){
analogWrite(A0, 175);
analogWrite(A1, 0);
analogWrite(A14, 175);
analogWrite(A15, 0);
}
void backward(){
analogWrite(A0, 0);
analogWrite(A1, 255);
analogWrite(A14, 0);
analogWrite(A15, 255);
}
void stopMotor(){
analogWrite(A0, 255);
analogWrite(A1, 255);
analogWrite(A14, 255);
analogWrite(A15, 255);
}
We defined the forward PWM value to be 175 and the backward PWM value to be 255. We start taking the TOF sensor readings and when the distance is greater than 925 mm from the wall, the car moves towards the wall (175 PWM). At the instant when the car crossed 925 mm, we used active braking through the stopMotor() function and stopped all the motors instantaneously. After that we gave a backward PWM of 255 to make the car flip and come backwards. This is demonstrated in the video below.
One thing to note here is that there needs to be a difference in the code between how the car responds the first time it crosses 925 mm and all subsequent readings. This is because to flip, we need to send the stopMotor() function call only once, if we sent it regardless, the car didnt flip.
Open-ended stunts
For this section, we decided to implement something what almost everyone of us wanted to do with our car since we got it. HOT WHEELS.
HOT WHEELS RAMP
For the creation of the ramp, we used the wooden blocks and cardboard from the lab. We started by creating a single lane ramp of 5 block thickness as shown in the videos below and a second ramp also single lane, initially 3 feet away of 4 block thickness for the car to land safely. We gave the car PWM values of 240 and 250 respectively so that the car could go straight in a calibrated manner.
Attempt 47: Flight Distance - 3 feet
Attempt 59: Flight Distance - 2 feet (3 lane landing ramp)
Attempt 60: Flight Distance - 2 feet (3 lane landing ramp)
This lab was a lot of fun and we also had various fails like the car running into the mens bathroom while doing the HOT WHEELS stunt. This is one of the moments we got on camera.
Conclusion
In this lab, we were able to implement open loop control for various stunts and also performed a closed loop flip. Please vote for us as the best stunt if you liked it thanks!