Skip to content

Commit

Permalink
merge failures fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Jul 30, 2024
1 parent 32fde07 commit 79da9ba
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Core/Inc/cerberus_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@
#define CANID_LV_MONITOR 0x503
#define CANID_PEDALS_ACCEL_MSG 0x504
#define CANID_PEDALS_BRAKE_MSG 0x505
#define CANID_EXTRA_MSG \
0x701 // Reserved for MPU debug message, see yaml for format
// Reserved for MPU debug message, see yaml for format
#define CANID_EXTRA_MSG 0x701
17 changes: 4 additions & 13 deletions Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
0x496 /* Throttle signal, Brake signal, IO, Drive enable */
#define DTI_QUEUE_SIZE 5

#define TIRE_DIAMETER 16 /* inches */
#define GEAR_RATIO 47 / 13.0 /* unitless */
#define POLE_PAIRS 10 /* unitless */
#define DTI_CANID_ID_IQ 0x476 /* Id, Iq values */
#define TIRE_DIAMETER 16 /* inches */
#define GEAR_RATIO 47 / 13.0 /* unitless */
#define POLE_PAIRS 10 /* unitless */
#define DTI_CANID_ID_IQ 0x476 /* Id, Iq values */
#define DTI_CANID_SIGNALS \
0x496 /* Throttle signal, Brake signal, IO, Drive enable */
#define DTI_QUEUE_SIZE 5
Expand All @@ -39,15 +39,6 @@
#define GEAR_RATIO 47 / 13.0 /* unitless */
#define POLE_PAIRS 10 /* unitless */

typedef struct {
int32_t rpm; /* SCALE: 1 UNITS: Rotations per Minute */
int16_t duty_cycle; /* SCALE: 10 UNITS: Percentage */
int16_t input_voltage; /* SCALE: 1 UNITS: Volts */
int16_t ac_current; /* SCALE: 10 UNITS: Amps */
int16_t dc_current; /* SCALE: 10 UNITS: Amps */
int16_t contr_temp; /* SCALE: 10 UNITS: Degrees Celsius */
int16_t motor_temp; /* SCALE: 10 UNITS: Degrees Celsius */
uint8_t fault_code; /* SCALE: 1 UNITS: No units just a number */
typedef struct {
int32_t rpm; /* SCALE: 1 UNITS: Rotations per Minute */
int16_t duty_cycle; /* SCALE: 10 UNITS: Percentage */
Expand Down
32 changes: 5 additions & 27 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ void vPedalsMonitor(void *pv_params)
mpu_t *mpu = (mpu_t *)pv_params;

uint8_t counter = 0;
static int index = 0;

for (;;) {
read_pedals(mpu, adc_data);
Expand Down Expand Up @@ -269,41 +268,20 @@ void vPedalsMonitor(void *pv_params)
// printf("Brake 1: %ld\r\n", adc_data[BRAKEPIN_1]);
// printf("Brake 2: %ld\r\n", adc_data[BRAKEPIN_2]);

static float buffer[10] = { 0 };

uint16_t brake_avg =
(adc_data[BRAKEPIN_1] + adc_data[BRAKEPIN_2]) / 2;
// Add the new value to the buffer
buffer[index] = brake_avg;

// Increment the index, wrapping around if necessary
index = (index + 1) % buffer_size;

// Calculate the average of the buffer
float sum = 0.0;
for (int i = 0; i < buffer_size; ++i) {
sum += buffer[i];
}
float average_brake = sum / buffer_size;

is_braking = average_brake > PEDAL_BRAKE_THRESH;
is_braking = (adc_data[BRAKEPIN_1] + adc_data[BRAKEPIN_2]) / 2;
brake_state = is_braking;

osMessageQueuePut(brakelight_signal, &is_braking, 0U, 0U);
//osMessageQueueReset(break_state_queue);
//osMessageQueuePut(break_state_queue, &is_braking, 0U, 0U);

uint16_t brake1_adj = adjust_pedal_val(
adc_data[BRAKEPIN_1], BRAKE1_OFFSET, BRAKE1_MAX_VAL);
uint16_t brake2_adj = adjust_pedal_val(
adc_data[BRAKEPIN_2], BRAKE2_OFFSET, BRAKE2_MAX_VAL);

/* Low Pass Filter */
sensor_data.accelerator_value =
(sensor_data.accelerator_value + (accel_val)) / 2;
sensor_data.brake_value = (sensor_data.brake_value +
(brake1_adj + brake2_adj) / 2) /
num_samples;
sensor_data.brake_value =
(sensor_data.brake_value +
(adc_data[BRAKEPIN_1] + adc_data[BRAKEPIN_2]) / 2) /
num_samples;

/* Publish to Onboard Pedals Queue */
//printf("Accel pedal queue %d", sensor_data.accelerator_value);
Expand Down
6 changes: 0 additions & 6 deletions Core/Src/state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@ static const bool valid_trans_to_from[MAX_FUNC_STATES][MAX_FUNC_STATES] = {
{ true, true, false, true }, /* BOOT */
{ false, true, true, true }, /* READY */
{ false, true, true, true }, /* DRIVING */
{ true, true, false, true }, /* BOOT */
{ false, true, true, true }, /* READY */
{ false, true, true, true }, /* DRIVING */
{ false, true, false, true } /* FAULTED */
};

osThreadId_t sm_director_handle;
const osThreadAttr_t sm_director_attributes = {
.name = "State Machine Director",
const osThreadAttr_t sm_director_attributes = {
.name = "State Machine Director",
.stack_size = 128 * 8,
.priority = (osPriority_t)osPriorityRealtime2,
.priority = (osPriority_t)osPriorityRealtime2,
};

static osMessageQueueId_t state_trans_queue;
Expand Down

0 comments on commit 79da9ba

Please sign in to comment.