Skip to content

Commit

Permalink
Set ContinuationIndentWidth to 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkoziej committed Apr 12, 2024
1 parent f6a1092 commit 7eaf5a1
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 222 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ BreakBeforeInlineASMColon: Always
BreakBeforeTernaryOperators: true
BreakStringLiterals: false
ColumnLimit: 79
ContinuationIndentWidth: 8
IncludeBlocks: Regroup

IncludeCategories:
Expand Down
30 changes: 15 additions & 15 deletions components/bbc/src/bbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@
#define CMD2DUTY(cmd) ((cmd) * ((1 << PWM_RESOLUTION) - 1))

static ledc_timer_config_t pwm_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = PWM_RESOLUTION,
.timer_num = LEDC_TIMER_0,
.freq_hz = PWM_FREQUENCY,
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = PWM_RESOLUTION,
.timer_num = LEDC_TIMER_0,
.freq_hz = PWM_FREQUENCY,
};

static ledc_channel_config_t pwm_channel = {
.gpio_num = PWM_PIN,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = PWM_INIT_DUTY_CYCLE,
.gpio_num = PWM_PIN,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = PWM_INIT_DUTY_CYCLE,
};

static void bbc_init();
static void bbc_100Hz();

ember_rate_funcs_S module_rf = {
.call_init = bbc_init,
.call_100Hz = bbc_100Hz,
.call_init = bbc_init,
.call_100Hz = bbc_100Hz,
};

static void bbc_init()
Expand All @@ -53,8 +53,8 @@ static void bbc_100Hz()
static float32_t prv_cmd;

bool bbc_authorized = CANRX_is_message_SUP_Authorization_ok()
&& CANRX_get_SUP_bbcAuthorized()
&& CANRX_is_message_CTRL_VelocityCommand_ok();
&& CANRX_get_SUP_bbcAuthorized()
&& CANRX_is_message_CTRL_VelocityCommand_ok();

float cmd;

Expand Down Expand Up @@ -83,5 +83,5 @@ void CANTX_populate_BBC_BrakeData(struct CAN_Message_BBC_BrakeData * const m)
m->BBC_dutyCycle = pwm_channel.duty;

m->BBC_percent = (float32_t) pwm_channel.duty
/ (float32_t) (1 << PWM_RESOLUTION) * 100;
/ (float32_t) (1 << PWM_RESOLUTION) * 100;
}
50 changes: 28 additions & 22 deletions components/ctrl/src/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#define ACCELERATION_TO_BRAKE_PERCENT(x) \
(((x) * ACCELERATION_TO_BRAKE_PERCENT_LINEAR_MAPPING) \
+ ACCELERATION_TO_BRAKE_PERCENT_LINEAR_MAPPING_OFFSET)
+ ACCELERATION_TO_BRAKE_PERCENT_LINEAR_MAPPING_OFFSET)

#define AVERAGE_TICKS_SAMPLES 4

Expand All @@ -49,13 +49,13 @@
static void ctrl_init();
static void ctrl_100Hz();
static void calculate_average_velocity(
int16_t left_delta, int16_t right_delta);
int16_t left_delta, int16_t right_delta);
static void encoder0_chan_a(void *arg);
static void encoder0_chan_b(void *arg);
static void encoder1_chan_a(void *arg);
static void encoder1_chan_b(void *arg);
static void velocity_control(
float desired_velocity, float desired_acceleration);
float desired_velocity, float desired_acceleration);

static volatile uint16_t pulse_cnt[2];
static bool speed_alarm;
Expand All @@ -69,8 +69,8 @@ static selfdrive_pid_t pid;
static bool setpoint_reset;

ember_rate_funcs_S module_rf = {
.call_init = ctrl_init,
.call_100Hz = ctrl_100Hz,
.call_init = ctrl_init,
.call_100Hz = ctrl_100Hz,
};

static void ctrl_init()
Expand All @@ -92,8 +92,14 @@ static void ctrl_init()
gpio_isr_handler_add(ENCODER1_CHAN_A, encoder1_chan_a, NULL);
gpio_isr_handler_add(ENCODER1_CHAN_B, encoder1_chan_b, NULL);

