From 3fa8686edd1d590d22b8f59142d36bf5de5c765e Mon Sep 17 00:00:00 2001 From: caila-marashaj Date: Mon, 22 Apr 2024 12:19:45 -0400 Subject: [PATCH] Revert "feat(motion-control): handle motor driver errors (#716)" This reverts commit 762d6d589f9c802267b1926a96e473efb2570091. --- .github/workflows/build-tests.yaml | 2 +- gantry/core/tasks_proto.cpp | 24 +--- gantry/core/tasks_rev1.cpp | 24 +--- gantry/firmware/interfaces_proto.cpp | 37 ++--- gantry/firmware/interfaces_rev1.cpp | 39 ++--- gantry/firmware/main_proto.cpp | 6 +- gantry/firmware/main_rev1.cpp | 6 +- gantry/firmware/motor_hardware.c | 27 +--- gantry/firmware/motor_hardware.h | 3 +- gantry/firmware/stm32g4xx_it.c | 1 - gantry/simulator/interfaces.cpp | 8 +- gantry/simulator/main.cpp | 6 +- gripper/core/tasks.cpp | 11 +- gripper/core/tasks_z.cpp | 22 +-- gripper/firmware/interfaces_z_motor.cpp | 19 +-- gripper/firmware/main_proto.cpp | 6 +- gripper/firmware/main_rev1.cpp | 6 +- gripper/firmware/motor_hardware.h | 2 - gripper/firmware/motor_hardware_shared.c | 18 +-- gripper/firmware/stm32g4xx_it.c | 5 - gripper/firmware/utility_gpio.c | 7 - gripper/simulator/interfaces.cpp | 8 +- gripper/simulator/main.cpp | 6 +- head/core/can_task.cpp | 3 +- head/core/tasks_proto.cpp | 34 +---- head/core/tasks_rev1.cpp | 34 +---- head/firmware/main_proto.cpp | 57 +++----- head/firmware/main_rev1.cpp | 44 ++---- head/firmware/motor_hardware.h | 5 +- head/firmware/motor_hardware_common.c | 39 +---- head/firmware/stm32g4xx_it.c | 8 -- head/simulator/main.cpp | 10 +- include/can/core/ids.hpp | 4 - include/can/core/messages.hpp | 38 +---- include/gantry/core/can_task.hpp | 3 +- include/gantry/core/interfaces_proto.hpp | 4 +- include/gantry/core/interfaces_rev1.hpp | 4 +- include/gantry/core/queues.hpp | 2 - include/gantry/core/tasks_proto.hpp | 8 +- include/gantry/core/tasks_rev1.hpp | 8 +- include/gripper/core/can_task.hpp | 3 +- include/gripper/core/interfaces.hpp | 4 +- include/gripper/core/tasks.hpp | 14 +- include/gripper/firmware/utility_gpio.h | 1 - include/gripper/simulation/sim_interfaces.hpp | 2 - include/head/core/queues.hpp | 2 - include/head/core/tasks_proto.hpp | 8 +- include/head/core/tasks_rev1.hpp | 8 +- .../brushed_motion_controller.hpp | 7 +- .../brushed_motor_interrupt_handler.hpp | 6 +- .../core/motor_hardware_interface.hpp | 12 +- .../core/stepper_motor/motion_controller.hpp | 30 +--- .../stepper_motor/motor_interrupt_handler.hpp | 22 +-- .../core/stepper_motor/tmc2130_driver.hpp | 7 +- .../core/stepper_motor/tmc2160.hpp | 16 --- .../core/stepper_motor/tmc2160_driver.hpp | 26 +--- .../tasks/gear_tmc2160_motor_driver_task.hpp | 33 +---- include/motor-control/core/tasks/messages.hpp | 13 +- .../core/tasks/motion_controller_task.hpp | 136 +++--------------- .../core/tasks/tmc2130_motor_driver_task.hpp | 34 +---- .../core/tasks/tmc2160_motor_driver_task.hpp | 44 +----- .../core/tasks/tmc_motor_driver_common.hpp | 11 +- .../brushed_motor/brushed_motor_hardware.hpp | 20 +-- .../firmware/stepper_motor/motor_hardware.hpp | 25 +--- .../simulation/motor_interrupt_driver.hpp | 5 +- .../simulation/sim_motor_hardware_iface.hpp | 61 ++------ .../tests/mock_brushed_motor_components.hpp | 23 +-- .../tests/mock_motor_driver_client.hpp | 21 --- .../tests/mock_motor_hardware.hpp | 23 +-- include/pipettes/core/dispatch_builder.hpp | 7 +- include/pipettes/core/gear_motor_tasks.hpp | 10 +- include/pipettes/core/interfaces.hpp | 2 - include/pipettes/core/linear_motor_tasks.hpp | 21 +-- .../pipettes/core/motor_interrupt_handler.hpp | 14 +- include/pipettes/core/tasks.hpp | 2 - include/pipettes/core/tasks/messages.hpp | 7 +- .../core/tasks/motion_controller_task.hpp | 123 +++------------- include/pipettes/firmware/interfaces.hpp | 20 ++- include/pipettes/firmware/interfaces_g4.hpp | 31 ++-- include/pipettes/simulator/interfaces.hpp | 51 ++----- include/spi/core/utils.hpp | 35 +---- include/spi/core/writer.hpp | 14 +- .../brushed_motor/brushed_motor_hardware.cpp | 2 - .../firmware/stepper_motor/motor_hardware.cpp | 2 - .../test_brushed_motor_interrupt_handler.cpp | 4 +- motor-control/tests/test_limit_switch.cpp | 10 +- .../tests/test_limit_switch_backoff.cpp | 10 +- .../tests/test_motor_interrupt_handler.cpp | 9 +- .../tests/test_motor_interrupt_queue.cpp | 6 +- motor-control/tests/test_motor_pulse.cpp | 10 +- .../tests/test_motor_stall_handling.cpp | 10 +- motor-control/tests/test_sync_handling.cpp | 10 +- pipettes/core/gear_motor_tasks.cpp | 35 +---- pipettes/core/linear_motor_tasks.cpp | 29 ++-- pipettes/firmware/hardware_config.c | 21 +-- pipettes/firmware/hardware_config.h | 2 - pipettes/firmware/interfaces.cpp | 20 +-- pipettes/firmware/main.cpp | 32 +---- pipettes/firmware/motor_configurations.cpp | 21 +-- pipettes/firmware/motor_hardware.c | 9 +- pipettes/firmware/stm32g4xx_it.c | 4 - pipettes/firmware/utility_gpio.c | 10 -- pipettes/simulator/interfaces.cpp | 71 ++------- pipettes/simulator/main.cpp | 6 +- sensors/tests/CMakeLists.txt | 2 +- 105 files changed, 386 insertions(+), 1501 deletions(-) delete mode 100644 include/motor-control/tests/mock_motor_driver_client.hpp diff --git a/.github/workflows/build-tests.yaml b/.github/workflows/build-tests.yaml index 375c02434..b6fbfd09d 100644 --- a/.github/workflows/build-tests.yaml +++ b/.github/workflows/build-tests.yaml @@ -18,7 +18,7 @@ jobs: build-and-test: name: Run all tests runs-on: "ubuntu-20.04" - timeout-minutes: 20 + timeout-minutes: 10 steps: - name: Checkout ot3-firmware repo uses: actions/checkout@v4 diff --git a/gantry/core/tasks_proto.cpp b/gantry/core/tasks_proto.cpp index 965adbd0f..de020ffc3 100644 --- a/gantry/core/tasks_proto.cpp +++ b/gantry/core/tasks_proto.cpp @@ -55,20 +55,18 @@ static auto eeprom_data_rev_update_builder = /** * Start gantry tasks. */ -auto gantry::tasks::start_tasks( +void gantry::tasks::start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& motion_controller, spi::hardware::SpiDeviceBase& spi_device, 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) { 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, ::queues); + auto& motion = mc_task_builder.start(5, "motion controller", + motion_controller, ::queues, ::queues); auto& tmc2130_driver = motor_driver_task_builder.start( 5, "tmc2130 driver", driver_configs, ::queues, spi_task_client); auto& move_group = @@ -118,15 +116,6 @@ auto gantry::tasks::start_tasks( ::queues.usage_storage_queue = &usage_storage_task.get_queue(); mh_tsk.start_task(); - - return gantry::tasks::call_run_diag0_interrupt; -} - -void gantry::tasks::call_run_diag0_interrupt() { - if (gantry::tasks::get_tasks().motion_controller) { - return gantry::tasks::get_tasks() - .motion_controller->run_diag0_interrupt(); - } } gantry::queues::QueueClient::QueueClient(can::ids::NodeId this_fw) @@ -142,11 +131,6 @@ void gantry::queues::QueueClient::send_motor_driver_queue( motor_driver_queue->try_write(m); } -void gantry::queues::QueueClient::send_motor_driver_queue_isr( - const tmc2130::tasks::TaskMessage& m) { - static_cast(motor_driver_queue->try_write_isr(m)); -} - void gantry::queues::QueueClient::send_move_group_queue( const move_group_task::TaskMessage& m) { move_group_queue->try_write(m); diff --git a/gantry/core/tasks_rev1.cpp b/gantry/core/tasks_rev1.cpp index 4ba6f156c..95c81ba29 100644 --- a/gantry/core/tasks_rev1.cpp +++ b/gantry/core/tasks_rev1.cpp @@ -54,20 +54,18 @@ static auto tail_accessor = eeprom::dev_data::DevDataTailAccessor{queues}; /** * Start gantry ::tasks. */ -auto gantry::tasks::start_tasks( +void gantry::tasks::start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& motion_controller, spi::hardware::SpiDeviceBase& spi_device, 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) { 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, ::queues); + auto& motion = mc_task_builder.start(5, "motion controller", + motion_controller, ::queues, ::queues); auto& tmc2160_driver = motor_driver_task_builder.start( 5, "tmc2160 driver", driver_configs, ::queues, spi_task_client); auto& move_group = @@ -117,15 +115,6 @@ auto gantry::tasks::start_tasks( ::queues.usage_storage_queue = &usage_storage_task.get_queue(); mh_tsk.start_task(); - - return gantry::tasks::call_run_diag0_interrupt; -} - -void gantry::tasks::call_run_diag0_interrupt() { - if (gantry::tasks::get_tasks().motion_controller) { - return gantry::tasks::get_tasks() - .motion_controller->run_diag0_interrupt(); - } } gantry::queues::QueueClient::QueueClient(can::ids::NodeId this_fw) @@ -141,11 +130,6 @@ void gantry::queues::QueueClient::send_motor_driver_queue( motor_driver_queue->try_write(m); } -void gantry::queues::QueueClient::send_motor_driver_queue_isr( - const tmc2160::tasks::TaskMessage& m) { - static_cast(motor_driver_queue->try_write_isr(m)); -} - void gantry::queues::QueueClient::send_move_group_queue( const move_group_task::TaskMessage& m) { move_group_queue->try_write(m); diff --git a/gantry/firmware/interfaces_proto.cpp b/gantry/firmware/interfaces_proto.cpp index 0c142d197..584fd990e 100644 --- a/gantry/firmware/interfaces_proto.cpp +++ b/gantry/firmware/interfaces_proto.cpp @@ -86,16 +86,10 @@ 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}, - .diag0 = { + .estop_in = { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) - .port = GPIOC, - .pin = GPIO_PIN_5, + .port = GPIOA, + .pin = GPIO_PIN_10, .active_setting = GPIO_PIN_RESET} }; @@ -131,21 +125,15 @@ 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}, - .diag0 = { + .estop_in = { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) - .port = GPIOC, - .pin = GPIO_PIN_5, + .port = GPIOA, + .pin = GPIO_PIN_10, .active_setting = GPIO_PIN_RESET} }; static tmc2130::configs::TMC2130DriverConfig gantry_x_driver_configs{ - .registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1}, + .registers = {.gconfig = {.en_pwm_mode = 1}, .ihold_irun = {.hold_current = 0x2, .run_current = 0x18, .hold_current_delay = 0x7}, @@ -168,7 +156,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}, .ihold_irun = {.hold_current = 0x2, .run_current = 0x18, .hold_current_delay = 0x7}, @@ -244,8 +232,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(), motor_hardware_iface, stallcheck, + update_position_queue); static auto encoder_background_timer = motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface); @@ -281,14 +269,13 @@ static constexpr auto can_bit_timings = can::bit_timings::BitTimings<170 * can::bit_timings::MHZ, 100, 500 * can::bit_timings::KHZ, 800>{}; -void interfaces::initialize(diag0_handler* call_diag0_handler) { +void interfaces::initialize() { // Initialize SPI if (initialize_spi(get_axis_type()) != HAL_OK) { Error_Handler(); } - initialize_timer(call_motor_handler, call_diag0_handler, - enc_overflow_callback); + initialize_timer(call_motor_handler, enc_overflow_callback); // Start the can bus canbus.start(can_bit_timings); diff --git a/gantry/firmware/interfaces_rev1.cpp b/gantry/firmware/interfaces_rev1.cpp index d34b82c10..bf0de3359 100644 --- a/gantry/firmware/interfaces_rev1.cpp +++ b/gantry/firmware/interfaces_rev1.cpp @@ -86,16 +86,10 @@ 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}, - .diag0 = { + .estop_in = { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) - .port = GPIOC, - .pin = GPIO_PIN_5, + .port = GPIOA, + .pin = GPIO_PIN_10, .active_setting = GPIO_PIN_RESET} }; @@ -131,21 +125,15 @@ 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}, - .diag0 = { + .estop_in = { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) - .port = GPIOC, - .pin = GPIO_PIN_5, + .port = GPIOA, + .pin = GPIO_PIN_10, .active_setting = GPIO_PIN_RESET} }; static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{ - .registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1}, + .registers = {.gconfig = {.en_pwm_mode = 0}, .ihold_irun = {.hold_current = 16, .run_current = 31, .hold_current_delay = 0x7}, @@ -171,7 +159,6 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{ .freewheel = 0, .pwm_reg = 0x7, .pwm_lim = 0xC}, - .drvconf = {.ot_select = 0}, .glob_scale = {.global_scaler = 0xA7}}, .current_config = { @@ -185,7 +172,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}, .ihold_irun = {.hold_current = 16, .run_current = 31, .hold_current_delay = 0x7}, @@ -211,7 +198,6 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_y{ .freewheel = 0, .pwm_reg = 0x7, .pwm_lim = 0xC}, - .drvconf = {.ot_select = 0}, .glob_scale = {.global_scaler = 0xA7}}, .current_config = { @@ -271,8 +257,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(), motor_hardware_iface, stallcheck, + update_position_queue); static auto encoder_background_timer = motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface); @@ -309,14 +295,13 @@ static constexpr auto can_bit_timings = can::bit_timings::BitTimings<170 * can::bit_timings::MHZ, 100, 500 * can::bit_timings::KHZ, 800>{}; -void interfaces::initialize(diag0_handler* call_diag0_handler) { +void interfaces::initialize() { // Initialize SPI if (initialize_spi(get_axis_type()) != HAL_OK) { Error_Handler(); } - initialize_timer(call_motor_handler, call_diag0_handler, - enc_overflow_callback); + initialize_timer(call_motor_handler, enc_overflow_callback); // Start the can bus canbus.start(can_bit_timings); diff --git a/gantry/firmware/main_proto.cpp b/gantry/firmware/main_proto.cpp index 55d10cc16..cf7c26e03 100644 --- a/gantry/firmware/main_proto.cpp +++ b/gantry/firmware/main_proto.cpp @@ -16,8 +16,6 @@ #include "gantry/core/tasks_proto.hpp" #include "i2c/firmware/i2c_comms.hpp" -static interfaces::diag0_handler call_diag0_handler = nullptr; - static auto i2c_comms2 = i2c::hardware::I2C(); static auto i2c_handles = I2CHandlerStruct{}; @@ -46,11 +44,11 @@ auto main() -> int { app_update_clear_flags(); - interfaces::initialize(&call_diag0_handler); + interfaces::initialize(); i2c_setup(&i2c_handles); i2c_comms2.set_handle(i2c_handles.i2c2); - call_diag0_handler = gantry::tasks::start_tasks( + gantry::tasks::start_tasks( interfaces::get_can_bus(), interfaces::get_motor().motion_controller, interfaces::get_spi(), interfaces::get_driver_config(), interfaces::get_motor_hardware_task(), i2c_comms2, eeprom_hw_iface); diff --git a/gantry/firmware/main_rev1.cpp b/gantry/firmware/main_rev1.cpp index 77b198539..39fed3b73 100644 --- a/gantry/firmware/main_rev1.cpp +++ b/gantry/firmware/main_rev1.cpp @@ -16,8 +16,6 @@ #include "gantry/core/tasks_rev1.hpp" #include "i2c/firmware/i2c_comms.hpp" -static interfaces::diag0_handler call_diag0_handler = nullptr; - static auto i2c_comms2 = i2c::hardware::I2C(); static auto i2c_handles = I2CHandlerStruct{}; @@ -46,11 +44,11 @@ auto main() -> int { app_update_clear_flags(); - interfaces::initialize(&call_diag0_handler); + interfaces::initialize(); i2c_setup(&i2c_handles); i2c_comms2.set_handle(i2c_handles.i2c2); - call_diag0_handler = gantry::tasks::start_tasks( + gantry::tasks::start_tasks( interfaces::get_can_bus(), interfaces::get_motor().motion_controller, interfaces::get_spi(), interfaces::get_driver_config(), interfaces::get_motor_hardware_task(), i2c_comms2, eeprom_hw_iface); diff --git a/gantry/firmware/motor_hardware.c b/gantry/firmware/motor_hardware.c index 637087c76..f48bcb6d7 100644 --- a/gantry/firmware/motor_hardware.c +++ b/gantry/firmware/motor_hardware.c @@ -23,8 +23,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { PC8 ------> Motor Step Pin Enable PA9 ------> Motor Enable Pin - DIAG0 - PC5 ------> Motor Diag0 Pin */ GPIO_InitStruct.Pin = GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -56,12 +54,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(GPIOA, // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) &GPIO_InitStruct); - - // Diag0 - GPIO_InitStruct.Pin = GPIO_PIN_5; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); } } SPI_HandleTypeDef hspi2 = { @@ -95,7 +87,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) { HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_1); HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9); - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8 | GPIO_PIN_5); + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8); } } @@ -127,7 +119,6 @@ HAL_StatusTypeDef initialize_spi(enum GantryAxisType gantry_type) { static motor_interrupt_callback timer_callback = NULL; static encoder_overflow_callback enc_overflow_callback = NULL; -static diag0_interrupt_callback* diag0_callback = NULL; /** @@ -149,9 +140,6 @@ void MX_GPIO_Init(void) { GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); } // motor timer: 200kHz from @@ -248,16 +236,6 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { } } -void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { - if (GPIO_Pin == GPIO_PIN_5) { - if (diag0_callback != NULL) { - if (*diag0_callback != NULL) { - (*diag0_callback)(); - } - } - } -} - void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) { if (htim == &htim2) { /* Peripheral clock enable */ @@ -277,10 +255,9 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) { } } -void initialize_timer(motor_interrupt_callback callback, diag0_interrupt_callback* diag0_int_callback, encoder_overflow_callback enc_callback) { +void initialize_timer(motor_interrupt_callback callback, encoder_overflow_callback enc_callback) { timer_callback = callback; enc_overflow_callback = enc_callback; - diag0_callback = diag0_int_callback; MX_GPIO_Init(); MX_TIM7_Init(); Encoder_GPIO_Init(); diff --git a/gantry/firmware/motor_hardware.h b/gantry/firmware/motor_hardware.h index 3a3024ac6..fa2e0ac71 100644 --- a/gantry/firmware/motor_hardware.h +++ b/gantry/firmware/motor_hardware.h @@ -14,12 +14,11 @@ extern TIM_HandleTypeDef htim2; typedef void (*motor_interrupt_callback)(); typedef void (*encoder_overflow_callback)(int32_t); -typedef void (*diag0_interrupt_callback)(); HAL_StatusTypeDef initialize_spi(enum GantryAxisType); void gantry_driver_CLK_init(enum GantryAxisType); -void initialize_timer(motor_interrupt_callback callback, diag0_interrupt_callback* diag0_int_callback, encoder_overflow_callback enc_callback); +void initialize_timer(motor_interrupt_callback callback, encoder_overflow_callback enc_callback); #ifdef __cplusplus } // extern "C" diff --git a/gantry/firmware/stm32g4xx_it.c b/gantry/firmware/stm32g4xx_it.c index 07463106c..b4f589e8f 100644 --- a/gantry/firmware/stm32g4xx_it.c +++ b/gantry/firmware/stm32g4xx_it.c @@ -147,7 +147,6 @@ void FDCAN1_IT0_IRQHandler(void) { */ void TIM7_IRQHandler(void) { HAL_TIM_IRQHandler(&htim7); } void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); } -void EXTI9_5_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5); } extern void xPortSysTickHandler(void); diff --git a/gantry/simulator/interfaces.cpp b/gantry/simulator/interfaces.cpp index a22db5105..f1a59f0bd 100644 --- a/gantry/simulator/interfaces.cpp +++ b/gantry/simulator/interfaces.cpp @@ -89,16 +89,14 @@ 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(), motor_interface, stallcheck, + update_position_queue); static motor_interrupt_driver::MotorInterruptDriver A(motor_queue, motor_interrupt, motor_interface, update_position_queue); -void interfaces::initialize(diag0_handler* call_diag0_handler) { - static_cast(call_diag0_handler); -} +void interfaces::initialize() {} static po::variables_map options{}; diff --git a/gantry/simulator/main.cpp b/gantry/simulator/main.cpp index 77a2d985d..d78b931e2 100644 --- a/gantry/simulator/main.cpp +++ b/gantry/simulator/main.cpp @@ -12,8 +12,6 @@ void signal_handler(int signum) { exit(signum); } -static interfaces::diag0_handler call_diag0_handler = NULL; - int main(int argc, char** argv) { signal(SIGINT, signal_handler); @@ -23,10 +21,10 @@ int main(int argc, char** argv) { return pcTaskGetName(xTaskGetCurrentTaskHandle()); }); - interfaces::initialize(&call_diag0_handler); + interfaces::initialize(); interfaces::initialize_sim(argc, argv); - call_diag0_handler = gantry::tasks::start_tasks( + gantry::tasks::start_tasks( interfaces::get_can_bus(), interfaces::get_motor().motion_controller, interfaces::get_spi(), interfaces::get_driver_config(), interfaces::get_motor_hardware_task(), *interfaces::get_sim_i2c2(), diff --git a/gripper/core/tasks.cpp b/gripper/core/tasks.cpp index 00a250ace..cd16770c6 100644 --- a/gripper/core/tasks.cpp +++ b/gripper/core/tasks.cpp @@ -58,7 +58,7 @@ static auto eeprom_data_rev_update_builder = /** * Start gripper tasks. */ -auto gripper_tasks::start_tasks( +void gripper_tasks::start_tasks( can::bus::CanBus& can_bus, motor_class::Motor& z_motor, brushed_motor::BrushedMotor& grip_motor, @@ -68,8 +68,7 @@ auto gripper_tasks::start_tasks( sensors::hardware::SensorHardwareBase& sensor_hardware, eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface, motor_hardware_task::MotorHardwareTask& zmh_tsk, - motor_hardware_task::MotorHardwareTask& gmh_tsk) - -> z_motor_iface::diag0_handler { + motor_hardware_task::MotorHardwareTask& gmh_tsk) { auto& can_writer = can_task::start_writer(can_bus); can_task::start_reader(can_bus); tasks.can_writer = &can_writer; @@ -123,8 +122,8 @@ auto gripper_tasks::start_tasks( queues.capacitive_sensor_queue_rear = &capacitive_sensor_task_rear.get_queue(); - auto diag0_handler = z_tasks::start_task( - z_motor, spi_device, driver_configs, tasks, queues, tail_accessor); + z_tasks::start_task(z_motor, spi_device, driver_configs, tasks, queues, + tail_accessor); g_tasks::start_task(grip_motor, tasks, queues, tail_accessor); @@ -133,8 +132,6 @@ auto gripper_tasks::start_tasks( zmh_tsk.start_task(); gmh_tsk.start_task(); - - return diag0_handler; } gripper_tasks::QueueClient::QueueClient(can::ids::NodeId this_fw) diff --git a/gripper/core/tasks_z.cpp b/gripper/core/tasks_z.cpp index ce5f9b306..43432ea46 100644 --- a/gripper/core/tasks_z.cpp +++ b/gripper/core/tasks_z.cpp @@ -34,16 +34,15 @@ static auto z_usage_storage_task_builder = freertos_task::TaskStarter<512, usage_storage_task::UsageStorageTask>{}; #endif -auto z_tasks::start_task( +void z_tasks::start_task( motor_class::Motor& z_motor, spi::hardware::SpiDeviceBase& spi_device, tmc2130::configs::TMC2130DriverConfig& driver_configs, AllTask& gripper_tasks, gripper_tasks::QueueClient& main_queues, eeprom::dev_data::DevDataTailAccessor& - tail_accessor) -> z_motor_iface::diag0_handler { - auto& motion = - mc_task_builder.start(5, "z mc", z_motor.motion_controller, z_queues, - z_queues, z_queues, z_queues); + tail_accessor) { + auto& motion = mc_task_builder.start(5, "z mc", z_motor.motion_controller, + z_queues, z_queues); auto& move_group = move_group_task_builder.start(5, "move group", z_queues, z_queues); auto& tmc2130_driver = motor_driver_task_builder.start( @@ -78,14 +77,6 @@ auto z_tasks::start_task( z_queues.z_usage_storage_queue = &z_usage_storage_task.get_queue(); #endif spi_task_client.set_queue(&spi_task.get_queue()); - - return z_tasks::call_run_diag0_interrupt; -} - -void z_tasks::call_run_diag0_interrupt() { - if (get_all_tasks().motion_controller) { - return get_all_tasks().motion_controller->run_diag0_interrupt(); - } } z_tasks::QueueClient::QueueClient() @@ -101,11 +92,6 @@ void z_tasks::QueueClient::send_motor_driver_queue( tmc2130_driver_queue->try_write(m); } -void z_tasks::QueueClient::send_motor_driver_queue_isr( - const tmc2130::tasks::TaskMessage& m) { - static_cast(tmc2130_driver_queue->try_write_isr(m)); -} - void z_tasks::QueueClient::send_move_group_queue( const move_group_task::TaskMessage& m) { move_group_queue->try_write(m); diff --git a/gripper/firmware/interfaces_z_motor.cpp b/gripper/firmware/interfaces_z_motor.cpp index cb6d1c3c0..c9c43c9a9 100644 --- a/gripper/firmware/interfaces_z_motor.cpp +++ b/gripper/firmware/interfaces_z_motor.cpp @@ -103,13 +103,7 @@ struct motion_controller::HardwareConfig motor_pins { .port = ESTOP_IN_PORT, .pin = ESTOP_IN_PIN, .active_setting = GPIO_PIN_RESET}, - .diag0 = - { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) - .port = GPIOB, - .pin = GPIO_PIN_2, - .active_setting = GPIO_PIN_RESET}, - .ebrake = ebrake + .ebrake = ebrake, }; /** @@ -125,7 +119,6 @@ static motor_hardware::MotorHardware motor_hardware_iface(motor_pins, &htim7, */ static tmc2130::configs::TMC2130DriverConfig MotorDriverConfigurations{ .registers = {.gconfig = {.en_pwm_mode = 0x0, - .diag0_error = 1, .stop_enable = use_stop_enable}, .ihold_irun = {.hold_current = 0x2, // 0.177A .run_current = 0xA, // 0.648A @@ -197,9 +190,8 @@ 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(), motor_hardware_iface, + stallcheck, update_position_queue); static auto encoder_background_timer = motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface); @@ -212,13 +204,12 @@ extern "C" void call_enc_handler(int32_t direction) { motor_hardware_iface.encoder_overflow(direction); } -void z_motor_iface::initialize(diag0_handler* call_diag0_handler) { +void z_motor_iface::initialize() { if (initialize_spi() != HAL_OK) { Error_Handler(); } initialize_hardware_z(); - set_z_motor_timer_callback(call_motor_handler, call_diag0_handler, - call_enc_handler); + set_z_motor_timer_callback(call_motor_handler, call_enc_handler); encoder_background_timer.start(); } diff --git a/gripper/firmware/main_proto.cpp b/gripper/firmware/main_proto.cpp index 5ff96f001..b34d83acf 100644 --- a/gripper/firmware/main_proto.cpp +++ b/gripper/firmware/main_proto.cpp @@ -25,8 +25,6 @@ #include "i2c/firmware/i2c_comms.hpp" #include "sensors/firmware/sensor_hardware.hpp" -static z_motor_iface::diag0_handler call_diag0_handler = nullptr; - static auto iWatchdog = iwdg::IndependentWatchDog{}; /** @@ -97,7 +95,7 @@ auto main() -> int { app_update_clear_flags(); - z_motor_iface::initialize(&call_diag0_handler); + z_motor_iface::initialize(); grip_motor_iface::initialize(); i2c_setup(&i2c_handles); @@ -105,7 +103,7 @@ auto main() -> int { i2c_comms3.set_handle(i2c_handles.i2c3); canbus.start(can_bit_timings); - call_diag0_handler = gripper_tasks::start_tasks( + gripper_tasks::start_tasks( canbus, z_motor_iface::get_z_motor(), grip_motor_iface::get_grip_motor(), z_motor_iface::get_spi(), z_motor_iface::get_tmc2130_driver_configs(), i2c_comms2, i2c_comms3, diff --git a/gripper/firmware/main_rev1.cpp b/gripper/firmware/main_rev1.cpp index f07597938..62572ef6a 100644 --- a/gripper/firmware/main_rev1.cpp +++ b/gripper/firmware/main_rev1.cpp @@ -26,8 +26,6 @@ #include "i2c/firmware/i2c_comms.hpp" #include "sensors/firmware/sensor_hardware.hpp" -static z_motor_iface::diag0_handler call_diag0_handler = nullptr; - static auto iWatchdog = iwdg::IndependentWatchDog{}; /** @@ -108,7 +106,7 @@ auto main() -> int { app_update_clear_flags(); - z_motor_iface::initialize(&call_diag0_handler); + z_motor_iface::initialize(); grip_motor_iface::initialize(); i2c_setup(&i2c_handles); @@ -116,7 +114,7 @@ auto main() -> int { i2c_comms3.set_handle(i2c_handles.i2c3); canbus.start(can_bit_timings); - call_diag0_handler = gripper_tasks::start_tasks( + gripper_tasks::start_tasks( canbus, z_motor_iface::get_z_motor(), grip_motor_iface::get_grip_motor(), z_motor_iface::get_spi(), z_motor_iface::get_tmc2130_driver_configs(), i2c_comms2, i2c_comms3, diff --git a/gripper/firmware/motor_hardware.h b/gripper/firmware/motor_hardware.h index 4df6dbd0a..37bce25ca 100644 --- a/gripper/firmware/motor_hardware.h +++ b/gripper/firmware/motor_hardware.h @@ -32,7 +32,6 @@ extern TIM_HandleTypeDef htim8; typedef void (*motor_interrupt_callback)(); typedef void (*z_encoder_overflow_callback)(int32_t); -typedef void (*diag0_interrupt_callback)(); HAL_StatusTypeDef initialize_spi(); @@ -40,7 +39,6 @@ void initialize_hardware_z(); void set_z_motor_timer_callback( motor_interrupt_callback callback, - diag0_interrupt_callback* diag0_int_callback, z_encoder_overflow_callback enc_callback); diff --git a/gripper/firmware/motor_hardware_shared.c b/gripper/firmware/motor_hardware_shared.c index f6118af8b..997322797 100644 --- a/gripper/firmware/motor_hardware_shared.c +++ b/gripper/firmware/motor_hardware_shared.c @@ -3,7 +3,6 @@ static motor_interrupt_callback timer_callback = NULL; static z_encoder_overflow_callback z_enc_overflow_callback = NULL; -static diag0_interrupt_callback* diag0_callback = NULL; static brushed_motor_interrupt_callback brushed_timer_callback = NULL; static encoder_overflow_callback gripper_enc_overflow_callback = NULL; static encoder_idle_state_callback gripper_enc_idle_state_overflow_callback = @@ -11,19 +10,11 @@ static encoder_idle_state_callback gripper_enc_idle_state_overflow_callback = static stopwatch_overflow_callback gripper_force_stopwatch_overflow_callback = NULL; -void MX_GPIO_Init(void) { - HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI2_IRQn); -} - void set_z_motor_timer_callback( motor_interrupt_callback callback, - diag0_interrupt_callback* diag0_int_callback, z_encoder_overflow_callback enc_callback) { timer_callback = callback; z_enc_overflow_callback = enc_callback; - diag0_callback = diag0_int_callback; - MX_GPIO_Init(); } void set_brushed_motor_timer_callback( @@ -221,14 +212,9 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim) { } } + void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { - if (GPIO_Pin == GPIO_PIN_2) { - if (diag0_callback != NULL) { - if (*diag0_callback != NULL) { - (*diag0_callback)(); - } - } - } else if (GPIO_Pin == ESTOP_IN_PIN) { + if (GPIO_Pin == ESTOP_IN_PIN) { #if PCBA_PRIMARY_REVISION != 'b' && PCBA_PRIMARY_REVISION != 'a' HAL_GPIO_WritePin(EBRAKE_PORT, EBRAKE_PIN, GPIO_PIN_RESET); #endif diff --git a/gripper/firmware/stm32g4xx_it.c b/gripper/firmware/stm32g4xx_it.c index 6a90023e6..2051ebc6b 100644 --- a/gripper/firmware/stm32g4xx_it.c +++ b/gripper/firmware/stm32g4xx_it.c @@ -198,11 +198,6 @@ void TIM7_IRQHandler(void) { call_motor_handler(); } -__attribute__((section(".ccmram"))) -void EXTI2_IRQHandler(void) { - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); -} - /** * @brief This function handles EXTI line[15:10] interrupts. */ diff --git a/gripper/firmware/utility_gpio.c b/gripper/firmware/utility_gpio.c index 9c25e0b46..551f5cc12 100644 --- a/gripper/firmware/utility_gpio.c +++ b/gripper/firmware/utility_gpio.c @@ -108,8 +108,6 @@ static void z_motor_gpio_init(void) { PB1 ------> Motor Step Pin Enable PA9 ------> Motor Enable Pin - Diag0 - PB2 ------> Motor Diag0 Pin */ GPIO_InitStruct.Pin = Z_MOT_DIR_PIN | Z_MOT_STEP_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; @@ -121,11 +119,6 @@ static void z_motor_gpio_init(void) { GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(Z_MOT_ENABLE_PORT, // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) &GPIO_InitStruct); - - GPIO_InitStruct.Pin = Z_MOT_DIAG0_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(Z_MOT_STEPDIR_PORT, &GPIO_InitStruct); } #if PCBA_PRIMARY_REVISION != 'b' && PCBA_PRIMARY_REVISION != 'a' diff --git a/gripper/simulator/interfaces.cpp b/gripper/simulator/interfaces.cpp index bdc4ce326..f3dfd2a14 100644 --- a/gripper/simulator/interfaces.cpp +++ b/gripper/simulator/interfaces.cpp @@ -94,9 +94,8 @@ 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(), motor_interface, + stallcheck, update_position_queue); static motor_interrupt_driver::MotorInterruptDriver A(motor_queue, motor_interrupt, @@ -136,8 +135,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) { - static_cast(call_diag0_handler); +void z_motor_iface::initialize() { motor_interface.provide_mech_config(z_motor_sys_config); }; diff --git a/gripper/simulator/main.cpp b/gripper/simulator/main.cpp index c3f235244..831f2673d 100644 --- a/gripper/simulator/main.cpp +++ b/gripper/simulator/main.cpp @@ -21,8 +21,6 @@ namespace po = boost::program_options; -static z_motor_iface::diag0_handler call_diag0_handler = nullptr; - void signal_handler(int signum) { LOG("Interrupt signal (%d) received.", signum); exit(signum); @@ -113,9 +111,9 @@ int main(int argc, char** argv) { auto i2c3 = std::make_shared(i2c_device_map); static auto canbus = can::sim::bus::SimCANBus(can::sim::transport::create(options)); - z_motor_iface::initialize(&call_diag0_handler); + z_motor_iface::initialize(); grip_motor_iface::initialize(); - call_diag0_handler = gripper_tasks::start_tasks( + gripper_tasks::start_tasks( canbus, z_motor_iface::get_z_motor(), grip_motor_iface::get_grip_motor(), z_motor_iface::get_spi(), z_motor_iface::get_tmc2130_driver_configs(), i2c2, *i2c3, diff --git a/head/core/can_task.cpp b/head/core/can_task.cpp index dcb1f3359..6cc432b07 100644 --- a/head/core/can_task.cpp +++ b/head/core/can_task.cpp @@ -28,8 +28,7 @@ using MotorDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::motor::MotorHandler, can::messages::ReadMotorDriverRegister, can::messages::WriteMotorDriverRegister, - can::messages::WriteMotorCurrentRequest, - can::messages::ReadMotorDriverErrorStatusRequest>; + can::messages::WriteMotorCurrentRequest>; using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::move_group::MoveGroupHandler< head_tasks::MotorQueueClient>, diff --git a/head/core/tasks_proto.cpp b/head/core/tasks_proto.cpp index c3c09d968..2690550ca 100644 --- a/head/core/tasks_proto.cpp +++ b/head/core/tasks_proto.cpp @@ -78,25 +78,10 @@ static auto eeprom_data_rev_update_builder = freertos_task::TaskStarter<512, eeprom::data_rev_task::UpdateDataRevTask>{}; 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(); - } -} - -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(); - } -} - /** * Start head tasks. */ -auto head_tasks::start_tasks( +void head_tasks::start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& left_motion_controller, @@ -110,8 +95,7 @@ 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 { + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) { // Start the head tasks auto& can_writer = can_task::start_writer(can_bus); can_task::start_reader(can_bus); @@ -157,8 +141,7 @@ auto head_tasks::start_tasks( // 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, left_queues); + 5, "left mc", left_motion_controller, 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); @@ -187,8 +170,7 @@ auto head_tasks::start_tasks( // 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, right_queues); + 5, "right mc", right_motion_controller, 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); @@ -217,9 +199,6 @@ 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); } // Implementation of HeadQueueClient @@ -252,11 +231,6 @@ void head_tasks::MotorQueueClient::send_motor_driver_queue( motor_queue->try_write(m); } -void head_tasks::MotorQueueClient::send_motor_driver_queue_isr( - const tmc2130::tasks::TaskMessage& m) { - static_cast(motor_queue->try_write_isr(m)); -} - void head_tasks::MotorQueueClient::send_move_group_queue( const move_group_task::TaskMessage& m) { move_group_queue->try_write(m); diff --git a/head/core/tasks_rev1.cpp b/head/core/tasks_rev1.cpp index c86699d71..2cf2d803d 100644 --- a/head/core/tasks_rev1.cpp +++ b/head/core/tasks_rev1.cpp @@ -83,25 +83,10 @@ static auto right_usage_storage_task_builder = static auto eeprom_data_rev_update_builder = freertos_task::TaskStarter<512, eeprom::data_rev_task::UpdateDataRevTask>{}; #endif - -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(); - } -} - -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(); - } -} - /** * Start head tasks. */ -auto head_tasks::start_tasks( +void head_tasks::start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& left_motion_controller, @@ -115,8 +100,7 @@ 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 { + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) { // Start the head tasks auto& can_writer = can_task::start_writer(can_bus); can_task::start_reader(can_bus); @@ -162,8 +146,7 @@ auto head_tasks::start_tasks( #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, left_queues); + 5, "left mc", left_motion_controller, 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); @@ -200,8 +183,7 @@ auto head_tasks::start_tasks( // 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, right_queues); + 5, "right mc", right_motion_controller, 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); @@ -238,9 +220,6 @@ auto head_tasks::start_tasks( #if PCBA_PRIMARY_REVISION != 'b' 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); } // Implementation of HeadQueueClient @@ -277,11 +256,6 @@ void head_tasks::MotorQueueClient::send_motor_driver_queue( motor_queue->try_write(m); } -void head_tasks::MotorQueueClient::send_motor_driver_queue_isr( - const tmc::tasks::TaskMessage& m) { - static_cast(motor_queue->try_write_isr(m)); -} - void head_tasks::MotorQueueClient::send_move_group_queue( const move_group_task::TaskMessage& m) { move_group_queue->try_write(m); diff --git a/head/firmware/main_proto.cpp b/head/firmware/main_proto.cpp index 614af1142..d3ba07641 100644 --- a/head/firmware/main_proto.cpp +++ b/head/firmware/main_proto.cpp @@ -1,7 +1,6 @@ #include #include #include -#include // clang-format off #include "FreeRTOS.h" @@ -41,9 +40,6 @@ static auto iWatchdog = iwdg::IndependentWatchDog{}; -static head_tasks::diag0_handler call_diag0_z_handler = nullptr; -static head_tasks::diag0_handler call_diag0_a_handler = nullptr; - static auto can_bus_1 = can::hal::bus::HalCanBus( can_get_device_handle(), gpio::PinConfig{// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) @@ -146,16 +142,10 @@ 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, + .port = GPIOB, + .pin = GPIO_PIN_4, .active_setting = GPIO_PIN_RESET} }; @@ -196,16 +186,10 @@ 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, + .port = GPIOB, + .pin = GPIO_PIN_4, .active_setting = GPIO_PIN_RESET} }; @@ -213,7 +197,7 @@ struct motor_hardware::HardwareConfig pin_configurations_right { static tmc2130::configs::TMC2130DriverConfig motor_driver_configs_right{ .registers = { - .gconfig = {.en_pwm_mode = 1, .diag0_error = 1}, + .gconfig = {.en_pwm_mode = 1}, .ihold_irun = {.hold_current = 0xB, .run_current = 0x19, .hold_current_delay = 0x7}, @@ -240,7 +224,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}, + .gconfig = {.en_pwm_mode = 1}, .ihold_irun = {.hold_current = 0xB, .run_current = 0x19, .hold_current_delay = 0x7}, @@ -284,9 +268,8 @@ 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(), motor_hardware_right, + stallcheck_right, update_position_queue_right); static auto encoder_background_timer_right = motor_encoder::BackgroundTimer(motor_interrupt_right, motor_hardware_right); @@ -306,9 +289,8 @@ 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(), motor_hardware_left, + stallcheck_left, update_position_queue_left); static auto encoder_background_timer_left = motor_encoder::BackgroundTimer(motor_interrupt_left, motor_hardware_left); @@ -411,8 +393,7 @@ 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); if (initialize_spi(&hspi2) != HAL_OK) { Error_Handler(); @@ -426,12 +407,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); + + 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(); diff --git a/head/firmware/main_rev1.cpp b/head/firmware/main_rev1.cpp index e6d17776f..ce5849129 100644 --- a/head/firmware/main_rev1.cpp +++ b/head/firmware/main_rev1.cpp @@ -1,7 +1,6 @@ #include #include #include -#include // clang-format off #include "FreeRTOS.h" @@ -41,9 +40,6 @@ static auto iWatchdog = iwdg::IndependentWatchDog{}; -static head_tasks::diag0_handler call_diag0_z_handler = nullptr; -static head_tasks::diag0_handler call_diag0_a_handler = nullptr; - static auto can_bus_1 = can::hal::bus::HalCanBus( can_get_device_handle(), gpio::PinConfig{// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) @@ -158,12 +154,6 @@ struct motor_hardware::HardwareConfig pin_configurations_left { .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}, .ebrake = gpio::PinConfig { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) .port = GPIOB, .pin = GPIO_PIN_5, .active_setting = GPIO_PIN_RESET @@ -208,12 +198,6 @@ struct motor_hardware::HardwareConfig pin_configurations_right { .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}, .ebrake = gpio::PinConfig { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) .port = GPIOB, .pin = GPIO_PIN_0, .active_setting = GPIO_PIN_RESET @@ -222,7 +206,7 @@ struct motor_hardware::HardwareConfig pin_configurations_right { // TODO clean up the head main file by using interfaces. static tmc2160::configs::TMC2160DriverConfig motor_driver_configs_right{ - .registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1}, + .registers = {.gconfig = {.en_pwm_mode = 0}, .ihold_irun = {.hold_current = 16, .run_current = 31, .hold_current_delay = 0x7}, @@ -248,7 +232,7 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_configs_right{ }}; static tmc2160::configs::TMC2160DriverConfig motor_driver_configs_left{ - .registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1}, + .registers = {.gconfig = {.en_pwm_mode = 0}, .ihold_irun = {.hold_current = 16, .run_current = 31, .hold_current_delay = 0x7}, @@ -302,9 +286,8 @@ 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(), motor_hardware_right, + stallcheck_right, update_position_queue_right); static auto encoder_background_timer_right = motor_encoder::BackgroundTimer(motor_interrupt_right, motor_hardware_right); @@ -328,9 +311,8 @@ 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(), motor_hardware_left, + stallcheck_left, update_position_queue_left); static auto encoder_background_timer_left = motor_encoder::BackgroundTimer(motor_interrupt_left, motor_hardware_left); @@ -436,8 +418,7 @@ 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); i2c_setup(&i2c_handles); i2c_comms3.set_handle(i2c_handles.i2c3); @@ -451,12 +432,11 @@ 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); + 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(); diff --git a/head/firmware/motor_hardware.h b/head/firmware/motor_hardware.h index 2cce7382f..e01e68d85 100644 --- a/head/firmware/motor_hardware.h +++ b/head/firmware/motor_hardware.h @@ -14,14 +14,11 @@ extern TIM_HandleTypeDef htim3; typedef void (*motor_interrupt_callback)(); typedef void (*encoder_overflow_callback)(int32_t); -typedef void (*diag0_interrupt_callback)(); HAL_StatusTypeDef initialize_spi(SPI_HandleTypeDef* hspi); void initialize_timer(motor_interrupt_callback callback, encoder_overflow_callback left_enc_overflow_callback, - encoder_overflow_callback right_enc_overflow_callback, - diag0_interrupt_callback* diag0_z_int_callback, - diag0_interrupt_callback* diag0_a_int_callback); + encoder_overflow_callback right_enc_overflow_callback); void initialize_rev_specific_pins(); #ifdef __cplusplus diff --git a/head/firmware/motor_hardware_common.c b/head/firmware/motor_hardware_common.c index e895252fe..d1313df4d 100644 --- a/head/firmware/motor_hardware_common.c +++ b/head/firmware/motor_hardware_common.c @@ -21,8 +21,6 @@ TIM_HandleTypeDef htim3 = { motor_interrupt_callback motor_callback = NULL; encoder_overflow_callback left_enc_overflow_callback = NULL; encoder_overflow_callback right_enc_overflow_callback = NULL; -static diag0_interrupt_callback* diag0_z_callback = NULL; -static diag0_interrupt_callback* diag0_a_callback = NULL; void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { GPIO_InitTypeDef GPIO_InitStruct = {0}; @@ -57,14 +55,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; HAL_GPIO_Init(GPIOC, // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) &GPIO_InitStruct); - - // A motor diag0 - GPIO_InitStruct.Pin = GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) - &GPIO_InitStruct); } else if (hspi->Instance == SPI3) { @@ -101,14 +91,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) &GPIO_InitStruct); - - // Z motor diag0 - GPIO_InitStruct.Pin = GPIO_PIN_13; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) - &GPIO_InitStruct); } } @@ -247,9 +229,6 @@ void MX_GPIO_Init(void) { __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); initialize_rev_specific_pins(); - - HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0); - HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); } #if PCBA_PRIMARY_REVISION == 'b' || PCBA_PRIMARY_REVISION == 'a' @@ -366,31 +345,15 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { // disable both left and right enable pins HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_RESET); - } else if (GPIO_Pin == GPIO_PIN_13) { - if (diag0_z_callback != NULL) { - if (*diag0_z_callback != NULL) { - (*diag0_z_callback)(); - } - } - } else if (GPIO_Pin == GPIO_PIN_15) { - if (diag0_a_callback != NULL) { - if (*diag0_a_callback != NULL) { - (*diag0_a_callback)(); - } - } } } void initialize_timer(motor_interrupt_callback callback, encoder_overflow_callback l_f_callback, - encoder_overflow_callback r_f_callback, - diag0_interrupt_callback* diag0_z_int_callback, - diag0_interrupt_callback* diag0_a_int_callback) { + encoder_overflow_callback r_f_callback) { motor_callback = callback; left_enc_overflow_callback = l_f_callback; right_enc_overflow_callback = r_f_callback; - diag0_z_callback = diag0_z_int_callback; - diag0_a_callback = diag0_a_int_callback; MX_GPIO_Init(); Encoder_GPIO_Init(); encoder_init(&htim2); diff --git a/head/firmware/stm32g4xx_it.c b/head/firmware/stm32g4xx_it.c index 929586b89..6e031a2bf 100644 --- a/head/firmware/stm32g4xx_it.c +++ b/head/firmware/stm32g4xx_it.c @@ -177,14 +177,6 @@ void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); } */ void TIM3_IRQHandler(void) { HAL_TIM_IRQHandler(&htim3); } -void EXTI15_10_IRQHandler(void) { - if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13)) { - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13); - } else if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_15)) { - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15); - } -} - extern void xPortSysTickHandler(void); void SysTick_Handler(void) { HAL_IncTick(); diff --git a/head/simulator/main.cpp b/head/simulator/main.cpp index 907f60bdb..79db8f736 100644 --- a/head/simulator/main.cpp +++ b/head/simulator/main.cpp @@ -94,9 +94,8 @@ 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(), motor_interface_right, + stallcheck_right, update_position_queue_right); static stall_check::StallCheck stallcheck_left( linear_config.get_encoder_pulses_per_mm() / 1000.0F, @@ -118,9 +117,8 @@ 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(), motor_interface_left, + stallcheck_left, update_position_queue_left); static motor_class::Motor motor_left{ motor_sys_config, motor_interface_left, diff --git a/include/can/core/ids.hpp b/include/can/core/ids.hpp index 2c5dd4169..db884f803 100644 --- a/include/can/core/ids.hpp +++ b/include/can/core/ids.hpp @@ -64,8 +64,6 @@ enum class MessageId { write_motor_current_request = 0x33, read_motor_current_request = 0x34, read_motor_current_response = 0x35, - read_motor_driver_error_status_request = 0x36, - read_motor_driver_error_status_response = 0x37, set_brushed_motor_vref_request = 0x40, set_brushed_motor_pwm_request = 0x41, gripper_grip_request = 0x42, @@ -169,12 +167,10 @@ enum class ErrorCode { over_pressure = 0xd, door_open = 0xe, reed_open = 0xf, - motor_driver_error_detected = 0x10, }; /** Error Severity levels. */ enum class ErrorSeverity { - none = 0x0, warning = 0x1, recoverable = 0x2, unrecoverable = 0x3, diff --git a/include/can/core/messages.hpp b/include/can/core/messages.hpp index 2a37a0a85..a60eedc3c 100644 --- a/include/can/core/messages.hpp +++ b/include/can/core/messages.hpp @@ -646,41 +646,6 @@ struct ReadMotorDriverRegisterResponse -> bool = default; }; -struct ReadMotorDriverErrorStatusRequest - : BaseMessage { - uint32_t message_index; - - template - static auto parse(Input body, Limit limit) - -> ReadMotorDriverErrorStatusRequest { - uint32_t msg_ind = 0; - - body = bit_utils::bytes_to_int(body, limit, msg_ind); - return ReadMotorDriverErrorStatusRequest{.message_index = msg_ind}; - } - - auto operator==(const ReadMotorDriverErrorStatusRequest& other) const - -> bool = default; -}; - -struct ReadMotorDriverErrorStatusResponse - : BaseMessage { - uint32_t message_index; - uint8_t reg_address; - uint32_t data; - - template - auto serialize(Output body, Limit limit) const -> uint8_t { - auto iter = bit_utils::int_to_bytes(message_index, body, limit); - iter = bit_utils::int_to_bytes(reg_address, iter, limit); - iter = bit_utils::int_to_bytes(data, iter, limit); - return iter - body; - } - - auto operator==(const ReadMotorDriverErrorStatusResponse& other) const - -> bool = default; -}; - struct WriteMotorCurrentRequest : BaseMessage { uint32_t message_index; @@ -1824,7 +1789,6 @@ using ResponseMessageType = std::variant< UpdateMotorPositionEstimationResponse, BaselineSensorResponse, PushTipPresenceNotification, GetMotorUsageResponse, GripperJawStateResponse, GripperJawHoldoffResponse, HepaUVInfoResponse, GetHepaFanStateResponse, - GetHepaUVStateResponse, MotorStatusResponse, GearMotorStatusResponse, - ReadMotorDriverErrorStatusResponse>; + GetHepaUVStateResponse, MotorStatusResponse, GearMotorStatusResponse>; } // namespace can::messages diff --git a/include/gantry/core/can_task.hpp b/include/gantry/core/can_task.hpp index 53bf495f9..2c4918fff 100644 --- a/include/gantry/core/can_task.hpp +++ b/include/gantry/core/can_task.hpp @@ -21,8 +21,7 @@ using MotorDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::motor::MotorHandler, can::messages::ReadMotorDriverRegister, can::messages::WriteMotorDriverRegister, - can::messages::WriteMotorCurrentRequest, - can::messages::ReadMotorDriverErrorStatusRequest>; + can::messages::WriteMotorCurrentRequest>; using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::move_group::MoveGroupHandler< gantry::queues::QueueClient>, diff --git a/include/gantry/core/interfaces_proto.hpp b/include/gantry/core/interfaces_proto.hpp index ad72967b2..d58ea63fd 100644 --- a/include/gantry/core/interfaces_proto.hpp +++ b/include/gantry/core/interfaces_proto.hpp @@ -9,12 +9,10 @@ namespace interfaces { -extern "C" using diag0_handler = void(*)(); - /** * Initialize the hardware portability layer. */ -void initialize(diag0_handler *call_diag0_handler); +void initialize(); /** * Get the CAN bus interface. diff --git a/include/gantry/core/interfaces_rev1.hpp b/include/gantry/core/interfaces_rev1.hpp index fa276cbff..129d2ac68 100644 --- a/include/gantry/core/interfaces_rev1.hpp +++ b/include/gantry/core/interfaces_rev1.hpp @@ -9,12 +9,10 @@ namespace interfaces { -extern "C" using diag0_handler = void(*)(); - /** * Initialize the hardware portability layer. */ -void initialize(diag0_handler *call_diag0_handler); +void initialize(); /** * Get the CAN bus interface. diff --git a/include/gantry/core/queues.hpp b/include/gantry/core/queues.hpp index 42884aa01..3007e49cb 100644 --- a/include/gantry/core/queues.hpp +++ b/include/gantry/core/queues.hpp @@ -32,8 +32,6 @@ struct QueueClient : can::message_writer::MessageWriter { void send_motor_driver_queue(const tmc::tasks::TaskMessage& m); - void send_motor_driver_queue_isr(const tmc::tasks::TaskMessage& m); - void send_move_group_queue(const move_group_task::TaskMessage& m); void send_move_status_reporter_queue( diff --git a/include/gantry/core/tasks_proto.hpp b/include/gantry/core/tasks_proto.hpp index 8fe6846d4..c9fe5be64 100644 --- a/include/gantry/core/tasks_proto.hpp +++ b/include/gantry/core/tasks_proto.hpp @@ -6,7 +6,6 @@ #include "eeprom/core/hardware_iface.hpp" #include "eeprom/core/task.hpp" #include "eeprom/core/update_data_rev_task.hpp" -#include "gantry/core/interfaces_proto.hpp" #include "i2c/core/hardware_iface.hpp" #include "i2c/core/tasks/i2c_poller_task.hpp" #include "i2c/core/tasks/i2c_task.hpp" @@ -29,17 +28,14 @@ namespace tasks { /** * Start gantry tasks. */ -auto start_tasks( +void start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& motion_controller, spi::hardware::SpiDeviceBase& spi_device, 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; - -void call_run_diag0_interrupt(); + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface); /** * Access to all tasks in the system. diff --git a/include/gantry/core/tasks_rev1.hpp b/include/gantry/core/tasks_rev1.hpp index ea086c412..0a90e559d 100644 --- a/include/gantry/core/tasks_rev1.hpp +++ b/include/gantry/core/tasks_rev1.hpp @@ -6,7 +6,6 @@ #include "eeprom/core/hardware_iface.hpp" #include "eeprom/core/task.hpp" #include "eeprom/core/update_data_rev_task.hpp" -#include "gantry/core/interfaces_rev1.hpp" #include "i2c/core/hardware_iface.hpp" #include "i2c/core/tasks/i2c_poller_task.hpp" #include "i2c/core/tasks/i2c_task.hpp" @@ -29,17 +28,14 @@ namespace tasks { /** * Start gantry tasks. */ -auto start_tasks( +void start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& motion_controller, spi::hardware::SpiDeviceBase& spi_device, 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; - -void call_run_diag0_interrupt(); + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface); /** * Access to all tasks in the system. diff --git a/include/gripper/core/can_task.hpp b/include/gripper/core/can_task.hpp index 91e03acc7..88fd98ca2 100644 --- a/include/gripper/core/can_task.hpp +++ b/include/gripper/core/can_task.hpp @@ -18,8 +18,7 @@ using MotorDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::motor::MotorHandler, can::messages::ReadMotorDriverRegister, can::messages::WriteMotorDriverRegister, - can::messages::WriteMotorCurrentRequest, - can::messages::ReadMotorDriverErrorStatusRequest>; + can::messages::WriteMotorCurrentRequest>; using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::move_group::MoveGroupHandler, can::messages::AddLinearMoveRequest, diff --git a/include/gripper/core/interfaces.hpp b/include/gripper/core/interfaces.hpp index 5430d5801..f11dac6ef 100644 --- a/include/gripper/core/interfaces.hpp +++ b/include/gripper/core/interfaces.hpp @@ -11,9 +11,7 @@ namespace z_motor_iface { -extern "C" using diag0_handler = void(*)(); - -void initialize(diag0_handler *call_diag0_handler); +void initialize(); /** * Access to the z motor. diff --git a/include/gripper/core/tasks.hpp b/include/gripper/core/tasks.hpp index 4f8641442..74d58a7ea 100644 --- a/include/gripper/core/tasks.hpp +++ b/include/gripper/core/tasks.hpp @@ -7,7 +7,6 @@ #include "eeprom/core/hardware_iface.hpp" #include "eeprom/core/task.hpp" #include "eeprom/core/update_data_rev_task.hpp" -#include "gripper/core/interfaces.hpp" #include "i2c/core/hardware_iface.hpp" #include "i2c/core/tasks/i2c_poller_task.hpp" #include "i2c/core/tasks/i2c_task.hpp" @@ -37,7 +36,7 @@ namespace gripper_tasks { /** * Start gripper tasks. */ -auto start_tasks(can::bus::CanBus& can_bus, +void start_tasks(can::bus::CanBus& can_bus, motor_class::Motor& z_motor, brushed_motor::BrushedMotor& grip_motor, spi::hardware::SpiDeviceBase& spi_device, @@ -46,8 +45,7 @@ auto start_tasks(can::bus::CanBus& can_bus, sensors::hardware::SensorHardwareBase& sensor_hardware, eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface, motor_hardware_task::MotorHardwareTask& zmh_tsk, - motor_hardware_task::MotorHardwareTask& gmh_tsk) - -> z_motor_iface::diag0_handler; + motor_hardware_task::MotorHardwareTask& gmh_tsk); /** * Access to all the message queues in the system. @@ -173,15 +171,13 @@ struct AllTask { namespace z_tasks { -auto start_task( +void start_task( motor_class::Motor& z_motor, spi::hardware::SpiDeviceBase& spi_device, tmc2130::configs::TMC2130DriverConfig& driver_configs, AllTask& tasks, gripper_tasks::QueueClient& main_queues, eeprom::dev_data::DevDataTailAccessor& - tail_accessor) -> z_motor_iface::diag0_handler; - -void call_run_diag0_interrupt(); + tail_accessor); struct QueueClient : can::message_writer::MessageWriter { QueueClient(); @@ -191,8 +187,6 @@ struct QueueClient : can::message_writer::MessageWriter { void send_motor_driver_queue(const tmc2130::tasks::TaskMessage& m); - void send_motor_driver_queue_isr(const tmc2130::tasks::TaskMessage& m); - void send_move_group_queue(const move_group_task::TaskMessage& m); void send_move_status_reporter_queue( diff --git a/include/gripper/firmware/utility_gpio.h b/include/gripper/firmware/utility_gpio.h index c0267033a..4cb96d005 100644 --- a/include/gripper/firmware/utility_gpio.h +++ b/include/gripper/firmware/utility_gpio.h @@ -53,7 +53,6 @@ void utility_gpio_init(); // z motor pins #define Z_MOT_DIR_PIN GPIO_PIN_10 #define Z_MOT_STEP_PIN GPIO_PIN_1 -#define Z_MOT_DIAG0_PIN GPIO_PIN_2 #define Z_MOT_STEPDIR_PORT GPIOB #define Z_MOT_ENABLE_PIN GPIO_PIN_9 #define Z_MOT_ENABLE_PORT GPIOA diff --git a/include/gripper/simulation/sim_interfaces.hpp b/include/gripper/simulation/sim_interfaces.hpp index a3750ab63..4de28bad4 100644 --- a/include/gripper/simulation/sim_interfaces.hpp +++ b/include/gripper/simulation/sim_interfaces.hpp @@ -4,8 +4,6 @@ namespace z_motor_iface { -extern "C" using diag0_handler = void(*)(); - auto get_z_motor_interface() -> sim_motor_hardware_iface::SimMotorHardwareIface&; diff --git a/include/head/core/queues.hpp b/include/head/core/queues.hpp index 6a07d9cd1..2552275ff 100644 --- a/include/head/core/queues.hpp +++ b/include/head/core/queues.hpp @@ -55,8 +55,6 @@ struct MotorQueueClient : can::message_writer::MessageWriter { void send_motor_driver_queue(const tmc::tasks::TaskMessage& m); - void send_motor_driver_queue_isr(const tmc::tasks::TaskMessage& m); - void send_move_group_queue(const move_group_task::TaskMessage& m); void send_move_status_reporter_queue( diff --git a/include/head/core/tasks_proto.hpp b/include/head/core/tasks_proto.hpp index 8be17643e..6f87e5286 100644 --- a/include/head/core/tasks_proto.hpp +++ b/include/head/core/tasks_proto.hpp @@ -24,12 +24,11 @@ namespace head_tasks { -extern "C" using diag0_handler = void(*)(); - /** * Start head tasks. */ -auto start_tasks( + +void start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& left_motion_controller, @@ -43,8 +42,7 @@ 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; + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface); /** * Access to all tasks not associated with a motor. This will be a singleton. diff --git a/include/head/core/tasks_rev1.hpp b/include/head/core/tasks_rev1.hpp index 430c89cf4..bbb375586 100644 --- a/include/head/core/tasks_rev1.hpp +++ b/include/head/core/tasks_rev1.hpp @@ -24,12 +24,11 @@ namespace head_tasks { -extern "C" using diag0_handler = void(*)(); - /** * Start head tasks. */ -auto start_tasks( + +void start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& left_motion_controller, @@ -43,8 +42,7 @@ 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; + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface); /** * Access to all tasks not associated with a motor. This will be a singleton. diff --git a/include/motor-control/core/brushed_motor/brushed_motion_controller.hpp b/include/motor-control/core/brushed_motor/brushed_motion_controller.hpp index 113f56214..00ec0dddf 100644 --- a/include/motor-control/core/brushed_motor/brushed_motion_controller.hpp +++ b/include/motor-control/core/brushed_motor/brushed_motion_controller.hpp @@ -101,15 +101,12 @@ class MotionController { enabled = false; } - void stop( - can::ids::ErrorSeverity error_severity = - can::ids::ErrorSeverity::warning, - can::ids::ErrorCode error_code = can::ids::ErrorCode::stop_requested) { + void stop() { queue.reset(); // if we're gripping something we need to flag this so we don't drop it if (!hardware.get_stay_enabled()) { if (hardware.is_timer_interrupt_running()) { - hardware.set_cancel_request(error_severity, error_code); + hardware.request_cancel(); } } } diff --git a/include/motor-control/core/brushed_motor/brushed_motor_interrupt_handler.hpp b/include/motor-control/core/brushed_motor/brushed_motor_interrupt_handler.hpp index 7b5a04c63..1c417adfe 100644 --- a/include/motor-control/core/brushed_motor/brushed_motor_interrupt_handler.hpp +++ b/include/motor-control/core/brushed_motor/brushed_motor_interrupt_handler.hpp @@ -179,7 +179,7 @@ class BrushedMotorInterruptHandler { } else if (in_estop) { // if we've received a stop request during this time we can clear // that flag since there isn't anything running - std::ignore = hardware.get_cancel_request(); + std::ignore = hardware.has_cancel_request(); // return out of error state once the estop is disabled if (!estop_triggered()) { in_estop = false; @@ -196,9 +196,7 @@ class BrushedMotorInterruptHandler { } else if (estop_triggered()) { in_estop = true; cancel_and_clear_moves(can::ids::ErrorCode::estop_detected); - } else if (static_cast( - hardware.get_cancel_request().code) != - can::ids::ErrorCode::ok) { + } else if (hardware.has_cancel_request()) { if (!hardware.get_stay_enabled()) { hardware.set_motor_state(BrushedMotorState::UNHOMED); } diff --git a/include/motor-control/core/motor_hardware_interface.hpp b/include/motor-control/core/motor_hardware_interface.hpp index 647603250..9a979143d 100644 --- a/include/motor-control/core/motor_hardware_interface.hpp +++ b/include/motor-control/core/motor_hardware_interface.hpp @@ -72,11 +72,6 @@ class UsageEEpromConfig { size_t num_keys = 0; }; -struct __attribute__((packed)) CancelRequest { - uint8_t severity; - uint8_t code; -}; - class MotorHardwareIface { public: MotorHardwareIface() = default; @@ -95,7 +90,6 @@ class MotorHardwareIface { virtual void read_limit_switch() = 0; virtual void read_estop_in() = 0; virtual void read_sync_in() = 0; - virtual auto read_tmc_diag0() -> bool = 0; virtual auto get_encoder_pulses() -> int32_t = 0; virtual void reset_encoder_pulses() = 0; virtual void start_timer_interrupt() = 0; @@ -104,10 +98,8 @@ class MotorHardwareIface { virtual void enable_encoder() = 0; virtual void disable_encoder() = 0; - virtual auto get_cancel_request() -> CancelRequest = 0; - virtual void set_cancel_request(can::ids::ErrorSeverity error_severity, - can::ids::ErrorCode error_code) = 0; - virtual void clear_cancel_request() = 0; + virtual auto has_cancel_request() -> bool = 0; + virtual void request_cancel() = 0; virtual auto get_usage_eeprom_config() -> const UsageEEpromConfig& = 0; // This variable can remain public because the only public methods diff --git a/include/motor-control/core/stepper_motor/motion_controller.hpp b/include/motor-control/core/stepper_motor/motion_controller.hpp index fe356fa6d..dd12d9ac2 100644 --- a/include/motor-control/core/stepper_motor/motion_controller.hpp +++ b/include/motor-control/core/stepper_motor/motion_controller.hpp @@ -178,22 +178,13 @@ class MotionController { return update_queue.try_write(can_msg); } - void stop( - can::ids::ErrorSeverity error_severity = - can::ids::ErrorSeverity::warning, - can::ids::ErrorCode error_code = can::ids::ErrorCode::stop_requested) { + void stop() { queue.reset(); if (hardware.is_timer_interrupt_running()) { - hardware.set_cancel_request(error_severity, error_code); + hardware.request_cancel(); } } - void clear_cancel_request() { hardware.clear_cancel_request(); } - - auto is_timer_interrupt_running() -> bool { - return hardware.is_timer_interrupt_running(); - } - auto read_limit_switch() -> bool { return hardware.check_limit_switch(); } [[nodiscard]] auto read_motor_position() const { @@ -208,8 +199,6 @@ class MotionController { auto check_read_sync_line() -> bool { return hardware.check_sync_in(); } - auto read_tmc_diag0() -> bool { return hardware.read_tmc_diag0(); } - void enable_motor() { hardware.start_timer_interrupt(); hardware.activate_motor(); @@ -343,31 +332,20 @@ class PipetteMotionController { return false; } - void stop( - can::ids::ErrorSeverity error_severity = - can::ids::ErrorSeverity::warning, - can::ids::ErrorCode error_code = can::ids::ErrorCode::stop_requested) { + void stop() { queue.reset(); // if the timer interrupt is running, cancel it. if it isn't running, // don't submit a cancel because then the cancel won't be read until // the timer starts the next time. if (hardware.is_timer_interrupt_running()) { - hardware.set_cancel_request(error_severity, error_code); + hardware.request_cancel(); } } - void clear_cancel_request() { hardware.clear_cancel_request(); } - - auto is_timer_interrupt_running() -> bool { - return hardware.is_timer_interrupt_running(); - } - auto read_limit_switch() -> bool { return hardware.check_limit_switch(); } auto check_read_sync_line() -> bool { return hardware.check_sync_in(); } - auto read_tmc_diag0() -> bool { return hardware.read_tmc_diag0(); } - void enable_motor() { hardware.start_timer_interrupt(); hardware.activate_motor(); diff --git a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp index 61fce36d2..adb52f9a7 100644 --- a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp +++ b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp @@ -9,11 +9,9 @@ #include "motor-control/core/motor_messages.hpp" #include "motor-control/core/stall_check.hpp" #include "motor-control/core/tasks/move_status_reporter_task.hpp" -#include "motor-control/core/tasks/tmc_motor_driver_common.hpp" #ifdef USE_PRESSURE_MOVE #include "pipettes/core/sensor_tasks.hpp" #endif - namespace motor_handler { using namespace motor_messages; @@ -46,7 +44,7 @@ using namespace motor_messages; */ template