Skip to content

Commit

Permalink
Added brake sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
jhwang04 committed Sep 20, 2024
1 parent 2a9272e commit 25f12f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
28 changes: 16 additions & 12 deletions lib/interfaces/include/MCUInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
#include "PedalsSystem.h"
#include "SharedDataTypes.h"

const int DEFAULT_BMS_OK_READ = 17; // SHDN_D_READ
const int DEFAULT_BMS_SENSE_PIN = 16; // BMS_OK_SENSE
const int DEFAULT_IMD_OK_READ = 10; // SHDN_C_READ
const int DEFAULT_IMD_SENSE_PIN = 18; // OKHS_SENSE
const int DEFAULT_BSPD_OK_READ = 39; // SHDN_E_READ
const int DEFAULT_SOFTWARE_OK_READ = 25; // SHDN_F_READ Watchdog Combined
const int DEFAULT_BOTS_OK_READ = 24; // SHDN_B_READ
const int DEFAULT_BRB_OK_READ = 26; // SHDN_G_READ
const int DEFAULT_BRAKE_LIGHT_CTRL = 6;
const int DEFAULT_INVERTER_ENABLE = 9;
const int DEFAULT_INVERTER_24V_ENABLE = 7;
const int DEFAULT_BMS_OK_READ = 17; // SHDN_D_READ
const int DEFAULT_BMS_SENSE_PIN = 16; // BMS_OK_SENSE
const int DEFAULT_IMD_OK_READ = 10; // SHDN_C_READ
const int DEFAULT_IMD_SENSE_PIN = 18; // OKHS_SENSE
const int DEFAULT_BSPD_OK_READ = 39; // SHDN_E_READ
const int DEFAULT_SOFTWARE_OK_READ = 25; // SHDN_F_READ Watchdog Combined
const int DEFAULT_BOTS_OK_READ = 24; // SHDN_B_READ
const int DEFAULT_BRB_OK_READ = 26; // SHDN_G_READ
const int DEFAULT_BRAKE_LIGHT_CTRL = 6;
const int DEFAULT_INVERTER_ENABLE = 9;
const int DEFAULT_INVERTER_24V_ENABLE = 7;
const int DEFAULT_BRAKE_PRESSURE_SENSOR_READ = 27; // Read pin for brake pressure sensor.

/// @brief specifically designed so that Walker would be happy
struct MainECUHardwareReadPins
Expand All @@ -36,10 +37,12 @@ struct MainECUHardwareReadPins
// inverter enable pins
int pin_inv_en;
int pin_inv_24V_en;
int pin_brake_pressure_sensor_read;
};

static const MainECUHardwareReadPins DEFAULT_PINS = {DEFAULT_BMS_OK_READ,DEFAULT_IMD_OK_READ, DEFAULT_BSPD_OK_READ, DEFAULT_SOFTWARE_OK_READ,
DEFAULT_BOTS_OK_READ, DEFAULT_BRB_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_ENABLE, DEFAULT_INVERTER_24V_ENABLE};
DEFAULT_BOTS_OK_READ, DEFAULT_BRB_OK_READ, DEFAULT_BRAKE_LIGHT_CTRL, DEFAULT_INVERTER_ENABLE,
DEFAULT_INVERTER_24V_ENABLE, DEFAULT_BRAKE_PRESSURE_SENSOR_READ};

class MCUInterface
{
Expand Down Expand Up @@ -115,6 +118,7 @@ class MCUInterface
// Interfaces
void update_mcu_status_CAN_ams(bool is_critical);
void update_mcu_status_CAN_dashboard(bool is_active);
void update_brake_pressure_CAN();

/* Enqueue MCU_status CAN */
void enqueue_CAN_mcu_status();
Expand Down
14 changes: 14 additions & 0 deletions lib/interfaces/src/MCUInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ void MCUInterface::update_mcu_status_CAN_pedals(const PedalsSystemData_s &pedals
mcu_status_.no_brake_implausibility = !pedals.brakeImplausible;
mcu_status_.no_accel_or_brake_implausibility = !(pedals.brakeAndAccelPressedImplausibility);
}
void MCUInterface::update_brake_pressure_CAN()
{
BRAKE_PRESSURE_SENSOR_t brake_sensor_msg;
brake_sensor_msg.brake_sensor_analog_read = analogRead(pins_.pin_brake_pressure_sensor_read);

CAN_message_t msg;

msg.id = Pack_BRAKE_PRESSURE_SENSOR_hytech(&brake_sensor_msg, msg.buf, &msg.len, (uint8_t*) &msg.flags.extended);

uint8_t buf[sizeof(CAN_message_t)] = {};
memmove(buf, &msg, sizeof(CAN_message_t));
msg_queue_->push_back(buf, sizeof(CAN_message_t));
}

void MCUInterface::tick(int fsm_state,
bool inv_has_error,
Expand Down Expand Up @@ -209,6 +222,7 @@ void MCUInterface::tick(int fsm_state,
// External Interfaces
update_mcu_status_CAN_ams(pack_charge_is_critical);
update_mcu_status_CAN_dashboard(button_is_pressed);
update_brake_pressure_CAN();
// Internal values
update_mcu_status_CAN();
// Push into buffer
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ lib_deps =
https://github.com/tonton81/FlexCAN_T4
https://github.com/ssilverman/QNEthernet#v0.26.0
https://github.com/RCMast3r/hytech_can#testing_new_inv_ids
https://github.com/hytech-racing/HT_CAN/releases/download/125/can_lib.tar.gz
https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz

[env:test_can_on_teensy]
lib_ignore =
Expand All @@ -81,7 +81,7 @@ lib_deps =
https://github.com/hytech-racing/shared_firmware_interfaces.git#feature/thermistor-template
https://github.com/hytech-racing/shared_firmware_systems.git#af96a63
https://github.com/RCMast3r/spi_libs#2214fee
https://github.com/hytech-racing/HT_CAN/releases/download/108/can_lib.tar.gz
https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz
git+ssh://git@github.com/hytech-racing/CASE_lib.git#v49


0 comments on commit 25f12f0

Please sign in to comment.