selfdrive_pid_init(
&pid, KP, KI, KD, 0.01, PID_LOWER_LIMIT, PID_UPPER_LIMIT, SIGMA);
selfdrive_pid_init(&pid,
KP,
KI,
KD,
0.01,
PID_LOWER_LIMIT,
PID_UPPER_LIMIT,
SIGMA);
}

static void ctrl_100Hz()
Expand All @@ -113,8 +119,8 @@ static void ctrl_100Hz()
// check if we're over the speed limit and
// go into the ESTOP state if that's the case
if ((base_get_state() == SYS_STATE_DBW_ACTIVE)
&& ((ABS(left_delta) >= ENCODER_MAX_TICKS)
|| (ABS(right_delta) >= ENCODER_MAX_TICKS))) {
&& ((ABS(left_delta) >= ENCODER_MAX_TICKS)
|| (ABS(right_delta) >= ENCODER_MAX_TICKS))) {
brake_percent = 0;
throttle_percent = 0;

Expand Down Expand Up @@ -152,12 +158,12 @@ static void ctrl_100Hz()

if (setpoint_reset) {
selfdrive_pid_setpoint_reset(
&pid, desired_velocity, current_velocity);
&pid, desired_velocity, current_velocity);
setpoint_reset = false;
}

desired_acceleration = selfdrive_pid_step(
&pid, desired_velocity, current_velocity);
&pid, desired_velocity, current_velocity);

velocity_control(desired_velocity, desired_acceleration);

Expand Down Expand Up @@ -280,7 +286,7 @@ static void IRAM_ATTR encoder1_chan_b(void *arg)
}

static void velocity_control(
float desired_velocity, float desired_acceleration)
float desired_velocity, float desired_acceleration)
{
// we'd like to stop, or so i hope
if (!desired_velocity) {
Expand All @@ -291,19 +297,19 @@ static void velocity_control(
}

if (desired_acceleration > 0) {
brake_percent = 0;
throttle_percent
= ACCELERATION_TO_THROTTLE_PERCENT(desired_acceleration);
brake_percent = 0;
throttle_percent = ACCELERATION_TO_THROTTLE_PERCENT(
desired_acceleration);
} else {
brake_percent
= ACCELERATION_TO_BRAKE_PERCENT(desired_acceleration);
= ACCELERATION_TO_BRAKE_PERCENT(desired_acceleration);
throttle_percent = 0;
}
}

void CANRX_onRxCallback_DBW_SetVelocityGains(
const struct CAN_TMessageRaw_PIDGains * const raw,
const struct CAN_TMessage_PIDGains * const dec)
const struct CAN_TMessageRaw_PIDGains * const raw,
const struct CAN_TMessage_PIDGains * const dec)
{
(void) raw;

Expand All @@ -319,29 +325,29 @@ void CANTX_populate_CTRL_Alarms(struct CAN_Message_CTRL_Alarms * const m)
}

void CANTX_populate_CTRL_ControllerData(
struct CAN_Message_CTRL_ControllerData * const m)
struct CAN_Message_CTRL_ControllerData * const m)
{
m->CTRL_averageVelocity = average_velocity;
m->CTRL_desiredAcceleration = desired_acceleration;
}

void CANTX_populateTemplate_ControllerGains(
struct CAN_TMessage_PIDGains * const m)
struct CAN_TMessage_PIDGains * const m)
{
m->gainKp = pid.kp;
m->gainKi = pid.ki;
m->gainKd = pid.kd;
}

void CANTX_populateTemplate_VelocityCommand(
struct CAN_TMessage_DBWVelocityCommand * const m)
struct CAN_TMessage_DBWVelocityCommand * const m)
{
m->brakePercent = brake_percent;
m->throttlePercent = throttle_percent;
}

