Skip to content

Commit

Permalink
clean address
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Aug 20, 2024
1 parent 03ba0f3 commit 732980d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions board/safety/safety_bmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ RxCheck bmw_rx_checks[] = { // todo add .check_checksum and .max_counter
{.msg = {{BMW_SteeringWheelAngle, BMW_PT_CAN, 7, .frequency = 100U}, { 0 }, { 0 }}},
{.msg = {{BMW_TransmissionDataDisplay, BMW_PT_CAN, 6, .frequency = 5U}, { 0 }, { 0 }}},
// todo cruise control type dependant, use param:
// {.msg = {{BMW_CruiseControlStatus, BMW_PT_CAN, 8, .frequency = 50U}, { 0 }, { 0 }}},
// {.msg = {{BMW_DynamicCruiseControlStatus, BMW_F_CAN, 7, .frequency = 100U}, { 0 }, { 0 }}},
// {.msg = {{559, BMW_F_CAN, 8, .frequency = 100U}, { 0 }, { 0 }}},
// {.msg = {{559, BMW_AUX_CAN, 8, .frequency = 100U}, { 0 }, { 0 }}},
// {.msg = {{BMW_CruiseControlStatus, BMW_PT_CAN, 8, .frequency = 5U}, { 0 }, { 0 }}},
// {.msg = {{BMW_DynamicCruiseControlStatus, BMW_F_CAN, 7, .frequency = 5U}, { 0 }, { 0 }}},
// {.msg = {{0x22f, BMW_F_CAN, 8, .frequency = 100U}, { 0 }, { 0 }}},
// {.msg = {{0x22f, BMW_AUX_CAN, 8, .frequency = 100U}, { 0 }, { 0 }}},
};


const CanMsg BMW_TX_MSGS[] = {
{BMW_CruiseControlStalk, BMW_PT_CAN, 4}, // Normal cruise control send status on PT-CAN
{BMW_CruiseControlStalk, BMW_F_CAN, 4}, // Dynamic cruise control send status on F-CAN
{558, BMW_F_CAN, 5}, // STEPPER_SERVO_CAN is allowed on F-CAN network
{558, BMW_AUX_CAN, 5}, // or an standalone network
{0x22e, BMW_F_CAN, 5}, // STEPPER_SERVO_CAN is allowed on F-CAN network
{0x22e, BMW_AUX_CAN, 5}, // or an standalone network
};

#define KPH_TO_MS 0.277778
Expand Down Expand Up @@ -103,9 +103,8 @@ static void bmw_rx_hook(const CANPacket_t *to_push) {
}
}
if (addr == BMW_TransmissionDataDisplay) {
if ((GET_BYTE(to_push, 0) & 0xF) == ((GET_BYTE(to_push, 0) >> 4) ^ 0xF)) { //check agains shift lever compliment signal
lever_position = GET_BYTE(to_push, 0) & 0xF; //compliment match
} else {
lever_position = GET_BYTE(to_push, 0) & 0xF;
if (lever_position != ((GET_BYTE(to_push, 0) >> 4) ^ 0xF)) { //check against shift lever compliment signal
lever_position = -1; //invalid
}
// if not in Drive
Expand All @@ -124,7 +123,7 @@ static void bmw_rx_hook(const CANPacket_t *to_push) {
}

// STEPPER_SERVO_CAN: get STEERING_STATUS
if ((addr == 559) && ((bus == BMW_F_CAN) || (bus == BMW_AUX_CAN))) {
if ((addr == 0x22f) && ((bus == BMW_F_CAN) || (bus == BMW_AUX_CAN))) {
actuator_torque = ((float)(int8_t)(GET_BYTE(to_push, 2))) * CAN_ACTUATOR_TQ_FAC; //Nm

if((((GET_BYTE(to_push, 1)>>4)>>CAN_ACTUATOR_CONTROL_STATUS_SOFTOFF_BIT) & 0x1) != 0x0){ //Soft off status means motor is shutting down due to error
Expand All @@ -145,7 +144,6 @@ static void bmw_rx_hook(const CANPacket_t *to_push) {
print("Too big angle \n");
}
}

if (bmw_fmax_limit_check((bmw_rt_angle_last >= 0.) ? angle_rate : -angle_rate, angle_rate_up, -angle_rate_down)) { //should be sensitive for jerks to the outside
controls_allowed = false; // todo ^ handle zero crossing a bit smarter
if (cruise_engaged){
Expand Down Expand Up @@ -188,7 +186,7 @@ static bool bmw_tx_hook(const CANPacket_t *to_send) {
// static float bmw_desired_angle_last = 0; // last desired steer angle
// // STEPPER_SERVO_CAN: get STEERING_COMMAND
// // do not transmit CAN message if steering angle too high
// if (addr == 558) {
// if (addr == 0x22e) {
// if (((GET_BYTE(to_send, 1) >> 4) & 0b11u) != 0x0){ //control enabled
// float steer_torque = ((float)(int8_t)(GET_BYTE(to_send, 4))) * CAN_ACTUATOR_TQ_FAC; //Nm
// if (bmw_fmax_limit_check(steer_torque - actuator_torque, max_tq_rate, -max_tq_rate)){
Expand Down

0 comments on commit 732980d

Please sign in to comment.