Add emergency stop function

This commit is contained in:
Aadi Desai 2021-06-13 17:26:50 +01:00
parent 39603efd3c
commit 0483397ae6
2 changed files with 12 additions and 4 deletions

View file

@ -18,8 +18,8 @@ void loop()
DynamicJsonDocument rdoc(1024); // receive doc, not sure how big this needs to be
deserializeJson(rdoc, Serial1); // Take JSON input from UART1
int requiredHeading = rdoc["rH"]; // if -1: command in progress, returning requested heading, dist/sp to be ignored
int distance = rdoc["dist"];
float speed = rdoc["sp"];
int distance = rdoc["dist"]; // -1 for emergency stop
float speed = rdoc["sp"]; // -1 for emergency stop
int currentHeading = rdoc["cH"];
bool resetDistanceTravelled = rdoc["rstD"];

View file

@ -357,12 +357,20 @@ void recvFromVision() // TO DO
{
}
void emergencyStop() // TO DO
void emergencyStop()
{
// Send stop signals to drive, energy
DynamicJsonDocument tdoc(1024);
tdoc["rH"] = heading;
tdoc["dist"] = -1;
tdoc["sp"] = -1;
tdoc["cH"] = heading;
tdoc["ch"] = 0;
serializeJson(tdoc, Serial1); // Send stop signals to Drive
serializeJson(tdoc, Serial2); // Send stop signals to Energy
while (InstrQueue.size())
{
InstrQueue.pop(); // Clear Instruction Queue
}
Status = CS_IDLE; // Reset rover to idle state
Serial.println("Instruction Queue cleared");
}