mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-12-22 13:35:49 +00:00
Fix UI range
Change colour to string Fix distance counting
This commit is contained in:
parent
a02bb51d7e
commit
34114e1b55
|
@ -145,7 +145,7 @@
|
||||||
<td style="text-align: center;" colspan="6"><strong>Set Translation to: </strong><strong id="SetTrans" style="font-size: 18px;">180</strong><strong>mm</strong></td>
|
<td style="text-align: center;" colspan="6"><strong>Set Translation to: </strong><strong id="SetTrans" style="font-size: 18px;">180</strong><strong>mm</strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6"><input type ="range" min="-200" max="100" value="0" class="slider" id="TranSlider"></td>
|
<td colspan="6"><input type ="range" min="-200" max="200" value="0" class="slider" id="TranSlider"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: center;" colspan="6"><strong>Set Speed to: </strong><strong id="SetSpd" style="font-size: 18px;">50</strong><strong>%</strong></td>
|
<td style="text-align: center;" colspan="6"><strong>Set Speed to: </strong><strong id="SetSpd" style="font-size: 18px;">50</strong><strong>%</strong></td>
|
||||||
|
@ -260,7 +260,7 @@
|
||||||
batteryVoltage = data.bV;
|
batteryVoltage = data.bV;
|
||||||
batteryCycles = data.bC;
|
batteryCycles = data.bC;
|
||||||
totalTripDistance = data.tD;
|
totalTripDistance = data.tD;
|
||||||
currentHeading = data.cH;
|
currentHeading = data.cH + 180;
|
||||||
current_pos = data.pos;
|
current_pos = data.pos;
|
||||||
current_x = current_pos[0];
|
current_x = current_pos[0];
|
||||||
current_y = current_pos[1];
|
current_y = current_pos[1];
|
||||||
|
@ -294,7 +294,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_data() {
|
function send_data() {
|
||||||
var raw_data = '{"Cid":' + command_id + ',"mode":' + mode + ',"rH":' + reqHeading + ',"rD":' + reqDistance + ',"rS":' + reqSpeed + ',"rC":' + reqCharge + ',"pSt":' + pstop_time + ',"col":' + hunt_colour + '}';
|
var raw_data = '{"Cid":' + command_id + ',"mode":' + mode + ',"rH":' + reqHeading + ',"rD":' + reqDistance + ',"rS":' + reqSpeed + ',"rC":' + reqCharge + ',"pSt":' + pstop_time + ',"col":"' + hunt_colour + '"}';
|
||||||
connection.send(raw_data);
|
connection.send(raw_data);
|
||||||
console.log(raw_data);
|
console.log(raw_data);
|
||||||
}
|
}
|
||||||
|
@ -313,10 +313,12 @@
|
||||||
bufferOutput = "charge " + reqCharge + "%";
|
bufferOutput = "charge " + reqCharge + "%";
|
||||||
}else if(cmdMode == 3){
|
}else if(cmdMode == 3){
|
||||||
bufferOutput = "wait " + pstop_time + "s";
|
bufferOutput = "wait " + pstop_time + "s";
|
||||||
|
}else if(cmdMode == 4){
|
||||||
|
bufferOutput = "colour " + hunt_colour;
|
||||||
}else if(cmdMode == -1){
|
}else if(cmdMode == -1){
|
||||||
bufferOutput = "telemetry reset";
|
bufferOutput = "telemetry reset";
|
||||||
}
|
}
|
||||||
if((mode == 1) || (mode == -1) || (mode == 2) || (mode == 3)){
|
if((mode == 1) || (mode == -1) || (mode == 2) || (mode == 3) || (mode == 4)){
|
||||||
document.getElementById("command_buffer").innerHTML += '[' + command_id + '] ' + bufferOutput + "<br>";
|
document.getElementById("command_buffer").innerHTML += '[' + command_id + '] ' + bufferOutput + "<br>";
|
||||||
document.getElementById("commandInput").value = ""
|
document.getElementById("commandInput").value = ""
|
||||||
}else if(mode == 0){
|
}else if(mode == 0){
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#ifndef INSTRUCTION_H
|
#ifndef INSTRUCTION_H
|
||||||
#define INSTRUCTION_H
|
#define INSTRUCTION_H
|
||||||
|
#include <string>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
INSTR_RESET = -1,
|
INSTR_RESET = -1,
|
||||||
|
@ -19,7 +20,7 @@ typedef struct instruction
|
||||||
float speed;
|
float speed;
|
||||||
int charge;
|
int charge;
|
||||||
int time;
|
int time;
|
||||||
int colour;
|
String colour;
|
||||||
} RoverInstruction;
|
} RoverInstruction;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -73,7 +73,7 @@ int bb_left, bb_right, bb_top, bb_bottom;
|
||||||
int bb_centre_x, bb_centre_y;
|
int bb_centre_x, bb_centre_y;
|
||||||
float chargeGoal;
|
float chargeGoal;
|
||||||
int waitGoal;
|
int waitGoal;
|
||||||
Colour_t colour;
|
String colour;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
|
@ -204,7 +204,7 @@ void loop()
|
||||||
case INSTR_COLOUR:
|
case INSTR_COLOUR:
|
||||||
{
|
{
|
||||||
Status = CS_IDLE;
|
Status = CS_IDLE;
|
||||||
colour = (Colour_t)instr->colour;
|
colour = instr->colour;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -362,7 +362,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length)
|
||||||
Serial.println("Change colour tracking command received");
|
Serial.println("Change colour tracking command received");
|
||||||
instr.id = rdoc["Cid"];
|
instr.id = rdoc["Cid"];
|
||||||
instr.instr = INSTR_COLOUR;
|
instr.instr = INSTR_COLOUR;
|
||||||
instr.colour = rdoc["col"];
|
String temp = rdoc["col"];
|
||||||
|
instr.colour = temp;
|
||||||
// Ignore rdoc["rH"], rdoc["rD"], rdoc["rS"], rdoc["rC"]
|
// Ignore rdoc["rH"], rdoc["rD"], rdoc["rS"], rdoc["rC"]
|
||||||
|
|
||||||
queueInstruction(instr); // Put charge command in InstrQueue
|
queueInstruction(instr); // Put charge command in InstrQueue
|
||||||
|
|
|
@ -460,6 +460,10 @@ void loop()
|
||||||
digitalWrite(pwmr, LOW);
|
digitalWrite(pwmr, LOW);
|
||||||
digitalWrite(pwml, LOW);
|
digitalWrite(pwml, LOW);
|
||||||
commandCompletionStatus = 3;
|
commandCompletionStatus = 3;
|
||||||
|
}else if (rdoc.containsKey("rstD") && rdoc["rstD"] == 1){
|
||||||
|
goal_x = 0;
|
||||||
|
goal_y = 0;
|
||||||
|
distTravelled_mm = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,7 +478,7 @@ void loop()
|
||||||
//Serial.println("status0");
|
//Serial.println("status0");
|
||||||
}
|
}
|
||||||
if (commandCompletionStatus == 1)
|
if (commandCompletionStatus == 1)
|
||||||
{ Serial.println("status1");
|
{ //Serial.println("status1");
|
||||||
//newCommand
|
//newCommand
|
||||||
//set goals
|
//set goals
|
||||||
goal_x += distance * sin(requiredHeading);
|
goal_x += distance * sin(requiredHeading);
|
||||||
|
@ -567,7 +571,7 @@ void loop()
|
||||||
commandComplete = true;
|
commandComplete = true;
|
||||||
current_x = goal_x;
|
current_x = goal_x;
|
||||||
current_y = goal_y;
|
current_y = goal_y;
|
||||||
distTravelled_mm += distance;
|
distTravelled_mm += abs(distance);
|
||||||
|
|
||||||
//compile energy use
|
//compile energy use
|
||||||
unsigned long currentMillis_Energy = millis();
|
unsigned long currentMillis_Energy = millis();
|
||||||
|
@ -595,6 +599,7 @@ void loop()
|
||||||
tdoc["mm"] = distTravelled_mm;
|
tdoc["mm"] = distTravelled_mm;
|
||||||
tdoc["pos"][0] = current_x;
|
tdoc["pos"][0] = current_x;
|
||||||
tdoc["pos"][1] = current_y;
|
tdoc["pos"][1] = current_y;
|
||||||
|
tdoc["bV"] = vb;
|
||||||
serializeJson(tdoc, Serial1); // Build JSON and send on UART1
|
serializeJson(tdoc, Serial1); // Build JSON and send on UART1
|
||||||
serializeJson(tdoc, Serial); // Build JSON and send on UART1
|
serializeJson(tdoc, Serial); // Build JSON and send on UART1
|
||||||
commandCompletionStatus = 0;
|
commandCompletionStatus = 0;
|
||||||
|
@ -604,7 +609,7 @@ void loop()
|
||||||
//find motor voltage
|
//find motor voltage
|
||||||
//int motorVSensor = analogRead(A5);
|
//int motorVSensor = analogRead(A5);
|
||||||
//float motorVoltage = motorVSensor * (5.0 / 1023.0);
|
//float motorVoltage = motorVSensor * (5.0 / 1023.0);
|
||||||
float motorVoltage = 5;
|
float motorVoltage = vb;
|
||||||
|
|
||||||
//find average power
|
//find average power
|
||||||
|
|
||||||
|
@ -749,10 +754,11 @@ void sampling(){
|
||||||
// The analogRead process gives a value between 0 and 1023
|
// The analogRead process gives a value between 0 and 1023
|
||||||
// representing a voltage between 0 and the analogue reference which is 4.096V
|
// representing a voltage between 0 and the analogue reference which is 4.096V
|
||||||
|
|
||||||
vb = sensorValue0 * (4.096 / 1023.0); // Convert the Vb sensor reading to volts
|
vb = sensorValue0 * (4.94 / 1023.0); // Convert the Vb sensor reading to volts
|
||||||
vref = sensorValue2 * (4.096 / 1023.0); // Convert the Vref sensor reading to volts
|
vref = sensorValue2 * (4.096 / 1023.0); // Convert the Vref sensor reading to volts
|
||||||
vpd = sensorValue3 * (4.096 / 1023.0); // Convert the Vpd sensor reading to volts
|
vpd = sensorValue3 * (4.096 / 1023.0); // Convert the Vpd sensor reading to volts
|
||||||
|
|
||||||
|
|
||||||
// The inductor current is in mA from the sensor so we need to convert to amps.
|
// The inductor current is in mA from the sensor so we need to convert to amps.
|
||||||
// We want to treat it as an input current in the Boost, so its also inverted
|
// We want to treat it as an input current in the Boost, so its also inverted
|
||||||
// For open loop control the duty cycle reference is calculated from the sensor
|
// For open loop control the duty cycle reference is calculated from the sensor
|
||||||
|
|
Loading…
Reference in a new issue