mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-11-10 01:35:50 +00:00
Add external compass input
This commit is contained in:
parent
aadb52990e
commit
2c135f118a
|
@ -29,6 +29,8 @@
|
||||||
#define TX2pin 16 // Pin 9 on expansion board, UART2
|
#define TX2pin 16 // Pin 9 on expansion board, UART2
|
||||||
#define RX3pin 14 // Pin 10 on expansion board, UART3
|
#define RX3pin 14 // Pin 10 on expansion board, UART3
|
||||||
#define TX3pin 4 // Pin 11 on expansion board, UART3
|
#define TX3pin 4 // Pin 11 on expansion board, UART3
|
||||||
|
#define RX4pin 15 // Pin 12 on expansion board, UART4
|
||||||
|
#define TX4pin 2 // Pin 13 on expansion board, UART4
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Function Declarations
|
#pragma region Function Declarations
|
||||||
|
@ -42,6 +44,7 @@ void sendToEnergy(bool instruction);
|
||||||
void recvFromEnergy();
|
void recvFromEnergy();
|
||||||
void sendToVision();
|
void sendToVision();
|
||||||
void recvFromVision();
|
void recvFromVision();
|
||||||
|
void recvFromCompass();
|
||||||
void emergencyStop();
|
void emergencyStop();
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@ void emergencyStop();
|
||||||
AsyncWebServer webserver(80);
|
AsyncWebServer webserver(80);
|
||||||
WebSocketsServer websocketserver(81);
|
WebSocketsServer websocketserver(81);
|
||||||
Ticker ticker;
|
Ticker ticker;
|
||||||
SoftwareSerial Serial3;
|
SoftwareSerial Serial3, Serial4;
|
||||||
std::queue<RoverInstruction> InstrQueue;
|
std::queue<RoverInstruction> InstrQueue;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
@ -79,6 +82,7 @@ void setup()
|
||||||
Serial1.begin(9600, SERIAL_8N1, RX1pin, TX1pin); // Set up hardware UART1 (Connected to Drive)
|
Serial1.begin(9600, SERIAL_8N1, RX1pin, TX1pin); // Set up hardware UART1 (Connected to Drive)
|
||||||
Serial2.begin(9600, SERIAL_8N1, RX2pin, TX2pin); // Set up hardware UART2 (Connected to Energy)
|
Serial2.begin(9600, SERIAL_8N1, RX2pin, TX2pin); // Set up hardware UART2 (Connected to Energy)
|
||||||
Serial3.begin(9600, SWSERIAL_8N1, RX3pin, TX3pin); // Set up software UART3 (Connected to Vision)
|
Serial3.begin(9600, SWSERIAL_8N1, RX3pin, TX3pin); // Set up software UART3 (Connected to Vision)
|
||||||
|
Serial4.begin(115200, SWSERIAL_8N1, RX4pin, TX4pin); // Set up software UART4 (Connected to Compass)
|
||||||
|
|
||||||
// Set global variable startup values
|
// Set global variable startup values
|
||||||
Status = CS_IDLE;
|
Status = CS_IDLE;
|
||||||
|
@ -131,7 +135,8 @@ void loop()
|
||||||
websocketserver.loop(); // Handle incoming client connections
|
websocketserver.loop(); // Handle incoming client connections
|
||||||
recvFromDrive(); // Update stats from Drive
|
recvFromDrive(); // Update stats from Drive
|
||||||
recvFromEnergy(); // Update stats from Energy
|
recvFromEnergy(); // Update stats from Energy
|
||||||
recvFromVision(); // Update stats from Vision
|
// recvFromVision(); // Update stats from Vision
|
||||||
|
recvFromCompass(); // Update stats from Compass
|
||||||
switch (Status)
|
switch (Status)
|
||||||
{
|
{
|
||||||
case CS_ERROR:
|
case CS_ERROR:
|
||||||
|
@ -216,7 +221,6 @@ void loop()
|
||||||
sendToEnergy(0); // Stop charging if goal reached
|
sendToEnergy(0); // Stop charging if goal reached
|
||||||
}
|
}
|
||||||
// Otherwise continue charging, no change
|
// Otherwise continue charging, no change
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -420,6 +424,16 @@ void recvFromVision() // Update bounding box and obstacle detection data from Vi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void recvFromCompass()
|
||||||
|
{
|
||||||
|
if (Serial4.available())
|
||||||
|
{
|
||||||
|
DynamicJsonDocument rdoc(128);
|
||||||
|
deserializeJson(rdoc, Serial4);
|
||||||
|
heading = rdoc["cH"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void emergencyStop()
|
void emergencyStop()
|
||||||
{
|
{
|
||||||
DynamicJsonDocument tdoc(1024);
|
DynamicJsonDocument tdoc(1024);
|
||||||
|
|
Loading…
Reference in a new issue