ECE 5160 Fast Robots - Lab 8: Stunts!

Lab 8 combines the rotational and distance PID controllers. In the selected task B, the car is expected to dash at full speed towards the wall and make a 180-degree turn when the distance between wall is below the limit.

You can click on the image to view it in a larger window.

Objectives


The goal of this lab is to combine the previous PID controllers together to perform fast movements on the car. I choose to implement task B, which is a combination of distance and orientational control.


Task B: Orientational Control


There are two ways to realize control of the robot: build control logics into the board or transmit control signals via BLE.
If the control sequence is built-in, the code inside the board is shown below:

                                    
                                        void stunt(){
                                            static bool firstLoop = true;
                                            unsigned int time = 0;
                                          
                                            if(firstLoop){
                                              speedFB = maxPWM;
                                              speedL = maxPWM;
                                              speedR = maxPWM;
                                              PID_TOF_IS_ON = true;
                                              firstLoop = false;
                                              Serial.println("111");
                                            }
                                          
                                            if(d1[1] <= 912 && PID_TOF_IS_ON){
                                              PID_TOF_IS_ON = false;
                                              PID_ROT_IS_ON = true;
                                              time = millis();
                                              desiredYaw = 130;
                                              Serial.println("222");
                                            }
                                          
                                            if(PID_ROT_IS_ON && (millis() - time >= 1500)){
                                              PID_ROT_IS_ON = false;
                                              speedFB = maxPWM;
                                              speedL = maxPWM;
                                              speedR = maxPWM;
                                              delay(1000);
                                              wheelBrkCtrl(100);
                                              firstLoop = true;
                                              startStunts = false;
                                              Serial.print("333");
                                            }
                                          
                                          }
                                    
                                

If we transmit the control sequence in real time using BLE, the code on the PC is shown below:
                                    
                                        ble.send_command(CMD.SET_TARGET_DIS, "912")
                                        ble.send_command(CMD.PID_TOF_ON, "120")
                                        time.sleep(1.3)
                                        ble.send_command(CMD.PID_TOF_OFF, "")
                                        ble.send_command(CMD.PID_ROT_ON, "")
                                        ble.send_command(CMD.SET_TARGET_YAW, "180")
                                        time.sleep(0.8)
                                        ble.send_command(CMD.PID_ROT_OFF, "")
                                        ble.send_command(CMD.MOVE_FB, "150")
                                        time.sleep(1)
                                        ble.send_command(CMD.STOP, "")
                                    
                                



The result can be shown in the following videos. The car marches atf full speed to the wall, while the distance PID controller is operating. When the distance reaches the setpoint, the distance PID controller will be shutdown and the rotational PID controller will be opened (with the angle setpoint to be given as 180 degrees, so that the car will turn around immediately). Since the PID controllers will call the wheels breaking function (force stop the motors and set the speed to zero), we'll see a temporary stop of the car before it turns around.

Slow version


Faster version


The speed when the car make a 180-degree turn is to be improved since the two PID controllers will set the wheel speed to zero when they are shut down.


THE END