Skip to content

Commit

Permalink
Bug/anand89/main sdc ws (#117)
Browse files Browse the repository at this point in the history
* Changes from testing

* Can Change

* Uncomment apps, final changes

---------

Co-authored-by: AdityaAsGithub <[email protected]>
  • Loading branch information
AdityaAsGithub and AdityaAsGithub authored Apr 16, 2024
1 parent ca70049 commit ccdc70a
Show file tree
Hide file tree
Showing 16 changed files with 356 additions and 85 deletions.
44 changes: 44 additions & 0 deletions common/daq/can_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@
"msg_id_override": "0x7C0",
"is_normal":true
},
{
"msg_name": "load_sensor_readings",
"msg_desc": "Load Sensor readings from left and right",
"signals": [
{"sig_name": "left_load_sensor", "type": "float", "unit": "N"},
{"sig_name": "right_load_sensor", "type": "float", "unit": "N"}
],
"msg_period": 15,
"msg_hlp": 4,
"msg_pgn": 1000
},
{
"msg_name": "shock_rear",
"msg_desc": "Load Sensor readings from left and right",
"signals": [
{"sig_name": "left_shock", "type": "uint16_t", "unit": "mm"},
{"sig_name": "right_shock", "type": "uint16_t", "unit": "mm"}
],
"msg_period": 15,
"msg_hlp": 4,
"msg_pgn": 1020
},
{
"msg_name": "mcu_status",
"msg_desc": "performance metrics of MCU",
Expand Down Expand Up @@ -624,6 +646,28 @@
"msg_hlp":4,
"msg_pgn":10
},
{
"msg_name": "shock_front",
"msg_desc": "Load Sensor readings from left and right",
"signals": [
{"sig_name": "left_shock", "type": "uint16_t", "unit": "mm"},
{"sig_name": "right_shock", "type": "uint16_t", "unit": "mm"}
],
"msg_period": 15,
"msg_hlp": 4,
"msg_pgn": 1015
},
{
"msg_name": "load_sensor_readings_dash",
"msg_desc": "Load Sensor readings from left and right",
"signals": [
{"sig_name": "left_load_sensor", "type": "float", "unit": "N"},
{"sig_name": "right_load_sensor", "type": "float", "unit": "N"}
],
"msg_period": 15,
"msg_hlp": 4,
"msg_pgn": 1010
},
{
"msg_name": "cooling_driver_request",
"msg_desc": "Cooling Pump/Fan requests from Dash LCD",
Expand Down
32 changes: 32 additions & 0 deletions common/daq/per_dbc.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ BO_ 1984 LWS_Config: 2 Main_Module
SG_ Reserved_1 : 3|5@1+ (1,0) [0|0] "" Vector__XXX
SG_ CCW : 0|3@1+ (1,0) [0|0] "" Vector__XXX

BO_ 2415983105 load_sensor_readings: 8 Main_Module
SG_ right_load_sensor : 32|32@1- (1,0) [0|0] "N" Vector__XXX
SG_ left_load_sensor : 0|32@1- (1,0) [0|0] "N" Vector__XXX

BO_ 2415984385 shock_rear: 4 Main_Module
SG_ right_shock : 16|16@1+ (1,0) [0|0] "mm" Vector__XXX
SG_ left_shock : 0|16@1+ (1,0) [0|0] "mm" Vector__XXX

BO_ 2415925633 mcu_status: 4 Main_Module
SG_ sched_error : 24|8@1+ (1,0) [0|0] "" Vector__XXX
SG_ background_use : 16|8@1+ (1,0) [0|0] "" Vector__XXX
Expand Down Expand Up @@ -327,6 +335,14 @@ BO_ 2415919749 raw_throttle_brake: 8 Dashboard
SG_ throttle_right : 12|12@1+ (0.02442,0) [0|0] "%" Vector__XXX
SG_ throttle : 0|12@1+ (0.02442,0) [0|0] "%" Vector__XXX

BO_ 2415984069 shock_front: 4 Dashboard
SG_ right_shock : 16|16@1+ (1,0) [0|0] "mm" Vector__XXX
SG_ left_shock : 0|16@1+ (1,0) [0|0] "mm" Vector__XXX

BO_ 2415983749 load_sensor_readings_dash: 8 Dashboard
SG_ right_load_sensor : 32|32@1- (1,0) [0|0] "N" Vector__XXX
SG_ left_load_sensor : 0|32@1- (1,0) [0|0] "N" Vector__XXX

BO_ 2348810949 cooling_driver_request: 5 Dashboard
SG_ batt_fan : 32|8@1+ (1,0) [0|100] "%" Vector__XXX
SG_ batt_pump2 : 24|8@1+ (1,0) [0|0] "" Vector__XXX
Expand Down Expand Up @@ -631,6 +647,12 @@ CM_ BO_ 1984 "Steering sensor configuration";
CM_ SG_ 1984 Reserved_2 "";
CM_ SG_ 1984 Reserved_1 "";
CM_ SG_ 1984 CCW "";
CM_ BO_ 2415983105 "Load Sensor readings from left and right";
CM_ SG_ 2415983105 right_load_sensor "";
CM_ SG_ 2415983105 left_load_sensor "";
CM_ BO_ 2415984385 "Load Sensor readings from left and right";
CM_ SG_ 2415984385 right_shock "";
CM_ SG_ 2415984385 left_shock "";
CM_ BO_ 2415925633 "performance metrics of MCU";
CM_ SG_ 2415925633 sched_error "PSCHED Error Flags (bit #)
0 - N/A
Expand Down Expand Up @@ -864,6 +886,12 @@ CM_ SG_ 2415919749 brake_right "";
CM_ SG_ 2415919749 brake "";
CM_ SG_ 2415919749 throttle_right "";
CM_ SG_ 2415919749 throttle "";
CM_ BO_ 2415984069 "Load Sensor readings from left and right";
CM_ SG_ 2415984069 right_shock "";
CM_ SG_ 2415984069 left_shock "";
CM_ BO_ 2415983749 "Load Sensor readings from left and right";
CM_ SG_ 2415983749 right_load_sensor "";
CM_ SG_ 2415983749 left_load_sensor "";
CM_ BO_ 2348810949 "Cooling Pump/Fan requests from Dash LCD";
CM_ SG_ 2348810949 batt_fan "";
CM_ SG_ 2348810949 batt_pump2 "";
Expand Down Expand Up @@ -1084,6 +1112,10 @@ VAL_ 2415925569 rear_left_motor_link 0 "disconnected" 1 "attempting" 2 "verifyin
VAL_ 2415925569 rear_left_motor 0 "disconnected" 1 "connected" 2 "config" 3 "error" ;
VAL_ 2347693088 car_state 0 "ready2go" 1 "flipped" 2 "flying" 3 "lightspeed" ;
VAL_ 2347693089 car_state2 0 "ready2go" 1 "flipped" 2 "flying" 3 "lightspeed" ;
SIG_VALTYPE_ 2415983105 left_load_sensor : 1;
SIG_VALTYPE_ 2415983105 right_load_sensor : 1;
SIG_VALTYPE_ 2415983749 left_load_sensor : 1;
SIG_VALTYPE_ 2415983749 right_load_sensor : 1;
SIG_VALTYPE_ 2348810751 left_speed : 1;
SIG_VALTYPE_ 2348810751 right_speed : 1;
SIG_VALTYPE_ 2483028349 test_sig5_3 : 1;
Expand Down
3 changes: 3 additions & 0 deletions common/phal_F4_F7/can/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ bool PHAL_initCAN(CAN_TypeDef* bus, bool test_mode, uint32_t bit_rate)
case 24000000:
bus->BTR = PHAL_CAN_24MHz_250k;
break;
case 36000000:
bus->BTR = PHAL_CAN_36MHz_250k;
break;
default:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions common/phal_F4_F7/can/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#define PHAL_CAN_16MHz_250k (0x003a0003) // sample point = 75%
#define PHAL_CAN_24MHz_250k (0x003a0005) // sample point = 75%
#define PHAL_CAN_36MHz_250k (0x003a0008) // sample point = 75%

typedef struct
{
Expand Down
2 changes: 1 addition & 1 deletion common/phal_F4_F7/usart/usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool PHAL_initUSART(usart_init_t* handle, const uint32_t fck)

// // Set CR3 parameters
handle->periph->CR3 |= handle->obsample << USART_CR3_ONEBIT_Pos;
handle->periph->CR3 |= USART_CR3_EIE;
// handle->periph->CR3 |= USART_CR3_EIE;

// Enable peripheral for use
handle->periph->CR1 |= USART_CR1_UE;
Expand Down
19 changes: 16 additions & 3 deletions source/a_box/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ int main (void)
// PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, 1);


if (1 != PHAL_initCAN(CAN1, false, 250000))
PHAL_FaultHandler();


// for (uint16_t dimitri_is_not_better_than_me = 0; dimitri_is_not_better_than_me < 1000; dimitri_is_not_better_than_me++)
// {
Expand Down Expand Up @@ -212,7 +211,7 @@ int main (void)
void preflightChecks(void)
{
static uint16_t state;

uint8_t charger_speed_def = 0;

switch (state++)
{
Expand All @@ -222,6 +221,20 @@ void preflightChecks(void)
case 1:
initFaultLibrary(FAULT_NODE_NAME, &q_tx_can1_s[0], ID_FAULT_SYNC_A_BOX);
break;
case 700:
charger_speed_def = PHAL_readGPIO(BMS_CHARGE_ENABLE_Port, BMS_CHARGE_ENABLE_Pin);
uint8_t speed_2 = PHAL_readGPIO(BMS_CHARGER_SAFETY_Port, BMS_CHARGER_SAFETY_Pin);
if (charger_speed_def)
{
if (1 != PHAL_initCAN(CAN1, false, 250000))
PHAL_FaultHandler();
}
else
{
if (1 != PHAL_initCAN(CAN1, false, 500000))
PHAL_FaultHandler();
}
break;
default:
if (state > 750)
{
Expand Down
34 changes: 34 additions & 0 deletions source/dashboard/can/can_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@
// Make this match the node name within the can_config.json
#define NODE_NAME "Dashboard"

// Used to represent a float as 32 bits
typedef union {
float f;
uint32_t u;
} FloatConvert_t;
#define FLOAT_TO_UINT32(float_) (((FloatConvert_t) float_).u)
#define UINT32_TO_FLOAT(uint32_) (((FloatConvert_t) ((uint32_t) uint32_)).f)

// Message ID definitions
/* BEGIN AUTO ID DEFS */
#define ID_RAW_THROTTLE_BRAKE 0x10000285
#define ID_SHOCK_FRONT 0x1000fdc5
#define ID_LOAD_SENSOR_READINGS_DASH 0x1000fc85
#define ID_COOLING_DRIVER_REQUEST 0xc0002c5
#define ID_FILT_THROTTLE_BRAKE 0x4000245
#define ID_START_BUTTON 0x4000005
Expand Down Expand Up @@ -58,6 +68,8 @@
// Message DLC definitions
/* BEGIN AUTO DLC DEFS */
#define DLC_RAW_THROTTLE_BRAKE 8
#define DLC_SHOCK_FRONT 4
#define DLC_LOAD_SENSOR_READINGS_DASH 8
#define DLC_COOLING_DRIVER_REQUEST 5
#define DLC_FILT_THROTTLE_BRAKE 3
#define DLC_START_BUTTON 1
Expand Down Expand Up @@ -103,6 +115,20 @@
data_a->raw_throttle_brake.brake_pot = brake_pot_;\
canTxSendToBack(&msg);\
} while(0)
#define SEND_SHOCK_FRONT(left_shock_, right_shock_) do {\
CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_SHOCK_FRONT, .DLC=DLC_SHOCK_FRONT, .IDE=1};\
CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\
data_a->shock_front.left_shock = left_shock_;\
data_a->shock_front.right_shock = right_shock_;\
canTxSendToBack(&msg);\
} while(0)
#define SEND_LOAD_SENSOR_READINGS_DASH(left_load_sensor_, right_load_sensor_) do {\
CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_LOAD_SENSOR_READINGS_DASH, .DLC=DLC_LOAD_SENSOR_READINGS_DASH, .IDE=1};\
CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\
data_a->load_sensor_readings_dash.left_load_sensor = FLOAT_TO_UINT32(left_load_sensor_);\
data_a->load_sensor_readings_dash.right_load_sensor = FLOAT_TO_UINT32(right_load_sensor_);\
canTxSendToBack(&msg);\
} while(0)
#define SEND_COOLING_DRIVER_REQUEST(dt_pump_, dt_fan_, batt_pump_, batt_pump2_, batt_fan_) do {\
CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_COOLING_DRIVER_REQUEST, .DLC=DLC_COOLING_DRIVER_REQUEST, .IDE=1};\
CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\
Expand Down Expand Up @@ -220,6 +246,14 @@ typedef union {
uint64_t brake_right: 12;
uint64_t brake_pot: 12;
} raw_throttle_brake;
struct {
uint64_t left_shock: 16;
uint64_t right_shock: 16;
} shock_front;
struct {
uint64_t left_load_sensor: 32;
uint64_t right_load_sensor: 32;
} load_sensor_readings_dash;
struct {
uint64_t dt_pump: 8;
uint64_t dt_fan: 8;
Expand Down
Loading

0 comments on commit ccdc70a

Please sign in to comment.