Skip to content

Commit

Permalink
Added Torque Dial Driver IO (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjackson312006 authored Feb 5, 2025
1 parent 622df3b commit 17439e1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Core/Inc/pedals.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ void increase_torque_limit();
*/
void decrease_torque_limit();

/**
* @brief Sets the torque limit to a specific percentage
*
* @param percentage Percentage of the torque limit. Acceptable values are between 0.0 and 1.0.
*
*/
void set_torque_limit(float percentage);

/**
* @brief Get the current torque limit percentage
*
Expand Down
22 changes: 20 additions & 2 deletions Core/Inc/steeringio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "can.h"

#define STEERING_CANID_IO 0x680
#define BUTTON_CANID_IO 0x680
#define DIAL_CANID_IO 0x681

typedef enum {
BUTTON_LEFT,
Expand All @@ -12,14 +13,31 @@ typedef enum {
BUTTON_UP,
BUTTON_DOWN,
BUTTON_ENTER,
BUTTON_SPARE,
MAX_STEERING_BUTTONS
} steeringio_button_t;

typedef enum {
DIAL_SWITCH_1,
DIAL_SWITCH_2,
DIAL_SWITCH_3,
DIAL_SWITCH_4,
DIAL_SWITCH_5,
MAX_DIAL_SIZE,
} steeringio_dial_t;

/**
* @brief Update the status of the steering wheel buttons.
*
* @param can_msg can message containing data update
*/
void steeringio_update(can_msg_t can_msg);
void buttons_update(can_msg_t can_msg);

/**
* @brief Update the status of the active steering wheel dial switch.
*
* @param can_msg can message containing data update
*/
void dial_update(can_msg_t can_msg);

#endif /* STEERING_H */
9 changes: 6 additions & 3 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ can_t *can1;

/* Relevant Info for Initializing CAN 1 */
static uint32_t id_list[] = { DTI_CANID_ERPM, DTI_CANID_CURRENTS, BMS_DCL_MSG,
STEERING_CANID_IO };
BUTTON_CANID_IO, DIAL_CANID_IO };

void init_can1(CAN_HandleTypeDef *hcan)
{
Expand Down Expand Up @@ -150,8 +150,11 @@ void vCanReceive(void *pv_params)
case BMS_DCL_MSG:
handle_dcl_msg();
break;
case STEERING_CANID_IO:
steeringio_update(msg);
case BUTTON_CANID_IO:
buttons_update(msg);
break;
case DIAL_CANID_IO:
dial_update(msg);
break;
default:
break;
Expand Down
12 changes: 12 additions & 0 deletions Core/Src/pedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ void decrease_torque_limit()
}
}

void set_torque_limit(float percentage)
{
torque_limit_percentage = percentage;

// Make sure the percentage is within the valid range
if (torque_limit_percentage > 1.0) {
torque_limit_percentage = 1.0;
} else if (torque_limit_percentage < 0.0) {
torque_limit_percentage = 0.0;
}
}

float get_torque_limit_percentage()
{
return torque_limit_percentage;
Expand Down
40 changes: 39 additions & 1 deletion Core/Src/steeringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ static void right_button_cb()
}
}

void steeringio_update(can_msg_t msg)
static void set_torque_limit_wrapper(float percentage)
{
if (get_func_state() == F_EFFICIENCY) {
set_torque_limit(percentage);
}
}

void buttons_update(can_msg_t msg)
{
uint8_t button_id = msg.data[0];

Expand Down Expand Up @@ -50,7 +57,38 @@ void steeringio_update(can_msg_t msg)
printf("Enter button pressed \n");
select_nero_index();
break;
case BUTTON_SPARE:
printf("Spare button pressed \n");
break;
default:
break;
}
}

void dial_update(can_msg_t msg)
{
uint8_t dial_switch_id = msg.data[0];

switch (dial_switch_id) {
case DIAL_SWITCH_1:
printf("Dial set to switch 1 \n");
set_torque_limit_wrapper(0.2);
break;
case DIAL_SWITCH_2:
printf("Dial set to switch 2 \n");
set_torque_limit_wrapper(0.4);
break;
case DIAL_SWITCH_3:
printf("Dial set to switch 3 \n");
set_torque_limit_wrapper(0.6);
break;
case DIAL_SWITCH_4:
printf("Dial set to switch 4 \n");
set_torque_limit_wrapper(0.8);
break;
case DIAL_SWITCH_5:
printf("Dial set to switch 5 \n");
set_torque_limit_wrapper(1.0);
break;
}
}

0 comments on commit 17439e1

Please sign in to comment.