Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(motion-control): handle motor driver errors #716

Merged
merged 75 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
e30658d
Adds interrupt for motor driver. Successfully built gantry firmware
pmoegenburg Aug 29, 2023
885837d
Updated other apps to work with MotionController refactor and new mes…
pmoegenburg Aug 30, 2023
9f90395
messaging with robot-server working
pmoegenburg Sep 19, 2023
2f1d488
working prototype
pmoegenburg Oct 12, 2023
b8afae2
debug update
pmoegenburg Oct 12, 2023
16baac0
clean up
pmoegenburg Oct 12, 2023
d2307be
cleanup and fixed tests
pmoegenburg Oct 19, 2023
f3f224b
test and simulator build changes
pmoegenburg Oct 25, 2023
bd16ea6
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Oct 26, 2023
759eac8
format
pmoegenburg Oct 26, 2023
e8e0cf0
fixed test and lint errors
pmoegenburg Oct 26, 2023
041cded
formatted
pmoegenburg Oct 26, 2023
457da97
fixed lint errors
pmoegenburg Oct 26, 2023
36257fa
PR review fixes part 1
pmoegenburg Oct 28, 2023
bfa0b85
PR review changes part 2
pmoegenburg Nov 1, 2023
352f8c8
lint fixes
pmoegenburg Nov 1, 2023
d2fd44c
PR review changes part 3
pmoegenburg Nov 3, 2023
394ea1d
made comments
pmoegenburg Nov 3, 2023
90c6a50
lint and build fixes
pmoegenburg Nov 3, 2023
514017b
format
pmoegenburg Nov 3, 2023
38bd2b8
PR review changes part 3
pmoegenburg Nov 8, 2023
9267d1c
change for debugging
pmoegenburg Nov 8, 2023
2776462
debugging commit
pmoegenburg Nov 8, 2023
fa94240
cleanup
pmoegenburg Nov 8, 2023
ad9dced
testing updates
pmoegenburg Nov 8, 2023
0d4fde6
testing proposed fix
pmoegenburg Nov 8, 2023
1fcd298
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Nov 13, 2023
0985ced
commit for debug
pmoegenburg Nov 13, 2023
a91c309
debug change
pmoegenburg Nov 13, 2023
c3e3130
debounce for debug
pmoegenburg Nov 13, 2023
3c8cdd4
debounce update
pmoegenburg Nov 13, 2023
f93f13e
fix
pmoegenburg Nov 13, 2023
110b08a
debug fix
pmoegenburg Nov 13, 2023
e1627b2
debug changes
pmoegenburg Nov 14, 2023
daf6e2d
debug update
pmoegenburg Nov 14, 2023
4c85967
debug update
pmoegenburg Nov 14, 2023
33cca88
debug update
pmoegenburg Nov 14, 2023
a1f2ec2
debug change
pmoegenburg Nov 14, 2023
f3bd1d3
debug change
pmoegenburg Nov 14, 2023
41c1560
debug update
pmoegenburg Nov 14, 2023
7d270e1
debug changes
pmoegenburg Nov 14, 2023
c9947fc
debug update
pmoegenburg Nov 15, 2023
60176a3
debug change
pmoegenburg Nov 15, 2023
39aa8ce
debug changes
pmoegenburg Nov 15, 2023
6ae3cde
cleanup
pmoegenburg Nov 15, 2023
2c59dcc
proposed refactor
pmoegenburg Dec 5, 2023
68488ff
format
pmoegenburg Dec 11, 2023
c6d92c7
set up motor driver error surfacing on z-axis board
pmoegenburg Dec 14, 2023
c7af96e
formatted
pmoegenburg Dec 14, 2023
19ace41
updated message naming
pmoegenburg Dec 18, 2023
cd19068
implemented motor driver error surfacing for head board
pmoegenburg Jan 3, 2024
4359c14
added debounce
pmoegenburg Jan 4, 2024
772ff3c
cleaned up logic
pmoegenburg Jan 4, 2024
9652cb5
moved delay
pmoegenburg Jan 16, 2024
ecffbdb
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Jan 16, 2024
3ea1c80
added send_from_isr method
pmoegenburg Jan 24, 2024
11214b0
formatted
pmoegenburg Jan 24, 2024
2b2b89a
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Jan 24, 2024
7a8dbfe
fixed tests and HAL_GPIO_EXTI_Callback
pmoegenburg Jan 25, 2024
c8aa62c
pipette motor driver error surfacing
pmoegenburg Jan 30, 2024
996ad11
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Jan 30, 2024
62a09c8
pipette subsystem fixes
pmoegenburg Jan 30, 2024
62e5825
refactored debounce mechanism, changed existing-error-present message…
pmoegenburg Feb 12, 2024
46aed14
finished pipette subsystem implementation for testing
pmoegenburg Feb 14, 2024
12c37d1
updated overtemp settings for gantry testing
pmoegenburg Feb 15, 2024
629d531
finalized driver configs
pmoegenburg Feb 15, 2024
36af4ba
formatted
pmoegenburg Feb 15, 2024
acc0fc5
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Feb 15, 2024
986661d
PR review comment fixes
pmoegenburg Feb 21, 2024
4aec9d3
removed comments
pmoegenburg Feb 21, 2024
087b4bf
Merge branch 'main' into RET-1025_handle_motor_driver_errors
pmoegenburg Mar 21, 2024
2b75f6f
update pipette motor_interrupt_handler
pmoegenburg Mar 25, 2024
9600858
fixed cross-compile issue
pmoegenburg Mar 25, 2024
c8ac8dc
formatted
pmoegenburg Mar 25, 2024
827a8be
increased build-and-test timeout to 20 min
pmoegenburg Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
build-and-test:
name: Run all tests
runs-on: "ubuntu-20.04"
timeout-minutes: 10
timeout-minutes: 20
steps:
- name: Checkout ot3-firmware repo
uses: actions/checkout@v4
Expand Down
24 changes: 20 additions & 4 deletions gantry/core/tasks_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ static auto eeprom_data_rev_update_builder =
/**
* Start gantry tasks.
*/
void gantry::tasks::start_tasks(
auto gantry::tasks::start_tasks(
can::bus::CanBus& can_bus,
motion_controller::MotionController<lms::BeltConfig>& 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) {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> interfaces::diag0_handler {
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
auto& motion = mc_task_builder.start(5, "motion controller",
motion_controller, ::queues, ::queues);
auto& motion =
mc_task_builder.start(5, "motion controller", motion_controller,
::queues, ::queues, ::queues, ::queues);
auto& tmc2130_driver = motor_driver_task_builder.start(
5, "tmc2130 driver", driver_configs, ::queues, spi_task_client);
auto& move_group =
Expand Down Expand Up @@ -116,6 +118,15 @@ void 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)
Expand All @@ -131,6 +142,11 @@ 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<void>(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);
Expand Down
24 changes: 20 additions & 4 deletions gantry/core/tasks_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ static auto tail_accessor = eeprom::dev_data::DevDataTailAccessor{queues};
/**
* Start gantry ::tasks.
*/
void gantry::tasks::start_tasks(
auto gantry::tasks::start_tasks(
can::bus::CanBus& can_bus,
motion_controller::MotionController<lms::BeltConfig>& 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) {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> interfaces::diag0_handler {
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
auto& motion = mc_task_builder.start(5, "motion controller",
motion_controller, ::queues, ::queues);
auto& motion =
mc_task_builder.start(5, "motion controller", motion_controller,
::queues, ::queues, ::queues, ::queues);
auto& tmc2160_driver = motor_driver_task_builder.start(
5, "tmc2160 driver", driver_configs, ::queues, spi_task_client);
auto& move_group =
Expand Down Expand Up @@ -115,6 +117,15 @@ void 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)
Expand All @@ -130,6 +141,11 @@ 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<void>(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);
Expand Down
37 changes: 25 additions & 12 deletions gantry/firmware/interfaces_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ struct motion_controller::HardwareConfig motor_pins_x {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.port = GPIOC,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET}
};

Expand Down Expand Up @@ -125,15 +131,21 @@ struct motion_controller::HardwareConfig motor_pins_y {
.port = GPIOB,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.port = GPIOC,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET}
};

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

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

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down Expand Up @@ -269,13 +281,14 @@ 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() {
void interfaces::initialize(diag0_handler* call_diag0_handler) {
// Initialize SPI
if (initialize_spi(get_axis_type()) != HAL_OK) {
Error_Handler();
}

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

// Start the can bus
canbus.start(can_bit_timings);
Expand Down
39 changes: 27 additions & 12 deletions gantry/firmware/interfaces_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ struct motion_controller::HardwareConfig motor_pins_x {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.port = GPIOC,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET}
};

Expand Down Expand Up @@ -125,15 +131,21 @@ struct motion_controller::HardwareConfig motor_pins_y {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in = {
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.port = GPIOC,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET}
};

static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
.registers = {.gconfig = {.en_pwm_mode = 0},
.registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand All @@ -159,6 +171,7 @@ 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 =
{
Expand All @@ -172,7 +185,7 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
}};

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

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down Expand Up @@ -295,13 +309,14 @@ 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() {
void interfaces::initialize(diag0_handler* call_diag0_handler) {
// Initialize SPI
if (initialize_spi(get_axis_type()) != HAL_OK) {
Error_Handler();
}

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

// Start the can bus
canbus.start(can_bit_timings);
Expand Down
6 changes: 4 additions & 2 deletions gantry/firmware/main_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#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{};

Expand Down Expand Up @@ -44,11 +46,11 @@ auto main() -> int {

app_update_clear_flags();

interfaces::initialize();
interfaces::initialize(&call_diag0_handler);
i2c_setup(&i2c_handles);
i2c_comms2.set_handle(i2c_handles.i2c2);

gantry::tasks::start_tasks(
call_diag0_handler = 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);
Expand Down
6 changes: 4 additions & 2 deletions gantry/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#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{};

Expand Down Expand Up @@ -44,11 +46,11 @@ auto main() -> int {

app_update_clear_flags();

interfaces::initialize();
interfaces::initialize(&call_diag0_handler);
i2c_setup(&i2c_handles);
i2c_comms2.set_handle(i2c_handles.i2c2);

gantry::tasks::start_tasks(
call_diag0_handler = 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);
Expand Down
Loading
Loading