Skip to content

Commit 1e45bcb

Browse files
committed
Merge branch 'master' into navigation_testing
2 parents d3a157f + 26930e4 commit 1e45bcb

File tree

8 files changed

+53
-20
lines changed

8 files changed

+53
-20
lines changed

OnPod/FlightComputer/include/CanManager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,14 @@ T extractCanValue(const __u8 data[], const std::vector<int> &byteIndices, T conv
4747
return tConverted;
4848
}
4949

50+
class BroadcastManager{
51+
public:
52+
BroadcastManager();
53+
~BroadcastManager();
54+
void addBroadcast(int);
55+
private:
56+
std::vector<int> _broadcastSockts = {};
57+
58+
};
5059

5160
#endif //FLIGHTCOMPUTER_CANMANAGER_H

OnPod/FlightComputer/include/Structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct PodValues {
2828
uint32_t accelerationTime = 0;
2929
uint32_t expectedTubePressure = 0;
3030
uint32_t maxVelocity = 0;
31+
uint32_t maxRPM = 0;
3132
uint32_t brakeDistance = 0;
3233
uint32_t maxStripCount = 0;
3334
bool taxi = false;

OnPod/FlightComputer/src/Communication/CanManager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
#include <algorithm>
33
#include <initializer_list>
44

5+
6+
BroadcastManager::BroadcastManager() = default;
7+
8+
void BroadcastManager::addBroadcast(int socket) {
9+
this->_broadcastSockts.push_back(socket);
10+
}
11+
12+
BroadcastManager::~BroadcastManager() {
13+
for(auto socket : _broadcastSockts){
14+
close(socket);
15+
}
16+
}
17+
518
void processFrame(const struct can_frame &frame, TelemetryManager &pod) {
619
std::vector<int> indices = {0, 1};
720
switch (frame.can_id) {

OnPod/FlightComputer/src/Constants/Constants.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ namespace GENERAL_CONSTANTS
1414

1515
static const float REAR_WHEEL_CIRCUMFRENCE = 0.933619f;
1616
static const float STRIP_DISTANCE = 30.48;
17+
static const float DEFAULT_MAX_STRIP_COUNT = 80;
1718

18-
static const uint32_t NAV_SERIAL_MESSAGE_SIZE = 7;
19+
static const int32_t NAV_SERIAL_MESSAGE_SIZE = 10;
20+
static const float STATIONARY_THRSHOLD_M = 0.5f;
1921
};
2022

2123
namespace CONNECTION_FLAGS

OnPod/FlightComputer/src/States.cpp

Lines changed: 15 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

@@ -295,6 +295,7 @@ Arming::Arming(TelemetryManager * pod ): PodState(pod) {
295295
_stateIdentifier = psArming;
296296
this->pod->telemetry->commandedBrakeNodeState = bnsStandby;
297297
this->pod->telemetry->commandedLvdcNodeState = lvdcFlight;
298+
this->pod->telemetry->podPosition = 0.0f;
298299
}
299300

300301
Arming::~Arming() = default;
@@ -439,6 +440,10 @@ bool Acceleration::testTransitions() {
439440
this->setupTransition(psBraking, (std::string)" Flight Timout of " + std::to_string(this->timeInStateSeconds()) + " reached. Pod --> Braking");
440441
return true;
441442
}
443+
444+
if(this->pod->telemetry->motorSpeed >= pod->telemetry->maxRPM){
445+
this->setupTransition(psCoasting, "Acceleration->Coasting from maximum speed");
446+
}
442447
return false;
443448
}
444449

@@ -449,7 +454,8 @@ Coasting::Coasting(TelemetryManager* pod) : PodState(pod) {
449454
this->pod->telemetry->commandedTorque = 0;
450455
}
451456

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

OnPod/FlightComputer/src/TelemetryManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,12 @@ 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;
364+
this->telemetry->motorSpeed = value;
365365
float average = (value+lastRPM)/2.0;
366366
average /= (1000.0*60.0);
367+
367368
float milliseconds = (std::chrono::duration_cast<std::chrono::microseconds>(thisTime - lastTime).count())/1000.0;
368369
float distance = average*milliseconds * GENERAL_CONSTANTS::REAR_WHEEL_CIRCUMFRENCE;
369-
370370
addPodDistance(distance);
371371
}
372372

OnPod/FlightComputer/src/Threads/CanBusThread.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ void startInverterBroadcast(int bcmSocket){
159159
}
160160
}
161161

162-
void setInverterTorque(int torque, int bcmSocket){
162+
void setInverterTorque(int32_t torque, int bcmSocket){
163163
struct broadcastManagerConfig msg = {};
164164
torque *=10;
165-
int32_t highByte = torque/256;
166-
int32_t lowByte = torque%256;
165+
uint16_t highByte = torque/256;
166+
uint16_t lowByte = torque%256;
167167
msg.msg_head.opcode = TX_SETUP;
168168
msg.msg_head.can_id = 0;
169169
msg.msg_head.flags = SETTIMER | STARTTIMER;
@@ -239,6 +239,7 @@ int canNetworkThread(TelemetryManager Pod){
239239
LOG(INFO) << "Starting CAN Thread on ";
240240
int32_t canSockRaw = 0;
241241
int32_t canSockBcm = 0;
242+
BroadcastManager manager = BroadcastManager();
242243
try{
243244
canSockRaw = getCanSocketRaw();
244245
}
@@ -248,13 +249,14 @@ int canNetworkThread(TelemetryManager Pod){
248249
}
249250
try{
250251
canSockBcm = getCanSocketBrodcastManager();
252+
manager.addBroadcast(canSockBcm);
251253
}
252254
catch (std::runtime_error &e){
253255
LOG(INFO) << e.what();
254256
return -1;
255257
}
256258
try{
257-
// startInverterBroadcast(canSockBcm);
259+
;// startInverterBroadcast(canSockBcm);
258260
}
259261
catch (const std::runtime_error &error){
260262
LOG(INFO) << error.what();

OnPod/FlightComputer/src/Threads/CommanderThread.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ 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 = podCommand.maxvelocity() / GENERAL_CONSTANTS::REAR_WHEEL_CIRCUMFRENCE;
99100
Pod->telemetry->brakeDistance = podCommand.brakingdistance();
100101
if(!podCommand.taxi()) {
101-
float maxStripCount = (Pod->telemetry->flightDistance - Pod->telemetry->brakeDistance) /
102-
GENERAL_CONSTANTS::STRIP_DISTANCE;
103-
Pod->telemetry->maxStripCount = int32_t(ceil(maxStripCount));
102+
Pod->telemetry->maxStripCount = ( (Pod->telemetry->flightDistance - Pod->telemetry->brakeDistance) /
103+
GENERAL_CONSTANTS::STRIP_DISTANCE ) + 1;
104104
}
105105
else{
106-
Pod->telemetry->maxStripCount = 999;
106+
Pod->telemetry->maxStripCount = GENERAL_CONSTANTS::DEFAULT_MAX_STRIP_COUNT;
107107
}
108108
}
109109
if (podCommand.has_manualbrakenodestate()){

0 commit comments

Comments
 (0)