Skip to content

Commit d3a157f

Browse files
committed
Merge branch 'master' into navigation_testing
2 parents 0dcc127 + b1c0ae8 commit d3a157f

File tree

3 files changed

+109
-77
lines changed

3 files changed

+109
-77
lines changed

OnPod/FlightComputer/include/States.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class PodState{
1818

1919
virtual bool testTransitions();
2020

21-
bool isNodeSensorCritical(int);
21+
bool isNodeSensorCritical(uint32_t);
2222

23-
bool isConnectionFlagCritical(int);
23+
bool isConnectionFlagCritical(uint32_t);
2424

25-
bool isInverterSensorCritical(int);
25+
bool isInverterSensorCritical(uint32_t);
2626

2727
bool brakingCriteriaMet();
2828

OnPod/FlightComputer/src/Constants/Constants.h

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,110 @@
44

55
namespace GENERAL_CONSTANTS
66
{
7-
static const int32_t VACUUM = 0;
8-
static const int32_t ATMOSPHERE = 15;
7+
static const uint32_t VACUUM = 0;
8+
static const uint32_t ATMOSPHERE = 15;
99

10-
static const int32_t CLOSED = 0;
11-
static const int32_t OPEN = 1;
10+
static const uint32_t CLOSED = 0;
11+
static const uint32_t OPEN = 1;
1212

1313
static const int32_t FLAGS_GOOD = -1;
1414

1515
static const float REAR_WHEEL_CIRCUMFRENCE = 0.933619f;
1616
static const float STRIP_DISTANCE = 30.48;
1717

18-
static const int32_t NAV_SERIAL_MESSAGE_SIZE = 10;
18+
static const uint32_t NAV_SERIAL_MESSAGE_SIZE = 7;
1919
};
2020

2121
namespace CONNECTION_FLAGS
2222
{
23-
static const int32_t TOTAL_CONNECTION_COUNT = 6; // update if you add
24-
static const int32_t BRAKE_NODE_HEARTBEAT_INDEX = 0;
25-
static const int32_t LVDC_NODE_HEARTBEAT_INDEX = 1;
26-
static const int32_t BMS_HEARTBEAT_INDEX = 2;
27-
static const int32_t INTERFACE_HEARTBEAT_INDEX = 3;
28-
static const int32_t ENCLOSURE_HEARTBEAT_INDEX = 4;
29-
static const int32_t NAVIGATION_HEARTBEAT_INDEX = 5;
23+
static const uint32_t TOTAL_CONNECTION_COUNT = 6; // update if you add
24+
static const uint32_t BRAKE_NODE_HEARTBEAT_INDEX = 0;
25+
static const uint32_t LVDC_NODE_HEARTBEAT_INDEX = 1;
26+
static const uint32_t BMS_HEARTBEAT_INDEX = 2;
27+
static const uint32_t INTERFACE_HEARTBEAT_INDEX = 3;
28+
static const uint32_t ENCLOSURE_HEARTBEAT_INDEX = 4;
29+
static const uint32_t NAVIGATION_HEARTBEAT_INDEX = 5;
3030
};
3131

3232
// Inverter Sensor Flag Indices
33-
namespace INVERTER_FLAGS
33+
namespace INVERTER_FLAGS
3434
{
35-
static const int32_t INVERTER_SENSOR_COUNT = 5; // update if you add
36-
static const int32_t MOTOR_TEMPERATURE_INDEX = 0;
37-
static const int32_t BUS_VOLTAGE_INDEX = 1;
38-
static const int32_t GATE_DRIVER_TEMP_INDEX = 2;
39-
static const int32_t CONTROL_BOARD_TEMP_INDEX = 3;
40-
static const int32_t MAX_IGBT_INDEX = 4;
41-
35+
static const uint32_t INVERTER_SENSOR_COUNT = 5; // update if you add
36+
static const uint32_t MOTOR_TEMPERATURE_INDEX = 0;
37+
static const uint32_t BUS_VOLTAGE_INDEX = 1;
38+
static const uint32_t GATE_DRIVER_TEMP_INDEX = 2;
39+
static const uint32_t CONTROL_BOARD_TEMP_INDEX = 3;
40+
static const uint32_t MAX_IGBT_INDEX = 4;
4241

4342
static const int32_t INVERTER_FAULT_COUNT = 4;
4443
static const int32_t POST_FAULT_LO_INDEX = 0;
4544
static const int32_t POST_FAULT_HI_INDEX = 1;
4645
static const int32_t RUN_FAULT_LO_INDEX = 2;
4746
static const int32_t RUN_FAULT_HI_INDEX = 3;
48-
4947
};
5048

49+
// Inverter Hi Fault mapping
50+
namespace INVERTER_RUN_FAULT_HI
51+
{
52+
static const uint32_t RESOLVER_NOT_CONNECTED = 0x4000;
53+
}
54+
5155
// BMS Sensor Flag Indices
52-
namespace BMS_FLAGS
56+
namespace BMS_FLAGS
5357
{
54-
static const int32_t BMS_SENSOR_COUNT = 9; // update if you add
55-
static const int32_t HV_PACK_VOLTAGE_INDEX = 0;
56-
static const int32_t HV_MAX_CELL_TEMP_INDEX = 1;
57-
static const int32_t HV_SOC_INDEX = 2;
58-
59-
static const int32_t LV1_PACK_VOLTAGE_INDEX = 3;
60-
static const int32_t LV1_CELL_TEMP_INDEX = 4;
61-
static const int32_t LV1_SOC_INDEX = 5;
62-
63-
static const int32_t LV2_PACK_VOLTAGE_INDEX = 6;
64-
static const int32_t LV2_CELL_TEMP_INDEX = 7;
65-
static const int32_t LV2_SOC_INDEX = 8;
58+
static const uint32_t BMS_SENSOR_COUNT = 9; // update if you add
59+
static const uint32_t HV_PACK_VOLTAGE_INDEX = 0;
60+
static const uint32_t HV_MAX_CELL_TEMP_INDEX = 1;
61+
static const uint32_t HV_SOC_INDEX = 2;
62+
63+
static const uint32_t LV1_PACK_VOLTAGE_INDEX = 3;
64+
static const uint32_t LV1_CELL_TEMP_INDEX = 4;
65+
static const uint32_t LV1_SOC_INDEX = 5;
66+
67+
static const uint32_t LV2_PACK_VOLTAGE_INDEX = 6;
68+
static const uint32_t LV2_CELL_TEMP_INDEX = 7;
69+
static const uint32_t LV2_SOC_INDEX = 8;
6670
};
6771

6872
// Node Sensor Flag indices
69-
namespace NODE_FLAGS
73+
namespace NODE_FLAGS
7074
{
71-
static const int32_t NODE_SENSOR_COUNT = 10; // update if you add
72-
static const int32_t LP1_INDEX = 0;
73-
static const int32_t LP2_INDEX = 1;
74-
static const int32_t LP3_INDEX = 2;
75-
static const int32_t LP4_INDEX = 3;
76-
static const int32_t HP_INDEX = 4;
77-
static const int32_t HP_TEMP_INDEX = 5;
78-
static const int32_t ENCLOSURE_PRESSURE_INDEX = 6;
79-
static const int32_t ENCLOSURE_TEMPERATURE_INDEX = 7;
80-
static const int32_t COOLING_PRESSURE_INDEX = 8;
81-
static const int32_t COOLING_TEMPERATURE_INDEX = 9;
75+
static const uint32_t NODE_SENSOR_COUNT = 10; // update if you add
76+
static const uint32_t LP1_INDEX = 0;
77+
static const uint32_t LP2_INDEX = 1;
78+
static const uint32_t LP3_INDEX = 2;
79+
static const uint32_t LP4_INDEX = 3;
80+
static const uint32_t HP_INDEX = 4;
81+
static const uint32_t HP_TEMP_INDEX = 5;
82+
static const uint32_t ENCLOSURE_PRESSURE_INDEX = 6;
83+
static const uint32_t ENCLOSURE_TEMPERATURE_INDEX = 7;
84+
static const uint32_t COOLING_PRESSURE_INDEX = 8;
85+
static const uint32_t COOLING_TEMPERATURE_INDEX = 9;
8286
};
8387

8488
// Solenoid Status indices
85-
namespace SOLENOID_INDEX
89+
namespace SOLENOID_INDEX
8690
{
87-
static const int32_t SOL1 = 0; // update if you add
88-
static const int32_t SOL2 = 1;
89-
static const int32_t SOL3 = 2;
90-
static const int32_t SOL4 = 3;
91+
static const uint32_t SOL1 = 0; // update if you add
92+
static const uint32_t SOL2 = 1;
93+
static const uint32_t SOL3 = 2;
94+
static const uint32_t SOL4 = 3;
9195
};
9296

97+
namespace CAN_IDS
98+
{
99+
static const uint32_t TEMP1_10HZ = 0x0A0;
100+
static const uint32_t TEMP2_10HZ = 0x0A1;
101+
static const uint32_t TEMP3_10HZ = 0x0A2;
102+
static const uint32_t MOTOR_POS_100HZ = 0x0A5;
103+
static const uint32_t CURRENT_100HZ = 0x0A6;
104+
static const uint32_t VOLTAGE_100HZ = 0x0A7;
105+
106+
};
93107

94108
namespace NetworkConstants
95109
{
96-
static const int32_t iCONFIG_SERVER_PORT = 3001;
110+
static const uint32_t iCONFIG_SERVER_PORT = 3001;
97111
}
98112

99113
#endif //FLIGHTCOMPUTER_CONSTANTS_H

OnPod/FlightComputer/src/States.cpp

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,25 @@ float PodState::timeInFlightSeconds() {
4848
return std::chrono::duration_cast<std::chrono::milliseconds>(current - this->_flightStartTime).count()/1000.0;
4949
}
5050

51-
bool PodState::isNodeSensorCritical(int sensorIndex) {
51+
bool PodState::isNodeSensorCritical(uint32_t sensorIndex) {
5252
std::vector<int> criticalSensors = {NODE_FLAGS::HP_INDEX, NODE_FLAGS::LP1_INDEX, NODE_FLAGS::LP2_INDEX, NODE_FLAGS::LP3_INDEX, NODE_FLAGS::LP4_INDEX,
5353
NODE_FLAGS::ENCLOSURE_TEMPERATURE_INDEX, NODE_FLAGS::ENCLOSURE_PRESSURE_INDEX};
5454
return std::find(criticalSensors.begin(), criticalSensors.end(), sensorIndex) != criticalSensors.end();
5555
}
5656

57-
bool PodState::isConnectionFlagCritical(int sensorIndex) {
58-
std::vector<int> criticalSensors = {};
59-
return std::find(criticalSensors.begin(), criticalSensors.end(), sensorIndex) != criticalSensors.end();
57+
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;
6065
}
6166

62-
bool PodState::isInverterSensorCritical(int sensorIndex) {
63-
std::vector<int> criticalSensors = {};
64-
return std::find(criticalSensors.begin(), criticalSensors.end(), sensorIndex) != criticalSensors.end();
67+
bool PodState::isInverterSensorCritical(uint32_t sensorIndex) {
68+
uint32_t criticalMask = INVERTER_RUN_FAULT_HI::RESOLVER_NOT_CONNECTED;
69+
return sensorIndex & criticalMask;
6570
}
6671

6772
int8_t PodState::checkFlags(std::vector<int32_t > &flags){
@@ -88,35 +93,48 @@ int32_t PodState::checkNodeStates(){
8893

8994
void PodState::commonChecks() {
9095
int32_t status;
96+
std::string nonCriticalError = "";
97+
9198
status = this->checkFlags(this->pod->telemetry->nodeSensorFlags);
92-
if( status != GENERAL_CONSTANTS::FLAGS_GOOD ){
99+
if (status != GENERAL_CONSTANTS::FLAGS_GOOD ){
93100
if(isNodeSensorCritical(status)){
94-
std::string error = "Failed on Critical Node sensor : " + std::to_string(status);
95-
throw CriticalErrorException(error);
101+
throw CriticalErrorException("Node sensor = " + std::to_string(status));
102+
}
103+
else {
104+
nonCriticalError += "Node sensor = " + std::to_string(status) + ", ";
96105
}
97-
std::string error = "Failed on Node sensor : " + std::to_string(status);
98-
throw std::runtime_error(error);
99106
}
107+
100108
status = this->checkFlags(this->pod->telemetry->connectionFlags);
101-
if(status != GENERAL_CONSTANTS::FLAGS_GOOD){
109+
if (status != GENERAL_CONSTANTS::FLAGS_GOOD){
102110
if(isConnectionFlagCritical(status)){
103-
std::string error = "Failed on critical communication flag : " + std::to_string(status);
104-
throw CriticalErrorException(error);
111+
throw CriticalErrorException("Communication Flag = " + std::to_string(status));
112+
}
113+
else {
114+
nonCriticalError += "Node sensor = " + std::to_string(status) + ", ";
105115
}
106-
std::string error = "Failed on communication flag : " + std::to_string(status);
107-
throw std::runtime_error(error);
108116
}
117+
109118
status = this->checkNodeStates();
110-
if(status != GENERAL_CONSTANTS::FLAGS_GOOD){
111-
std::string error = "Failed on Node state agreement : " + std::to_string(status);
112-
throw CriticalErrorException(error);
119+
if (status != GENERAL_CONSTANTS::FLAGS_GOOD){
120+
throw CriticalErrorException("Node State Disagreement = " + std::to_string(status));
121+
}
122+
123+
if (this->pod->telemetry->inverterRunFaultHi){
124+
nonCriticalError += "Inverter Non-critical Error HI-bytes = " + std::to_string(this->pod->telemetry->inverterRunFaultHi) + ", ";
113125
}
126+
127+
if (nonCriticalError != "")
128+
throw std::runtime_error("Non Critical Error: " + nonCriticalError);
114129
}
115130

116131
void PodState::armedChecks(){
117132
if(!this->pod->telemetry->inverterHeartbeat){
118-
std::string error = "Inverter Heartbeat Expired.";
119-
throw CriticalErrorException(error);
133+
throw CriticalErrorException("Inverter Heartbeat Expired.");
134+
}
135+
136+
if (isInverterSensorCritical(this->pod->telemetry->inverterRunFaultHi)){
137+
throw CriticalErrorException("Inverter Resolver Lost.");
120138
}
121139

122140
int status = checkFlags(pod->telemetry->inverterSensorFlags);

0 commit comments

Comments
 (0)