diff --git a/Control/data/index.html b/Control/data/index.html index 73775ff..aa07511 100644 --- a/Control/data/index.html +++ b/Control/data/index.html @@ -145,7 +145,7 @@ Set Translation to: 180mm - + Set Speed to: 50% @@ -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 + "
"; document.getElementById("commandInput").value = "" }else if(mode == 0){ diff --git a/Control/include/instruction.h b/Control/include/instruction.h index dc110bb..d319cdd 100644 --- a/Control/include/instruction.h +++ b/Control/include/instruction.h @@ -1,5 +1,6 @@ #ifndef INSTRUCTION_H #define INSTRUCTION_H +#include typedef enum { INSTR_RESET = -1, @@ -19,7 +20,7 @@ typedef struct instruction float speed; int charge; int time; - int colour; + String colour; } RoverInstruction; #endif diff --git a/Control/src/main.cpp b/Control/src/main.cpp index 658cc1c..3022e8a 100644 --- a/Control/src/main.cpp +++ b/Control/src/main.cpp @@ -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 diff --git a/Drive/src/main.cpp b/Drive/src/main.cpp index e346166..dda6f59 100644 --- a/Drive/src/main.cpp +++ b/Drive/src/main.cpp @@ -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