Skip to content

Commit 6a95168

Browse files
committed
fix flag mask bug
1 parent 9881a26 commit 6a95168

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

OnPod/FlightComputer/src/States.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ bool PodState::isNodeSensorCritical(uint32_t sensorIndex) {
5555
}
5656

5757
bool PodState::isConnectionFlagCritical(uint32_t sensorIndex) {
58-
uint32_t criticalMask = CONNECTION_FLAGS::BRAKE_NODE_HEARTBEAT_INDEX |
59-
CONNECTION_FLAGS::LVDC_NODE_HEARTBEAT_INDEX |
60-
CONNECTION_FLAGS::BMS_HEARTBEAT_INDEX |
61-
CONNECTION_FLAGS::INTERFACE_HEARTBEAT_INDEX |
62-
CONNECTION_FLAGS::ENCLOSURE_HEARTBEAT_INDEX |
63-
CONNECTION_FLAGS::NAVIGATION_HEARTBEAT_INDEX;
64-
return sensorIndex & criticalMask;
58+
std::vector<int> criticalSensors = {CONNECTION_FLAGS::BRAKE_NODE_HEARTBEAT_INDEX,
59+
CONNECTION_FLAGS::LVDC_NODE_HEARTBEAT_INDEX,
60+
CONNECTION_FLAGS::BMS_HEARTBEAT_INDEX,
61+
CONNECTION_FLAGS::INTERFACE_HEARTBEAT_INDEX,
62+
CONNECTION_FLAGS::ENCLOSURE_HEARTBEAT_INDEX,
63+
CONNECTION_FLAGS::NAVIGATION_HEARTBEAT_INDEX};
64+
return std::find(criticalSensors.begin(), criticalSensors.end(), sensorIndex) != criticalSensors.end();
6565
}
6666

6767
bool PodState::isInverterSensorCritical(uint32_t sensorIndex) {
@@ -148,7 +148,6 @@ void PodState::armedChecks(){
148148
std::string error = "Failed on inverter fault, see pod messages";
149149
throw std::runtime_error(error);
150150
}
151-
152151
}
153152

154153
bool PodState::brakingCriteriaMet() {
@@ -163,6 +162,7 @@ bool PodState::brakingCriteriaMet() {
163162
pod->sendUpdate("Braking at maximum strip count");
164163
return true;
165164
}
165+
166166
return false;
167167
}
168168

@@ -440,6 +440,10 @@ bool Acceleration::testTransitions() {
440440
this->setupTransition(psBraking, (std::string)" Flight Timout of " + std::to_string(this->timeInStateSeconds()) + " reached. Pod --> Braking");
441441
return true;
442442
}
443+
444+
if(this->pod->telemetry->motorSpeed >= pod->telemetry->maxRPM){
445+
this->setupTransition(psCoasting, "Acceleration->Coasting from maximum speed");
446+
}
443447
return false;
444448
}
445449

@@ -450,7 +454,8 @@ Coasting::Coasting(TelemetryManager* pod) : PodState(pod) {
450454
this->pod->telemetry->commandedTorque = 0;
451455
}
452456

453-
bool Coasting::testTransitions() {
457+
bool Coasting::testTransitions() {
458+
this->pod->telemetry->commandedTorque = 0;
454459
if(this->pod->getControlsInterfaceState() == ciEmergencyStop){
455460
this->setupTransition(psBraking, "Emergency Stop. Pod --> Braking");
456461
return true;

OnPod/FlightComputer/src/TelemetryManager.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,10 @@ void TelemetryManager::setMotorSpeed(int32_t value) {
361361
auto thisTime = std::chrono::high_resolution_clock::now();
362362
this->telemetry->lastMotorReadTime = thisTime;
363363
int32_t lastRPM = this->telemetry->motorSpeed;
364-
this->telemetry->motorSpeed = value;
365-
364+
this->telemetry->motorSpeed = value;
366365
float average = (value+lastRPM)/2.0;
367366
average /= (1000.0*60.0);
368367

369-
if (average < this->telemetry->maxRPM) {
370-
this->telemetry->motorSpeed = value;
371-
}
372-
else {
373-
this->telemetry->motorSpeed = 0;
374-
}
375-
376368
float milliseconds = (std::chrono::duration_cast<std::chrono::microseconds>(thisTime - lastTime).count())/1000.0;
377369
float distance = average*milliseconds * GENERAL_CONSTANTS::REAR_WHEEL_CIRCUMFRENCE;
378370
addPodDistance(distance);

OnPod/FlightComputer/src/Threads/CommanderThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void parseProtoCommand(PodCommand podCommand, TelemetryManager *Pod) {
9696
Pod->telemetry->taxi = podCommand.taxi();
9797
Pod->telemetry->expectedTubePressure = podCommand.expectedtubepressure();
9898
Pod->telemetry->maxVelocity = podCommand.maxvelocity();
99-
Pod->telemetry->maxRPM = Pod->telemetry->maxVelocity / GENERAL_CONSTANTS::REAR_WHEEL_CIRCUMFRENCE;
99+
Pod->telemetry->maxRPM = podCommand.maxvelocity() / GENERAL_CONSTANTS::REAR_WHEEL_CIRCUMFRENCE;
100100
Pod->telemetry->brakeDistance = podCommand.brakingdistance();
101101
if(!podCommand.taxi()) {
102102
Pod->telemetry->maxStripCount = ( (Pod->telemetry->flightDistance - Pod->telemetry->brakeDistance) /

0 commit comments

Comments
 (0)