1818#include "data.h"
1919#include "states.h"
2020#include "hv_iox.h"
21-
21+ #include <math.h>
2222#include "bms_fault_checking.h"
2323#include "rms_fault_checking.h"
2424#include "pressure_fault_checking.h"
25+ #define NO_FAULT
26+ #define LV_BATT_SOC_CALC (x ) (pow(-1.1142 * (x), 6) + \
27+ pow(78.334 * (x), 5) - \
28+ pow(2280.5 * (x), 4) + \
29+ pow(35181.0 * (x), 3) - \
30+ pow(303240.0 *(x),2) - (1000000.0 * (x)))
2531
2632/* Imports/Externs */
2733
@@ -50,42 +56,46 @@ static bool checkStopped(void) {
5056
5157stateTransition_t * idleAction () {
5258 static firstCycle = true;
53-
59+ static displayBatt = 0 ;
5460 if (firstCycle ) {
5561 data -> flags -> brakeInit = true;
5662/* Does this! */
5763/* brakePrimaryUnactuate();*/
5864/* brakeSecondaryUnactuate();*/
5965 firstCycle = false;
6066 }
61-
67+
68+ if (displayBatt >= 100 ) {
69+ printf ("LV SOC: %f\n" , LV_BATT_SOC_CALC (getLVBattVoltage ()));
70+ displayBatt = 0 ;
71+ } else
72+ displayBatt += 1 ;
6273 data -> state = 1 ;
6374
6475 if (data -> flags -> emergencyBrake ) {
6576 return findTransition (stateMachine .currState ,RUN_FAULT_NAME );
6677 }
6778
6879 // CHECK PRESSURE
69- /* if(!checkPrerunPressures()){*/
70- /* return stateMachine.currState->fault;*/
71- /* }*/
72-
73- // CHECK STOPPED (MOTION)
74- /* if(!checkStopped()){*/
75- /* return stateMachine.currState->fault;*/
76- /* }*/
80+ #ifndef NO_FAULT
81+ if (!checkPrerunPressures ()){
82+ return stateMachine .currState -> fault ;
83+ }
84+ #endif
7785
7886 // TODO check LV Power
79- // TODO check LV Temp
8087
81- /* if(!checkPrerunBattery()){*/
82- /* return stateMachine.currState->fault;*/
83- /* }*/
84-
85- /* if(!checkPrerunRMS()){*/
86- /* return stateMachine.currState->fault;*/
87- /* }*/
88+
89+ // TODO check LV Temp
90+ #ifndef NO_FAULT
91+ if (!checkPrerunBattery ()){
92+ return stateMachine .currState -> fault ;
93+ }
8894
95+ if (!checkPrerunRMS ()){
96+ return stateMachine .currState -> fault ;
97+ }
98+ #endif
8999 // TRANSITION CRITERIA
90100 if (data -> flags -> readyPump ){
91101 return findTransition (stateMachine .currState , PUMPDOWN_NAME );
@@ -102,7 +112,7 @@ stateTransition_t * pumpdownAction() {
102112 if (data -> flags -> emergencyBrake ) {
103113 return findTransition (stateMachine .currState ,RUN_FAULT_NAME );
104114 }
105-
115+ #ifndef NO_FAULT
106116 if (!getIMDStatus ()) {
107117 return stateMachine .currState -> fault ;
108118 }
@@ -112,17 +122,11 @@ stateTransition_t * pumpdownAction() {
112122 return stateMachine .currState -> fault ;
113123 }
114124
115-
116125 // CHECK PRESSURE
117- /* if(!checkPrerunPressures()){*/
118- /* return stateMachine.currState->fault;*/
119- /* }*/
120-
121- // CHECK STOPPED (MOTION)
122- if (!checkStopped ()){
126+ if (!checkPrerunPressures ()){
123127 return stateMachine .currState -> fault ;
124128 }
125-
129+ #endif
126130 // TODO check LV Power
127131 // TODO check LV Temp
128132
@@ -144,9 +148,10 @@ stateTransition_t * pumpdownAction() {
144148
145149stateTransition_t * propulsionAction () {
146150 static bool isInit = false;
151+
147152 data -> state = 3 ;
148153 if (!isInit ) {
149-
154+ data -> flags -> clrMotionData = true;
150155 data -> timers -> startTime = getuSTimestamp ();
151156 isInit = true;
152157 }
@@ -188,7 +193,7 @@ stateTransition_t * propulsionAction() {
188193 return findTransition (stateMachine .currState , BRAKING_NAME );
189194 }
190195
191- if (data -> motion -> retroCount >= 3 ) {
196+ if (data -> motion -> retroCount >= 3 && data -> flags -> readyToBrake ) {
192197 printf ("here3\n" );
193198 return findTransition (stateMachine .currState , BRAKING_NAME );
194199 }
@@ -211,6 +216,7 @@ stateTransition_t * brakingAction() {
211216 if (data -> flags -> emergencyBrake ) {
212217 return findTransition (stateMachine .currState ,RUN_FAULT_NAME );
213218 }
219+ #ifndef NO_FAULT
214220 if (!getIMDStatus ()) {
215221 return stateMachine .currState -> fault ;
216222 }
@@ -236,15 +242,15 @@ stateTransition_t * brakingAction() {
236242 if (!checkBrakingRMS ()){
237243 return stateMachine .currState -> fault ;
238244 }
239-
245+ #endif
240246 if ((getuSTimestamp () - data -> timers -> startTime ) > MAX_RUN_TIME ){
241247 return stateMachine .currState -> fault ;
242248 }
243249
244250 // CHECK TRANSITION CRITERIA
245- if (checkStopped ()){
251+ /* if(checkStopped()){
246252 return findTransition(stateMachine.currState, STOPPED_NAME);
247- }
253+ }*/
248254
249255
250256 return NULL ;
0 commit comments