Skip to content

Commit

Permalink
remove garbage and merge garbage, change send_regen_braking function …
Browse files Browse the repository at this point in the history
…signature, add docs
  • Loading branch information
Sabramz committed Jul 31, 2024
1 parent 79da9ba commit 1a7a458
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 40 deletions.
4 changes: 1 addition & 3 deletions Core/Inc/cerberus_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
#define PEDAL_BRAKE_THRESH 650

/* Torque Tuning */
#define MAX_TORQUE 220 /* Nm, divded by 10 of torque of car */
#define MAX_BRAKE_PRESSURE 1800 // psi
#define REGEN_RAMP_TIME 500 // regen ramp time (in ms)
#define MAX_TORQUE 220 /* Nm */

// DEBUGGING: Start with a high debounce period, lower it if it is too slow
// NOTE: SteeringIOMonitor updates every 25 ms. Previous value of 25 ms doesn't
Expand Down
13 changes: 7 additions & 6 deletions Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ dti_t *dti_init();
void dti_set_torque(int16_t torque);

/**
* @brief Set the brake AC current target for regenerative braking.
* @brief Set the brake AC current target for regenerative braking. Only positive values are accepted by the DTI.
*
* @param current_target The desired AC current to do regenerative braking at.
* @param current_target The desired AC current to do regenerative braking at. Must be positive.
*/
void dti_set_regen(int16_t current_target);

/*
* SCALE: 10
* UNITS: Amps
/**
* @brief Send a CAN message containing the AC current target for regenerative braking.
*
* @param brake_current AC current target for regenerative braking. The motor controler has a maximum resolution of the tenths place.
*/
void dti_set_brake_current(int16_t brake_current);
void dti_send_brake_current(float brake_current);

/*
* SCALE: 10
Expand Down
7 changes: 0 additions & 7 deletions Core/Src/bms.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,8 @@ void vBMSCANMonitor(void *pv_params)
if (osOK == osMessageQueueGet(bms_monitor_queue,
&msg_from_queue, NULL,
osWaitForever)) {
/*TO-DO: fix duration (ticks)*/
osTimerStart(bms->bms_monitor_timer,
BMS_CAN_MONITOR_DELAY);
//serial_print("BMS DCL %d", bms->dcl);
if (msg_from_queue.id == BMS_CURR_LIMIT_MSG) {
/* Message is big endian, STM32 is *byte* little endian */
bms->ccl = (msg_from_queue.data[0] << 8) |
msg_from_queue.data[1];
}
}
}
}
28 changes: 5 additions & 23 deletions Core/Src/dti.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#define CAN_QUEUE_SIZE 5 /* messages */
#define SAMPLES 20
#define SAMPLES 20
static osMutexAttr_t dti_mutex_attributes;

dti_t *dti_init()
Expand Down Expand Up @@ -95,7 +94,7 @@ void dti_set_regen(int16_t current_target)
}

/* DTI CAN manual page 18, scale = 10 */
dti_set_brake_current(average * 10);
dti_send_brake_current(average);
}

void dti_set_current(int16_t current)
Expand All @@ -115,14 +114,15 @@ void dti_set_current(int16_t current)
queue_can_msg(msg);
}

void dti_set_brake_current(int16_t brake_current)
void dti_send_brake_current(float brake_current)
{
can_msg_t msg = { .id = 0x056,
.len = 8,
.data = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
// serial_print("Sending regen current: %i", brake_current);0x0
/* Motor controller expects int value * 10 */
int16_t adjusted_brake_current = brake_current * 10;
/* convert to big endian */
endian_swap(&brake_current, sizeof(brake_current));
endian_swap(&adjusted_brake_current, sizeof(adjusted_brake_current));
/* Send CAN message */
memcpy(&msg.data, &brake_current, 2);
queue_can_msg(msg);
Expand Down Expand Up @@ -280,23 +280,6 @@ static void dti_record_rpm(dti_t *mc, can_msg_t msg)
osMutexRelease(*mc->mutex);
}

uint16_t dti_get_input_voltage(dti_t *mc)
{
uint16_t voltage;
osMutexAcquire(*mc->mutex, osWaitForever);
voltage = mc->input_voltage;
osMutexRelease(*mc->mutex);

return voltage;
}

static void dti_set_input_voltage(dti_t *mc, can_msg_t msg)
{
osMutexAcquire(*mc->mutex, osWaitForever);
mc->input_voltage = (msg.data[8] << 8) | msg.data[7];
osMutexRelease(*mc->mutex);
}

void vDTIRouter(void *pv_params)
{
can_msg_t message;
Expand All @@ -313,7 +296,6 @@ void vDTIRouter(void *pv_params)
switch (message.id) {
case DTI_CANID_ERPM:
dti_record_rpm(mc, message);
dti_set_input_voltage(mc, message);
break;
case DTI_CANID_CURRENTS:
break;
Expand Down
1 change: 0 additions & 1 deletion Core/Src/torque.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

/* DO NOT ATTEMPT TO SEND TORQUE COMMANDS LOWER THAN THIS VALUE */
#define MIN_COMMAND_FREQ 60 /* Hz */
#define MIN_COMMAND_FREQ 60 /* Hz */
#define MAX_COMMAND_DELAY 1000 / MIN_COMMAND_FREQ /* ms */

static float torque_limit_percentage = 1.0;
Expand Down

0 comments on commit 1a7a458

Please sign in to comment.