Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Oct 26, 2023
1 parent bd16ea6 commit 759eac8
Show file tree
Hide file tree
Showing 49 changed files with 323 additions and 214 deletions.
11 changes: 7 additions & 4 deletions gantry/core/tasks_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ auto gantry::tasks::start_tasks(
tmc2130::configs::TMC2130DriverConfig& driver_configs,
motor_hardware_task::MotorHardwareTask& mh_tsk,
i2c::hardware::I2CBase& i2c2,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> interfaces::diag0_handler {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> interfaces::diag0_handler {
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
auto& motion = mc_task_builder.start(5, "motion controller",
motion_controller, ::queues, ::queues, ::queues);
auto& motion =
mc_task_builder.start(5, "motion controller", motion_controller,
::queues, ::queues, ::queues);
auto& tmc2130_driver = motor_driver_task_builder.start(
5, "tmc2130 driver", driver_configs, ::queues, spi_task_client);
auto& move_group =
Expand Down Expand Up @@ -122,7 +124,8 @@ auto gantry::tasks::start_tasks(

void gantry::tasks::call_run_diag0_interrupt() {
if (gantry::tasks::get_tasks().motion_controller) {
return gantry::tasks::get_tasks().motion_controller->run_diag0_interrupt();
return gantry::tasks::get_tasks()
.motion_controller->run_diag0_interrupt();
}
}

Expand Down
11 changes: 7 additions & 4 deletions gantry/core/tasks_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ auto gantry::tasks::start_tasks(
tmc2160::configs::TMC2160DriverConfig& driver_configs,
motor_hardware_task::MotorHardwareTask& mh_tsk,
i2c::hardware::I2CBase& i2c2,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> interfaces::diag0_handler {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> interfaces::diag0_handler {
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
auto& motion = mc_task_builder.start(5, "motion controller",
motion_controller, ::queues, ::queues, ::queues);
auto& motion =
mc_task_builder.start(5, "motion controller", motion_controller,
::queues, ::queues, ::queues);
auto& tmc2160_driver = motor_driver_task_builder.start(
5, "tmc2160 driver", driver_configs, ::queues, spi_task_client);
auto& move_group =
Expand Down Expand Up @@ -121,7 +123,8 @@ auto gantry::tasks::start_tasks(

void gantry::tasks::call_run_diag0_interrupt() {
if (gantry::tasks::get_tasks().motion_controller) {
return gantry::tasks::get_tasks().motion_controller->run_diag0_interrupt();
return gantry::tasks::get_tasks()
.motion_controller->run_diag0_interrupt();
}
}

Expand Down
35 changes: 18 additions & 17 deletions gantry/firmware/interfaces_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ struct motion_controller::HardwareConfig motor_pins_x {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
Expand Down Expand Up @@ -130,11 +131,12 @@ struct motion_controller::HardwareConfig motor_pins_y {
.port = GPIOB,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
Expand All @@ -143,8 +145,7 @@ struct motion_controller::HardwareConfig motor_pins_y {
};

static tmc2130::configs::TMC2130DriverConfig gantry_x_driver_configs{
.registers = {.gconfig = {.en_pwm_mode = 1,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1},
.ihold_irun = {.hold_current = 0x2,
.run_current = 0x18,
.hold_current_delay = 0x7},
Expand All @@ -167,8 +168,7 @@ static tmc2130::configs::TMC2130DriverConfig gantry_x_driver_configs{
}};

static tmc2130::configs::TMC2130DriverConfig gantry_y_driver_configs{
.registers = {.gconfig = {.en_pwm_mode = 1,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1},
.ihold_irun = {.hold_current = 0x2,
.run_current = 0x18,
.hold_current_delay = 0x7},
Expand Down Expand Up @@ -244,8 +244,8 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(), motor_hardware_iface, stallcheck,
update_position_queue);
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(),
motor_hardware_iface, stallcheck, update_position_queue);

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down Expand Up @@ -287,7 +287,8 @@ void interfaces::initialize(diag0_handler* call_diag0_handler) {
Error_Handler();
}

initialize_timer(call_motor_handler, call_diag0_handler, enc_overflow_callback);
initialize_timer(call_motor_handler, call_diag0_handler,
enc_overflow_callback);

// Start the can bus
canbus.start(can_bit_timings);
Expand Down
35 changes: 18 additions & 17 deletions gantry/firmware/interfaces_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ struct motion_controller::HardwareConfig motor_pins_x {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
Expand Down Expand Up @@ -130,11 +131,12 @@ struct motion_controller::HardwareConfig motor_pins_y {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
Expand All @@ -143,8 +145,7 @@ struct motion_controller::HardwareConfig motor_pins_y {
};

static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
.registers = {.gconfig = {.en_pwm_mode = 0,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand Down Expand Up @@ -184,8 +185,7 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
}};

static tmc2160::configs::TMC2160DriverConfig motor_driver_config_y{
.registers = {.gconfig = {.en_pwm_mode = 0,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand Down Expand Up @@ -271,8 +271,8 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(), motor_hardware_iface, stallcheck,
update_position_queue);
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(),
motor_hardware_iface, stallcheck, update_position_queue);

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down Expand Up @@ -315,7 +315,8 @@ void interfaces::initialize(diag0_handler* call_diag0_handler) {
Error_Handler();
}

initialize_timer(call_motor_handler, call_diag0_handler, enc_overflow_callback);
initialize_timer(call_motor_handler, call_diag0_handler,
enc_overflow_callback);

// Start the can bus
canbus.start(can_bit_timings);
Expand Down
4 changes: 2 additions & 2 deletions gantry/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(), motor_interface, stallcheck,
update_position_queue);
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(),
motor_interface, stallcheck, update_position_queue);

static motor_interrupt_driver::MotorInterruptDriver A(motor_queue,
motor_interrupt,
Expand Down
5 changes: 3 additions & 2 deletions gripper/firmware/interfaces_z_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ static motor_class::Motor z_motor{
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gripper_tasks::z_tasks::get_queues(), gripper_tasks::z_tasks::get_queues(), motor_hardware_iface,
stallcheck, update_position_queue);
motor_queue, gripper_tasks::z_tasks::get_queues(),
gripper_tasks::z_tasks::get_queues(), motor_hardware_iface, stallcheck,
update_position_queue);

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down
5 changes: 3 additions & 2 deletions gripper/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gripper_tasks::z_tasks::get_queues(), gripper_tasks::z_tasks::get_queues(), motor_interface,
stallcheck, update_position_queue);
motor_queue, gripper_tasks::z_tasks::get_queues(),
gripper_tasks::z_tasks::get_queues(), motor_interface, stallcheck,
update_position_queue);

static motor_interrupt_driver::MotorInterruptDriver A(motor_queue,
motor_interrupt,
Expand Down
10 changes: 6 additions & 4 deletions head/core/tasks_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ void head_tasks::start_tasks(
head_queues.eeprom_queue = &eeprom_task.get_queue();

// Start the left motor tasks
auto& left_motion = left_mc_task_builder.start(
5, "left mc", left_motion_controller, left_queues, left_queues, left_queues);
auto& left_motion =
left_mc_task_builder.start(5, "left mc", left_motion_controller,
left_queues, left_queues, left_queues);
auto& left_tmc2130_driver = left_motor_driver_task_builder.start(
5, "left motor driver", left_driver_configs, left_queues,
spi3_task_client);
Expand Down Expand Up @@ -169,8 +170,9 @@ void head_tasks::start_tasks(
left_queues.usage_storage_queue = &left_usage_storage_task.get_queue();

// Start the right motor tasks
auto& right_motion = right_mc_task_builder.start(
5, "right mc", right_motion_controller, right_queues, right_queues, right_queues);
auto& right_motion =
right_mc_task_builder.start(5, "right mc", right_motion_controller,
right_queues, right_queues, right_queues);
auto& right_tmc2130_driver = right_motor_driver_task_builder.start(
5, "right motor driver", right_driver_configs, right_queues,
spi2_task_client);
Expand Down
10 changes: 6 additions & 4 deletions head/core/tasks_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ void head_tasks::start_tasks(
head_queues.eeprom_queue = &eeprom_task.get_queue();
#endif
// Start the left motor tasks
auto& left_motion = left_mc_task_builder.start(
5, "left mc", left_motion_controller, left_queues, left_queues, left_queues);
auto& left_motion =
left_mc_task_builder.start(5, "left mc", left_motion_controller,
left_queues, left_queues, left_queues);
auto& left_tmc2160_driver = left_motor_driver_task_builder.start(
5, "left motor driver", left_driver_configs, left_queues,
spi3_task_client);
Expand Down Expand Up @@ -182,8 +183,9 @@ void head_tasks::start_tasks(
#endif

// Start the right motor tasks
auto& right_motion = right_mc_task_builder.start(
5, "right mc", right_motion_controller, right_queues, right_queues, right_queues);
auto& right_motion =
right_mc_task_builder.start(5, "right mc", right_motion_controller,
right_queues, right_queues, right_queues);
auto& right_tmc2160_driver = right_motor_driver_task_builder.start(
5, "right motor driver", right_driver_configs, right_queues,
spi2_task_client);
Expand Down
10 changes: 6 additions & 4 deletions head/firmware/main_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ static stall_check::StallCheck stallcheck_right(
static motor_hardware::MotorHardware motor_hardware_right(
pin_configurations_right, &htim7, &htim2, right_usage_config);
static motor_handler::MotorInterruptHandler motor_interrupt_right(
motor_queue_right, head_tasks::get_right_queues(), head_tasks::get_right_queues(), motor_hardware_right,
stallcheck_right, update_position_queue_right);
motor_queue_right, head_tasks::get_right_queues(),
head_tasks::get_right_queues(), motor_hardware_right, stallcheck_right,
update_position_queue_right);

static auto encoder_background_timer_right =
motor_encoder::BackgroundTimer(motor_interrupt_right, motor_hardware_right);
Expand All @@ -289,8 +290,9 @@ static stall_check::StallCheck stallcheck_left(
static motor_hardware::MotorHardware motor_hardware_left(
pin_configurations_left, &htim7, &htim3, left_usage_config);
static motor_handler::MotorInterruptHandler motor_interrupt_left(
motor_queue_left, head_tasks::get_left_queues(), head_tasks::get_left_queues(), motor_hardware_left,
stallcheck_left, update_position_queue_left);
motor_queue_left, head_tasks::get_left_queues(),
head_tasks::get_left_queues(), motor_hardware_left, stallcheck_left,
update_position_queue_left);

static auto encoder_background_timer_left =
motor_encoder::BackgroundTimer(motor_interrupt_left, motor_hardware_left);
Expand Down
10 changes: 6 additions & 4 deletions head/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ static stall_check::StallCheck stallcheck_right(
static motor_hardware::MotorHardware motor_hardware_right(
pin_configurations_right, &htim7, &htim2, right_usage_config);
static motor_handler::MotorInterruptHandler motor_interrupt_right(
motor_queue_right, head_tasks::get_right_queues(), head_tasks::get_right_queues(), motor_hardware_right,
stallcheck_right, update_position_queue_right);
motor_queue_right, head_tasks::get_right_queues(),
head_tasks::get_right_queues(), motor_hardware_right, stallcheck_right,
update_position_queue_right);

static auto encoder_background_timer_right =
motor_encoder::BackgroundTimer(motor_interrupt_right, motor_hardware_right);
Expand All @@ -311,8 +312,9 @@ static stall_check::StallCheck stallcheck_left(
static motor_hardware::MotorHardware motor_hardware_left(
pin_configurations_left, &htim7, &htim3, left_usage_config);
static motor_handler::MotorInterruptHandler motor_interrupt_left(
motor_queue_left, head_tasks::get_left_queues(), head_tasks::get_left_queues(), motor_hardware_left,
stallcheck_left, update_position_queue_left);
motor_queue_left, head_tasks::get_left_queues(),
head_tasks::get_left_queues(), motor_hardware_left, stallcheck_left,
update_position_queue_left);

static auto encoder_background_timer_left =
motor_encoder::BackgroundTimer(motor_interrupt_left, motor_hardware_left);
Expand Down
10 changes: 6 additions & 4 deletions head/simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ static stall_check::StallCheck stallcheck_right(
linear_config.get_usteps_per_mm() / 1000.0F, utils::STALL_THRESHOLD_UM);

static motor_handler::MotorInterruptHandler motor_interrupt_right(
motor_queue_right, head_tasks::get_right_queues(), head_tasks::get_right_queues(), motor_interface_right,
stallcheck_right, update_position_queue_right);
motor_queue_right, head_tasks::get_right_queues(),
head_tasks::get_right_queues(), motor_interface_right, stallcheck_right,
update_position_queue_right);

static stall_check::StallCheck stallcheck_left(
linear_config.get_encoder_pulses_per_mm() / 1000.0F,
Expand All @@ -117,8 +118,9 @@ static motor_class::Motor motor_right{
motor_queue_right, update_position_queue_right};

static motor_handler::MotorInterruptHandler motor_interrupt_left(
motor_queue_left, head_tasks::get_left_queues(), head_tasks::get_left_queues(), motor_interface_left,
stallcheck_left, update_position_queue_left);
motor_queue_left, head_tasks::get_left_queues(),
head_tasks::get_left_queues(), motor_interface_left, stallcheck_left,
update_position_queue_left);

static motor_class::Motor motor_left{
motor_sys_config, motor_interface_left,
Expand Down
4 changes: 2 additions & 2 deletions include/can/core/message_handlers/motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class MotionHandler {
std::variant<std::monostate, DisableMotorRequest, EnableMotorRequest,
GetMotionConstraintsRequest, SetMotionConstraints,
ReadLimitSwitchRequest, MotorPositionRequest,
UpdateMotorPositionEstimationRequest,
GetMotorUsageRequest, MotorDriverErrorEncountered>;
UpdateMotorPositionEstimationRequest, GetMotorUsageRequest,
MotorDriverErrorEncountered>;

MotionHandler(MotionTaskClient &motion_client)
: motion_client{motion_client} {}
Expand Down
3 changes: 2 additions & 1 deletion include/can/core/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ using MotorPositionRequest = Empty<MessageId::motor_position_request>;
using UpdateMotorPositionEstimationRequest =
Empty<MessageId::update_motor_position_estimation_request>;

using MotorDriverErrorEncountered = Empty<MessageId::motor_driver_error_encountered>;
using MotorDriverErrorEncountered =
Empty<MessageId::motor_driver_error_encountered>;

struct WriteToEEPromRequest : BaseMessage<MessageId::write_eeprom> {
uint32_t message_index;
Expand Down
2 changes: 1 addition & 1 deletion include/gantry/core/interfaces_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" typedef void (*diag0_handler)(void);
/**
* Initialize the hardware portability layer.
*/
void initialize(diag0_handler* call_diag0_handler);
void initialize(diag0_handler *call_diag0_handler);

/**
* Get the CAN bus interface.
Expand Down
Loading

0 comments on commit 759eac8

Please sign in to comment.