void CANTX_populateTemplate_EncoderData(
struct CAN_TMessage_EncoderData * const m)
struct CAN_TMessage_EncoderData * const m)
{
m->encoderLeft = pulse_cnt[0];
m->encoderRight = pulse_cnt[1];
Expand Down
37 changes: 19 additions & 18 deletions components/steer/src/steer.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ enum {
float velocity;

ember_rate_funcs_S module_rf = {
.call_init = steer_init,
.call_100Hz = steer_100Hz,
.call_init = steer_init,
.call_100Hz = steer_100Hz,
};

static void steer_init()
{
selfdrive_pid_init(
&pid, KP, 0, 0, TS, PID_LOWER_LIMIT, PID_UPPER_LIMIT, 0);
&pid, KP, 0, 0, TS, PID_LOWER_LIMIT, PID_UPPER_LIMIT, 0);
}

static void steer_100Hz()
Expand All @@ -66,9 +66,10 @@ static void steer_100Hz()
alarm.odrive_calibration = calibration_needed;

bool steer_authorized = CANRX_is_message_DBW_SteeringCommand_ok()
&& CANRX_is_message_SUP_Authorization_ok()
&& CANRX_is_message_WHL_AbsoluteEncoder_ok()
&& CANRX_is_node_ODRIVE_ok() && CANRX_get_SUP_steerAuthorized();
&& CANRX_is_message_SUP_Authorization_ok()
&& CANRX_is_message_WHL_AbsoluteEncoder_ok()
&& CANRX_is_node_ODRIVE_ok()
&& CANRX_get_SUP_steerAuthorized();

if (!steer_authorized) {
base_request_state(SYS_STATE_IDLE);
Expand Down Expand Up @@ -118,11 +119,11 @@ static void steer_100Hz()
CANTX_doTx_STEER_ODriveRequestState();

selfdrive_pid_setpoint_reset(
&pid, CANRX_get_DBW_steeringAngle(), encoder_deg);
&pid, CANRX_get_DBW_steeringAngle(), encoder_deg);
}

velocity = selfdrive_pid_step(
&pid, RAD2DEG(CANRX_get_DBW_steeringAngle()), encoder_deg);
&pid, RAD2DEG(CANRX_get_DBW_steeringAngle()), encoder_deg);
}

static float encoder2deg(void)
Expand All @@ -132,7 +133,7 @@ static float encoder2deg(void)
// unfortunately, OpenCAN doesn't support
// big-endian messages at the moment...
int16_t ticks
= ((raw_ticks & 0xff00) >> 8) | ((raw_ticks & 0xff) << 8);
= ((raw_ticks & 0xff00) >> 8) | ((raw_ticks & 0xff) << 8);

float deg = (ENCODER2DEG_SLOPE * ticks) + ENCODER2DEG_SLOPE_OFFSET;

Expand All @@ -144,7 +145,7 @@ static bool odrive_calibration_needed(void)
bool calibration_needed = false;

calibration_needed
|= CANRX_get_ODRIVE_axisError() != CAN_ODRIVE_AXISERROR_NONE;
|= CANRX_get_ODRIVE_axisError() != CAN_ODRIVE_AXISERROR_NONE;
calibration_needed |= CANRX_get_ODRIVE_motorErrorAlarm();
calibration_needed |= CANRX_get_ODRIVE_encoderErrorAlarm();
calibration_needed |= CANRX_get_ODRIVE_controllerErrorAlarm();
Expand All @@ -159,40 +160,40 @@ void CANTX_populate_STEER_Alarms(struct CAN_Message_STEER_Alarms * const m)
}

void CANTX_populate_STEER_ODriveClearErrors(
uint8_t * const data, uint8_t * const len)
uint8_t * const data, uint8_t * const len)
{
(void) data;
(void) len;
}

