Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Jan 24, 2024
1 parent 3ea1c80 commit 11214b0
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 77 deletions.
2 changes: 1 addition & 1 deletion gripper/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static brushed_motor_handler::BrushedMotorInterruptHandler
static brushed_motor_interrupt_driver::BrushedMotorInterruptDriver G(
brushed_motor_queue, brushed_motor_interrupt, brushed_motor_hardware_iface);

void z_motor_iface::initialize(diag0_handler *call_diag0_handler) {
void z_motor_iface::initialize(diag0_handler* call_diag0_handler) {
static_cast<void>(call_diag0_handler);
motor_interface.provide_mech_config(z_motor_sys_config);
};
Expand Down
14 changes: 9 additions & 5 deletions head/core/tasks_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ static auto tail_accessor = eeprom::dev_data::DevDataTailAccessor{head_queues};

void call_run_diag0_z_interrupt() {
if (head_tasks::get_left_tasks().motion_controller) {
return head_tasks::get_left_tasks().motion_controller->run_diag0_interrupt();
return head_tasks::get_left_tasks()
.motion_controller->run_diag0_interrupt();
}
}

void call_run_diag0_a_interrupt() {
if (head_tasks::get_right_tasks().motion_controller) {
return head_tasks::get_right_tasks().motion_controller->run_diag0_interrupt();
return head_tasks::get_right_tasks()
.motion_controller->run_diag0_interrupt();
}
}

Expand All @@ -108,7 +110,8 @@ auto head_tasks::start_tasks(
motor_hardware_task::MotorHardwareTask& rmh_tsk,
motor_hardware_task::MotorHardwareTask& lmh_tsk,
i2c::hardware::I2CBase& i2c3,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> std::tuple<diag0_handler, diag0_handler> {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> std::tuple<diag0_handler, diag0_handler> {
// Start the head tasks
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
Expand Down Expand Up @@ -214,8 +217,9 @@ auto head_tasks::start_tasks(
right_queues.move_status_report_queue =
&right_move_status_reporter.get_queue();
right_queues.usage_storage_queue = &right_usage_storage_task.get_queue();

return std::make_tuple(call_run_diag0_z_interrupt, call_run_diag0_a_interrupt);

return std::make_tuple(call_run_diag0_z_interrupt,
call_run_diag0_a_interrupt);
}

// Implementation of HeadQueueClient
Expand Down
12 changes: 8 additions & 4 deletions head/core/tasks_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ static auto eeprom_data_rev_update_builder =

void call_run_diag0_z_interrupt() {
if (head_tasks::get_left_tasks().motion_controller) {
return head_tasks::get_left_tasks().motion_controller->run_diag0_interrupt();
return head_tasks::get_left_tasks()
.motion_controller->run_diag0_interrupt();
}
}

void call_run_diag0_a_interrupt() {
if (head_tasks::get_right_tasks().motion_controller) {
return head_tasks::get_right_tasks().motion_controller->run_diag0_interrupt();
return head_tasks::get_right_tasks()
.motion_controller->run_diag0_interrupt();
}
}

Expand All @@ -113,7 +115,8 @@ auto head_tasks::start_tasks(
motor_hardware_task::MotorHardwareTask& rmh_tsk,
motor_hardware_task::MotorHardwareTask& lmh_tsk,
i2c::hardware::I2CBase& i2c3,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> std::tuple<diag0_handler, diag0_handler> {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> std::tuple<diag0_handler, diag0_handler> {
// Start the head tasks
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
Expand Down Expand Up @@ -236,7 +239,8 @@ auto head_tasks::start_tasks(
right_queues.usage_storage_queue = &right_usage_storage_task.get_queue();
#endif

return std::make_tuple(call_run_diag0_z_interrupt, call_run_diag0_a_interrupt);
return std::make_tuple(call_run_diag0_z_interrupt,
call_run_diag0_a_interrupt);
}

// Implementation of HeadQueueClient
Expand Down
58 changes: 28 additions & 30 deletions head/firmware/main_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ struct motor_hardware::HardwareConfig pin_configurations_left {
.port = GPIOA,
.pin = GPIO_PIN_8,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOB,
.pin = GPIO_PIN_4,
.active_setting = GPIO_PIN_RESET},
.diag0 =
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_13,
.active_setting = GPIO_PIN_RESET}
.port = GPIOB,
.pin = GPIO_PIN_4,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_13,
.active_setting = GPIO_PIN_RESET}
};

struct motor_hardware::HardwareConfig pin_configurations_right {
Expand Down Expand Up @@ -196,26 +196,24 @@ struct motor_hardware::HardwareConfig pin_configurations_right {
.port = GPIOA,
.pin = GPIO_PIN_8,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOB,
.pin = GPIO_PIN_4,
.active_setting = GPIO_PIN_RESET},
.diag0 =
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_15,
.active_setting = GPIO_PIN_RESET}
.port = GPIOB,
.pin = GPIO_PIN_4,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_15,
.active_setting = GPIO_PIN_RESET}
};

// TODO clean up the head main file by using interfaces.
static tmc2130::configs::TMC2130DriverConfig motor_driver_configs_right{
.registers =
{
.gconfig = {.en_pwm_mode = 1,
.diag0_error = 1,
.diag0_otpw = 1},
.gconfig = {.en_pwm_mode = 1, .diag0_error = 1, .diag0_otpw = 1},
.ihold_irun = {.hold_current = 0xB,
.run_current = 0x19,
.hold_current_delay = 0x7},
Expand All @@ -242,9 +240,7 @@ static tmc2130::configs::TMC2130DriverConfig motor_driver_configs_right{
static tmc2130::configs::TMC2130DriverConfig motor_driver_configs_left{
.registers =
{
.gconfig = {.en_pwm_mode = 1,
.diag0_error = 1,
.diag0_otpw = 1},
.gconfig = {.en_pwm_mode = 1, .diag0_error = 1, .diag0_otpw = 1},
.ihold_irun = {.hold_current = 0xB,
.run_current = 0x19,
.hold_current_delay = 0x7},
Expand Down Expand Up @@ -415,7 +411,8 @@ auto main() -> int {

app_update_clear_flags();
initialize_timer(motor_callback_glue, left_enc_overflow_callback_glue,
right_enc_overflow_callback_glue, &call_diag0_z_handler, &call_diag0_a_handler);
right_enc_overflow_callback_glue, &call_diag0_z_handler,
&call_diag0_a_handler);

if (initialize_spi(&hspi2) != HAL_OK) {
Error_Handler();
Expand All @@ -429,11 +426,12 @@ auto main() -> int {

i2c_setup(&i2c_handles);
i2c_comms3.set_handle(i2c_handles.i2c3);
std::tie(call_diag0_z_handler, call_diag0_a_handler) = head_tasks::start_tasks(can_bus_1, motor_left.motion_controller,
motor_right.motion_controller, psd, spi_comms2,
spi_comms3, motor_driver_configs_left,
motor_driver_configs_right, rmh_tsk, lmh_tsk,
i2c_comms3, eeprom_hw_iface);
std::tie(call_diag0_z_handler, call_diag0_a_handler) =
head_tasks::start_tasks(can_bus_1, motor_left.motion_controller,
motor_right.motion_controller, psd, spi_comms2,
spi_comms3, motor_driver_configs_left,
motor_driver_configs_right, rmh_tsk, lmh_tsk,
i2c_comms3, eeprom_hw_iface);

timer_for_notifier.start();

Expand Down
14 changes: 8 additions & 6 deletions head/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ auto main() -> int {
app_update_clear_flags();

initialize_timer(motor_callback_glue, left_enc_overflow_callback_glue,
right_enc_overflow_callback_glue, &call_diag0_z_handler, &call_diag0_a_handler);
right_enc_overflow_callback_glue, &call_diag0_z_handler,
&call_diag0_a_handler);

i2c_setup(&i2c_handles);
i2c_comms3.set_handle(i2c_handles.i2c3);
Expand All @@ -454,11 +455,12 @@ auto main() -> int {

utility_gpio_init();
can_bus_1.start(can_bit_timings);
std::tie(call_diag0_z_handler, call_diag0_a_handler) = head_tasks::start_tasks(can_bus_1, motor_left.motion_controller,
motor_right.motion_controller, psd, spi_comms2,
spi_comms3, motor_driver_configs_left,
motor_driver_configs_right, rmh_tsk, lmh_tsk,
i2c_comms3, eeprom_hw_iface);
std::tie(call_diag0_z_handler, call_diag0_a_handler) =
head_tasks::start_tasks(can_bus_1, motor_left.motion_controller,
motor_right.motion_controller, psd, spi_comms2,
spi_comms3, motor_driver_configs_left,
motor_driver_configs_right, rmh_tsk, lmh_tsk,
i2c_comms3, eeprom_hw_iface);

timer_for_notifier.start();

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 @@ -623,7 +623,8 @@ struct ReadMotorDriverErrorStatusRequest
uint32_t message_index;

template <bit_utils::ByteIterator Input, typename Limit>
static auto parse(Input body, Limit limit) -> ReadMotorDriverErrorStatusRequest {
static auto parse(Input body, Limit limit)
-> ReadMotorDriverErrorStatusRequest {
uint32_t msg_ind = 0;

body = bit_utils::bytes_to_int(body, limit, msg_ind);
Expand Down
3 changes: 2 additions & 1 deletion include/head/core/tasks_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ auto start_tasks(
motor_hardware_task::MotorHardwareTask& right_motor_hardware,
motor_hardware_task::MotorHardwareTask& left_motor_hardware,
i2c::hardware::I2CBase& i2c3,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> std::tuple<diag0_handler, diag0_handler>;
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> std::tuple<diag0_handler, diag0_handler>;

/**
* Access to all tasks not associated with a motor. This will be a singleton.
Expand Down
3 changes: 2 additions & 1 deletion include/head/core/tasks_rev1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ auto start_tasks(
motor_hardware_task::MotorHardwareTask& right_motor_hardware,
motor_hardware_task::MotorHardwareTask& left_motor_hardware,
i2c::hardware::I2CBase& i2c3,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> std::tuple<diag0_handler, diag0_handler>;
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> std::tuple<diag0_handler, diag0_handler>;

/**
* Access to all tasks not associated with a motor. This will be a singleton.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ class MotorInterruptHandler {
.error_code = err_code});
if (err_code == can::ids::ErrorCode::motor_driver_error_detected) {
driver_client.send_motor_driver_queue_isr(
can::messages::ReadMotorDriverErrorStatusRequest{.message_index =
message_index});
can::messages::ReadMotorDriverErrorStatusRequest{
.message_index = message_index});
}
if (err_code == can::ids::ErrorCode::collision_detected) {
build_and_send_ack(AckMessageId::position_error);
Expand Down
19 changes: 12 additions & 7 deletions include/motor-control/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,17 @@ class MotionControllerMessageHandler {
const motor_control_task_messages::RouteMotorDriverInterrupt& m) {
if (debounce_count > 9) {
if (controller.read_tmc_diag0()) {
controller.stop(can::ids::ErrorSeverity::unrecoverable,
can::ids::ErrorCode::motor_driver_error_detected);
controller.stop(
can::ids::ErrorSeverity::unrecoverable,
can::ids::ErrorCode::motor_driver_error_detected);
if (!controller.is_timer_interrupt_running()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
.error_code = can::ids::ErrorCode::
motor_driver_error_detected});
driver_client.send_motor_driver_queue(
can::messages::ReadMotorDriverErrorStatusRequest{
.message_index = m.message_index});
Expand All @@ -252,7 +253,9 @@ class MotionControllerMessageHandler {
} else {
debounce_count++;
vTaskDelay(pdMS_TO_TICKS(100));
motion_client.send_motion_controller_queue(motor_control_task_messages::RouteMotorDriverInterrupt{.message_index = m.message_index});
motion_client.send_motion_controller_queue(
motor_control_task_messages::RouteMotorDriverInterrupt{
.message_index = m.message_index});
}
}

Expand Down Expand Up @@ -341,8 +344,10 @@ class MotionControllerTask {
*/

void run_diag0_interrupt() {
if (!diag0_debounced){
static_cast<void>(queue.try_write_isr(motor_control_task_messages::RouteMotorDriverInterrupt{.message_index = 0}));
if (!diag0_debounced) {
static_cast<void>(queue.try_write_isr(
motor_control_task_messages::RouteMotorDriverInterrupt{
.message_index = 0}));
diag0_debounced = true;
}
}
Expand Down
11 changes: 5 additions & 6 deletions include/motor-control/core/tasks/tmc2130_motor_driver_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ class MotorDriverMessageHandler {
m.rxBuffer);
if (spi::utils::tag_in_token(
m.id.token, spi::utils::ResponseTag::IS_ERROR_RESPONSE)) {
can::messages::ReadMotorDriverErrorStatusResponse
response_msg{
.message_index = m.id.message_index,
.reg_address = static_cast<uint8_t>(m.id.token),
.data = data,
};
can::messages::ReadMotorDriverErrorStatusResponse response_msg{
.message_index = m.id.message_index,
.reg_address = static_cast<uint8_t>(m.id.token),
.data = data,
};
can_client.send_can_message(can::ids::NodeId::host,
response_msg);
} else {
Expand Down
11 changes: 5 additions & 6 deletions include/motor-control/core/tasks/tmc2160_motor_driver_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ class MotorDriverMessageHandler {
m.rxBuffer);
if (spi::utils::tag_in_token(
m.id.token, spi::utils::ResponseTag::IS_ERROR_RESPONSE)) {
can::messages::ReadMotorDriverErrorStatusResponse
response_msg{
.message_index = m.id.message_index,
.reg_address = static_cast<uint8_t>(m.id.token),
.data = data,
};
can::messages::ReadMotorDriverErrorStatusResponse response_msg{
.message_index = m.id.message_index,
.reg_address = static_cast<uint8_t>(m.id.token),
.data = data,
};
can_client.send_can_message(can::ids::NodeId::host,
response_msg);
} else {
Expand Down
9 changes: 5 additions & 4 deletions include/motor-control/core/tasks/tmc_motor_driver_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ namespace tmc {
namespace tasks {

using SpiResponseMessage = std::tuple<spi::messages::TransactResponse>;
using CanMessageTuple = std::tuple<can::messages::ReadMotorDriverRegister,
can::messages::WriteMotorDriverRegister,
can::messages::WriteMotorCurrentRequest,
can::messages::ReadMotorDriverErrorStatusRequest>;
using CanMessageTuple =
std::tuple<can::messages::ReadMotorDriverRegister,
can::messages::WriteMotorDriverRegister,
can::messages::WriteMotorCurrentRequest,
can::messages::ReadMotorDriverErrorStatusRequest>;
using GearCanMessageTuple =
std::tuple<can::messages::GearReadMotorDriverRegister,
can::messages::ReadMotorDriverErrorStatusRequest,
Expand Down
3 changes: 2 additions & 1 deletion include/pipettes/core/gear_motor_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ struct QueueClient : can::message_writer::MessageWriter {

void send_motor_driver_queue(const tmc2160::tasks::gear::TaskMessage& m);

void send_motor_driver_queue_isr(const tmc2160::tasks::gear::TaskMessage& m);
void send_motor_driver_queue_isr(
const tmc2160::tasks::gear::TaskMessage& m);

void send_move_group_queue(
const pipettes::tasks::move_group_task::TaskMessage& m);
Expand Down
6 changes: 4 additions & 2 deletions include/pipettes/core/linear_motor_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ struct QueueClient : can::message_writer::MessageWriter {
driver_queue->try_write(m);
}

void send_motor_driver_queue_isr(const tmc2130::tasks::TaskMessage& m) const {
void send_motor_driver_queue_isr(
const tmc2130::tasks::TaskMessage& m) const {
static_cast<void>(driver_queue->try_write_isr(m));
}

Expand Down Expand Up @@ -177,7 +178,8 @@ struct QueueClient : can::message_writer::MessageWriter {
driver_queue->try_write(m);
}

void send_motor_driver_queue_isr(const tmc2160::tasks::TaskMessage& m) const {
void send_motor_driver_queue_isr(
const tmc2160::tasks::TaskMessage& m) const {
static_cast<void>(driver_queue->try_write_isr(m));
}

Expand Down

0 comments on commit 11214b0

Please sign in to comment.