Fix UI range

Change colour to string
Fix distance counting
This commit is contained in:
Mee2001 2021-06-15 12:57:28 +01:00
parent a02bb51d7e
commit 34114e1b55
4 changed files with 22 additions and 12 deletions

View file

@ -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>
</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>
<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;
batteryCycles = data.bC;
totalTripDistance = data.tD;
currentHeading = data.cH;
currentHeading = data.cH + 180;
current_pos = data.pos;
current_x = current_pos[0];
current_y = current_pos[1];
@ -294,7 +294,7 @@
}
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);
console.log(raw_data);
}
@ -313,10 +313,12 @@
bufferOutput = "charge " + reqCharge + "%";
}else if(cmdMode == 3){
bufferOutput = "wait " + pstop_time + "s";
}else if(cmdMode == 4){
bufferOutput = "colour " + hunt_colour;
}else if(cmdMode == -1){
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("commandInput").value = ""
}else if(mode == 0){

View file

@ -1,5 +1,6 @@
#ifndef INSTRUCTION_H
#define INSTRUCTION_H
#include <string>
typedef enum {
INSTR_RESET = -1,
@ -19,7 +20,7 @@ typedef struct instruction
float speed;
int charge;
int time;
int colour;
String colour;
} RoverInstruction;
#endif

View file

@ -73,7 +73,7 @@ int bb_left, bb_right, bb_top, bb_bottom;
int bb_centre_x, bb_centre_y;
float chargeGoal;
int waitGoal;
Colour_t colour;
String colour;
#pragma endregion
void setup()
@ -204,7 +204,7 @@ void loop()
case INSTR_COLOUR:
{
Status = CS_IDLE;
colour = (Colour_t)instr->colour;
colour = instr->colour;
}
break;
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");
instr.id = rdoc["Cid"];
instr.instr = INSTR_COLOUR;
instr.colour = rdoc["col"];
String temp = rdoc["col"];
instr.colour = temp;
// Ignore rdoc["rH"], rdoc["rD"], rdoc["rS"], rdoc["rC"]
queueInstruction(instr); // Put charge command in InstrQueue

View file

@ -460,6 +460,10 @@ void loop()
digitalWrite(pwmr, LOW);
digitalWrite(pwml, LOW);
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");
}
if (commandCompletionStatus == 1)
{ Serial.println("status1");
{ //Serial.println("status1");
//newCommand
//set goals
goal_x += distance * sin(requiredHeading);
@ -567,7 +571,7 @@ void loop()
commandComplete = true;
current_x = goal_x;
current_y = goal_y;
distTravelled_mm += distance;
distTravelled_mm += abs(distance);
//compile energy use
unsigned long currentMillis_Energy = millis();
@ -595,6 +599,7 @@ void loop()
tdoc["mm"] = distTravelled_mm;
tdoc["pos"][0] = current_x;
tdoc["pos"][1] = current_y;
tdoc["bV"] = vb;
serializeJson(tdoc, Serial1); // Build JSON and send on UART1
serializeJson(tdoc, Serial); // Build JSON and send on UART1
commandCompletionStatus = 0;
@ -604,7 +609,7 @@ void loop()
//find motor voltage
//int motorVSensor = analogRead(A5);
//float motorVoltage = motorVSensor * (5.0 / 1023.0);
float motorVoltage = 5;
float motorVoltage = vb;
//find average power
@ -749,10 +754,11 @@ void sampling(){
// The analogRead process gives a value between 0 and 1023
// 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
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.
// 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