21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wpedantic"
24#pragma GCC diagnostic pop
55 constexpr double PI_ = 3.1415926535897932384626433832795;
71 void update(uint16_t pedal_1, uint16_t pedal_2, uint16_t brake);
128 constexpr int16_t
pedalTorqueMapping(
const uint16_t
pedal,
const uint16_t brake,
const int16_t motor_rpm,
const bool flip_dir);
130 MCP2515::ERROR
sendCyclicRead(uint8_t reg_id, uint8_t read_period);
Definition of the CarState structure representing the state of the car.
Definition of throttle and brake mapping tables.
constexpr TablePoint< uint16_t, int16_t > THROTTLE_TABLE[5]
Throttle mapping table (calculated), maps APPS_5V readings to torque values.
constexpr TablePoint< uint16_t, int16_t > BRAKE_TABLE[5]
Brake mapping table, negative values for regen.
constexpr TablePoint< uint16_t, uint16_t > APPS_3V3_SCALE_TABLE[3]
APPS_3V3 mapping table, maps 3V3 readings to 5V readings.
Declaration and definition of the LinearInterp class template for linear interpolation.
constexpr uint16_t FAULT_CHECK_HEX
constexpr bool FLIP_MOTOR_DIR
constexpr uint8_t ADC_BUFFER_SIZE
constexpr bool BRAKE_RELIABLE
constexpr bool REGEN_ENABLED
constexpr uint32_t MAX_MOTOR_READ_MILLIS
Declaration of signal processing functions.
Filter with exponential moving average algorithm.
Class template for performing linear interpolation using a lookup table.
Pedal class for managing throttle and brake pedal inputs. Handles filtering, fault detection,...
void update(uint16_t pedal_1, uint16_t pedal_2, uint16_t brake)
Updates pedal sensor readings, applies filtering, and checks for faults.
void sendFrame()
Sends the appropriate CAN frame to the motor based on pedal and car state.
bool initMotor()
Initializes the motor CAN communication by setting up cyclic reads for motor data and configuring CAN...
bool checkCyclicRead(uint8_t reg_id)
bool checkPedalFault()
Checks for a fault between two pedal sensor readings.
static constexpr uint8_t WARN_ERR
static constexpr LinearInterp< uint16_t, int16_t, int32_t, 5 > BRAKE_MAP
void initFilter()
Initializes the CAN filters for reading motor data. Call after constructing the Pedal object and the ...
static constexpr LinearInterp< uint16_t, int16_t, int32_t, 5 > THROTTLE_MAP
static constexpr canid_t MOTOR_READ
static constexpr LinearInterp< uint16_t, uint16_t, uint32_t, 3 > APPS_3V3_SCALE_MAP
const can_frame stop_frame
CAN frame to stop the motor.
static constexpr uint8_t REGID_READ
void readMotor()
Reads motor data from the CAN bus and updates the CarState.
uint32_t last_motor_read_millis
static constexpr uint8_t RPM_PERIOD
ExponentialFilter< uint16_t, uint16_t > brake_filter
static constexpr canid_t MOTOR_SEND
ExponentialFilter< uint16_t, uint16_t > pedal1_filter
static constexpr uint8_t SPEED_IST
can_frame torque_msg
CAN frame for torque command.
constexpr int16_t pedalTorqueMapping(const uint16_t pedal, const uint16_t brake, const int16_t motor_rpm, const bool flip_dir)
Maps the pedal ADC to a torque value. If no braking requested, maps throttle normally....
static constexpr uint8_t ERR_PERIOD
MCP2515::ERROR sendCyclicRead(uint8_t reg_id, uint8_t read_period)
Sends a cyclic read request to the motor controller for speed (rpm).
uint32_t fault_start_millis
ExponentialFilter< uint16_t, uint16_t > pedal2_filter
Pedal pedal(mcp2515_DL, car, car.pedal.apps_5v)
Namespace for pedal-related constants, such as thresholds and calculation parameters....
constexpr uint16_t INCH_PER_KM
constexpr uint16_t MAX_MOTOR_RPM
constexpr uint8_t GEAR_RATIO_DENOMINATOR
constexpr uint8_t GEAR_RATIO_NUMERATOR
constexpr uint8_t WHEEL_DIAMETER_INCH
constexpr uint8_t MIN_REGEN_KMH
constexpr uint16_t MAX_TORQUE_VAL
constexpr uint8_t MINUTES_PER_HOUR
constexpr int16_t MIN_REGEN_RPM_VAL
Represents the state of the car. Holds telemetry data and status, used as central data sharing struct...