mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-12-22 13:35:49 +00:00
Add ability to select Vision colour tracking
This commit is contained in:
parent
bbe36fb9dd
commit
c98bafd6f7
12
Control/include/colour.h
Normal file
12
Control/include/colour.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef COLOUR_H
|
||||
#define COLOUR_H
|
||||
|
||||
typedef enum {
|
||||
C_RED,
|
||||
C_LBLUE,
|
||||
C_GREEN,
|
||||
C_PINK,
|
||||
C_ORANGE
|
||||
} Colour_t;
|
||||
|
||||
#endif
|
|
@ -6,7 +6,8 @@ typedef enum {
|
|||
INSTR_STOP,
|
||||
INSTR_MOVE,
|
||||
INSTR_CHARGE,
|
||||
INSTR_WAIT
|
||||
INSTR_WAIT,
|
||||
INSTR_COLOUR
|
||||
} instr_t;
|
||||
|
||||
typedef struct instruction
|
||||
|
@ -18,6 +19,7 @@ typedef struct instruction
|
|||
float speed;
|
||||
int charge;
|
||||
int time;
|
||||
Colour_t colour;
|
||||
} RoverInstruction;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <SPIFFS.h>
|
||||
#include "status.h"
|
||||
#include "instruction.h"
|
||||
#include "colour.h"
|
||||
#include <queue>
|
||||
#pragma endregion
|
||||
|
||||
|
@ -71,6 +72,7 @@ int bb_left, bb_right, bb_top, bb_bottom;
|
|||
int bb_centre_x, bb_centre_y;
|
||||
float chargeGoal;
|
||||
int waitGoal;
|
||||
Colour_t colour;
|
||||
#pragma endregion
|
||||
|
||||
void setup()
|
||||
|
@ -100,6 +102,7 @@ void setup()
|
|||
driveCommandComplete = 1;
|
||||
chargeGoal = 0;
|
||||
waitGoal = 0;
|
||||
colour = C_RED;
|
||||
|
||||
if (!SPIFFS.begin(true)) // Mount SPIFFS
|
||||
{
|
||||
|
@ -196,6 +199,12 @@ void loop()
|
|||
waitGoal = millis() + 1000*(instr->time); // Set wait time
|
||||
}
|
||||
break;
|
||||
case INSTR_COLOUR:
|
||||
{
|
||||
Status = CS_IDLE;
|
||||
colour = instr->colour;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Serial.println("Unknown instruction type in queue, skipping...");
|
||||
|
@ -346,6 +355,17 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length)
|
|||
queueInstruction(instr); // Put charge command in InstrQueue
|
||||
}
|
||||
break;
|
||||
case 4: // Normal wait command, results in no motion, added to end of command cache
|
||||
{
|
||||
Serial.println("Change colour tracking command received");
|
||||
instr.id = rdoc["Cid"];
|
||||
instr.instr = INSTR_COLOUR;
|
||||
instr.colour = rdoc["col"];
|
||||
// Ignore rdoc["rH"], rdoc["rD"], rdoc["rS"], rdoc["rC"]
|
||||
|
||||
queueInstruction(instr); // Put charge command in InstrQueue
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// Default case, print and continue
|
||||
|
@ -437,7 +457,7 @@ void recvFromEnergy() // Update telemetry data and state info from Energy packet
|
|||
|
||||
void sendToVision()
|
||||
{
|
||||
Serial3.print("R"); // Request new data from Vision
|
||||
Serial3.print(colour); // Select coloured ball to track
|
||||
}
|
||||
|
||||
void recvFromVision() // Update bounding box and obstacle detection data from Vision packet
|
||||
|
|
Loading…
Reference in a new issue