void CANTX_populate_STEER_ODriveRequestState(
struct CAN_Message_STEER_ODriveRequestState * const m)
struct CAN_Message_STEER_ODriveRequestState * const m)
{
switch (odrive_state) {
case IDLE:
m->STEER_odriveRequestState
= CAN_STEER_ODRIVEREQUESTSTATE_IDLE;
= CAN_STEER_ODRIVEREQUESTSTATE_IDLE;
break;

case FULL_CALIBRATION_SEQUENCE:
m->STEER_odriveRequestState
= CAN_STEER_ODRIVEREQUESTSTATE_FULL_CALIBRATION_SEQUENCE;
= CAN_STEER_ODRIVEREQUESTSTATE_FULL_CALIBRATION_SEQUENCE;
break;

case CLOSED_LOOP_CONTROL:
m->STEER_odriveRequestState
= CAN_STEER_ODRIVEREQUESTSTATE_CLOSED_LOOP_CONTROL;
= CAN_STEER_ODRIVEREQUESTSTATE_CLOSED_LOOP_CONTROL;
break;

default:
m->STEER_odriveRequestState
= CAN_STEER_ODRIVEREQUESTSTATE_UNDEFINED;
= CAN_STEER_ODRIVEREQUESTSTATE_UNDEFINED;
break;
}
}

void CANTX_populate_STEER_ODriveVelocity(
struct CAN_Message_STEER_ODriveVelocity * const m)
struct CAN_Message_STEER_ODriveVelocity * const m)
{
// unfortunately, OpenCAN doesn't support
// IEEE754 signals at the moment...
Expand All @@ -202,7 +203,7 @@ void CANTX_populate_STEER_ODriveVelocity(
}

void CANTX_populate_STEER_SteeringData(
struct CAN_Message_STEER_SteeringData * const m)
struct CAN_Message_STEER_SteeringData * const m)
{
switch (steer_state) {
case READY:
Expand Down
18 changes: 9 additions & 9 deletions components/sup/src/sup.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static bool throttle_authorized;
static bool steer_authorized;

ember_rate_funcs_S module_rf = {
.call_100Hz = sup_100Hz,
.call_100Hz = sup_100Hz,
};

static void sup_100Hz()
Expand All @@ -26,13 +26,13 @@ static void sup_100Hz()
authorized = true;
taskDISABLE_INTERRUPTS();
authorized &= CANRX_is_message_DBW_VelocityCommand_ok()
|| CANRX_is_message_DBW_RawVelocityCommand_ok();
|| CANRX_is_message_DBW_RawVelocityCommand_ok();
authorized &= CANRX_is_node_CTRL_ok();
authorized &= CANRX_is_node_BBC_ok();
authorized &= CANRX_get_CTRL_sysStatus()
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
authorized &= CANRX_get_BBC_sysStatus()
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
authorized &= !CANRX_get_CTRL_speedAlarm();
taskENABLE_INTERRUPTS();
bbc_authorized = authorized;
Expand All @@ -42,21 +42,21 @@ static void sup_100Hz()
taskDISABLE_INTERRUPTS();
authorized &= CANRX_is_message_DBW_SteeringCommand_ok();
authorized &= CANRX_get_STEER_sysStatus()
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
taskENABLE_INTERRUPTS();
steer_authorized = authorized;

// THROTTLE
authorized = true;
taskDISABLE_INTERRUPTS();
authorized &= CANRX_is_message_DBW_VelocityCommand_ok()
|| CANRX_is_message_DBW_RawVelocityCommand_ok();
|| CANRX_is_message_DBW_RawVelocityCommand_ok();
authorized &= CANRX_is_node_CTRL_ok();
authorized &= CANRX_is_node_THROTTLE_ok();
authorized &= CANRX_get_CTRL_sysStatus()
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
authorized &= CANRX_get_THROTTLE_sysStatus()
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
!= CAN_T_DBWNODESTATUS_SYSSTATUS_ESTOP;
authorized &= CANRX_get_STEER_state() == CAN_STEER_STATE_READY;
authorized &= !CANRX_get_CTRL_speedAlarm();
taskENABLE_INTERRUPTS();
Expand All @@ -70,7 +70,7 @@ static void sup_100Hz()
}

void CANTX_populate_SUP_Authorization(
struct CAN_Message_SUP_Authorization * const m)
struct CAN_Message_SUP_Authorization * const m)
{
m->SUP_bbcAuthorized = bbc_authorized;
m->SUP_throttleAuthorized = throttle_authorized;
Expand Down
Loading

0 comments on commit 7eaf5a1

Please sign in to comment.