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.
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.
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");
}
}
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 END