Skip to content

Commit

Permalink
Verified it work on hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielDelgado committed Sep 23, 2023
1 parent fde2376 commit 59a85d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Apps/Inc/SendTritium.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "common.h"

// #define SENDTRITIUM_PRINT_MES

#define MOTOR_MSG_PERIOD 100
#define FSM_PERIOD 100
#define DEBOUNCE_PERIOD 2 // in units of FSM_PERIOD
Expand Down Expand Up @@ -53,7 +55,7 @@ EXPOSE_GETTER(float, currentSetpoint)
EXPOSE_GETTER(float, velocitySetpoint)

// Setter functions for local variables in SendTritium.c
#ifdef DEBUG
#ifdef SENDTRITIUM_EXPOSE_VARS
EXPOSE_SETTER(bool, cruiseEnable)
EXPOSE_SETTER(bool, cruiseSet)
EXPOSE_SETTER(bool, onePedalEnable)
Expand Down
18 changes: 9 additions & 9 deletions Apps/Src/SendTritium.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define MIN_CRUISE_VELOCITY mpsToRpm(20.0f) // rpm
#define MAX_GEARSWITCH_VELOCITY mpsToRpm(8.0f) // rpm

#define BRAKE_PEDAL_THRESHOLD 5 // percent
#define BRAKE_PEDAL_THRESHOLD 15 // percent
#define ACCEL_PEDAL_THRESHOLD 10 // percent

#define ONEPEDAL_BRAKE_THRESHOLD 25 // percent
Expand Down Expand Up @@ -65,9 +65,10 @@ float cruiseVelSetpoint = 0;
// Current observed velocity
static float velocityObserved = 0;

#ifndef DEBUG
#ifndef SENDTRITIUM_PRINT_MES
// Counter for sending setpoints to motor
static uint8_t motorMsgCounter = 0;
#endif

// Debouncing counters
static uint8_t onePedalCounter = 0;
Expand All @@ -80,7 +81,6 @@ static bool onePedalPrevious = false;

static bool cruiseEnableButton = false;
static bool cruiseEnablePrevious = false;
#endif

// FSM
static TritiumState_t prevState; // Previous state
Expand All @@ -101,7 +101,7 @@ GETTER(float, currentSetpoint)
GETTER(float, velocitySetpoint)

// Setter functions for local variables in SendTritium.c
#ifdef DEBUG
#ifdef SENDTRITIUM_EXPOSE_VARS
SETTER(bool, cruiseEnable)
SETTER(bool, cruiseSet)
SETTER(bool, onePedalEnable)
Expand Down Expand Up @@ -164,7 +164,7 @@ static float percentToFloat(uint8_t percent){
return pedalToPercent[percent];
}

#ifdef DEBUG
#ifdef SENDTRITIUM_PRINT_MES
/**
* @brief Dumps info to UART during testing
*/
Expand Down Expand Up @@ -222,7 +222,7 @@ static void dumpInfo(){
}
#endif

#ifndef DEBUG
#ifndef SENDTRITIUM_EXPOSE_VARS
/**
* @brief Reads inputs from the system
*/
Expand Down Expand Up @@ -636,7 +636,7 @@ void Task_SendTritium(void *p_arg){
state = FSM[NEUTRAL_DRIVE];
prevState = FSM[NEUTRAL_DRIVE];

#ifndef DEBUG
#ifndef SENDTRITIUM_PRINT_MES
CANDATA_t driveCmd = {
.ID=MOTOR_DRIVE,
.idx=0,
Expand All @@ -648,14 +648,14 @@ void Task_SendTritium(void *p_arg){
prevState = state;

state.stateHandler(); // do what the current state does
#ifndef DEBUG
#ifndef SENDTRITIUM_EXPOSE_VARS
readInputs(); // read inputs from the system
UpdateDisplay_SetAccel(accelPedalPercent);
#endif
state.stateDecider(); // decide what the next state is

// Drive
#ifdef DEBUG
#ifdef SENDTRITIUM_PRINT_MES
dumpInfo();
#else
if(MOTOR_MSG_COUNTER_THRESHOLD == motorMsgCounter){
Expand Down
4 changes: 2 additions & 2 deletions Drivers/Src/Pedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// Refine in testing
static const int16_t LowerBound[NUMBER_OF_PEDALS] = {
400, // Accelerator lower bound
2800, // Brake lower bound
2100, // Brake lower bound
};

static const int16_t UpperBound[NUMBER_OF_PEDALS] = {
900, // Accelerator upper bound
3100, // Brake upper bound
3300, // Brake upper bound
};

/**
Expand Down

0 comments on commit 59a85d1

Please sign in to comment.