Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Feb 15, 2024
1 parent 629d531 commit 36af4ba
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 74 deletions.
6 changes: 2 additions & 4 deletions gantry/firmware/interfaces_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ struct motion_controller::HardwareConfig motor_pins_y {
};

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

static tmc2160::configs::TMC2160DriverConfig motor_driver_config_y{
.registers = {.gconfig = {.en_pwm_mode = 0,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand Down
6 changes: 2 additions & 4 deletions head/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,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, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand All @@ -249,8 +248,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, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand Down
1 change: 0 additions & 1 deletion head/firmware/stm32g4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); }
void TIM3_IRQHandler(void) { HAL_TIM_IRQHandler(&htim3); }

void EXTI15_10_IRQHandler(void) {
// make this get/deduce pin! Needs to work for C13/z and C15/a!
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)) {
Expand Down
7 changes: 0 additions & 7 deletions include/can/core/message_handlers/motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ class MotionHandler {
private:
void handle_message(std::monostate &m) { static_cast<void>(m); }

/*
void handle_message(const auto &m) {
motion_client.send_motion_controller_queue(utils::variant_cast(m)); //
try to compile, talk with Seth
}
*/

void handle_message(const auto &m) {
motion_client.send_motion_controller_queue(m);
}
Expand Down
21 changes: 0 additions & 21 deletions include/common/core/message_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,4 @@ struct VariantCat<std::variant<VariantAContents...>,
using type = std::variant<VariantAContents..., VariantBContents...>;
};

/*
template <class... Args>
struct variant_cast_proxy
{
std::variant<Args...> v;
template <class... ToArgs>
operator std::variant<ToArgs...>() const
{
return std::visit([](auto&& arg) -> std::variant<ToArgs...> { return arg
; }, v);
}
};
template <class... Args>
auto variant_cast(const std::variant<Args...>& v) -> variant_cast_proxy<Args...>
{
return {v};
}
*/

}; // namespace utils
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ class MotorInterruptHandler {
cancel_and_clear_moves(can::ids::ErrorCode::estop_detected);
in_estop = true;
} else if (static_cast<can::ids::ErrorCode>(cancel_request.code) !=
can::ids::ErrorCode::ok) { // is this correct? Should be
// zero-initialized. Check,
// confirm!
can::ids::ErrorCode::ok) {
cancel_and_clear_moves(
static_cast<can::ids::ErrorCode>(cancel_request.code),
static_cast<can::ids::ErrorSeverity>(cancel_request.severity));
Expand Down
38 changes: 31 additions & 7 deletions include/motor-control/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ class MotionControllerMessageHandler {
void handle(const can::messages::EnableMotorRequest& m) {
LOG("Received enable motor request");
if (controller.read_tmc_diag0()) {
can_client.send_can_message(can::ids::NodeId::host, can::messages::ErrorMessage{.message_index = m.message_index, .severity = can::ids::ErrorSeverity::unrecoverable, .error_code = can::ids::ErrorCode::motor_driver_error_detected});
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.enable_motor();
can_client.send_can_message(can::ids::NodeId::host,
Expand Down Expand Up @@ -114,7 +120,13 @@ class MotionControllerMessageHandler {
m.velocity, m.acceleration, m.group_id, m.seq_id, m.duration,
m.request_stop_condition);
if (controller.read_tmc_diag0()) {
can_client.send_can_message(can::ids::NodeId::host, can::messages::ErrorMessage{.message_index = m.message_index, .severity = can::ids::ErrorSeverity::unrecoverable, .error_code = can::ids::ErrorCode::motor_driver_error_detected});
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.move(m);
}
Expand All @@ -125,7 +137,13 @@ class MotionControllerMessageHandler {
"groupid=%d, seqid=%d\n",
m.velocity, m.group_id, m.seq_id);
if (controller.read_tmc_diag0()) {
can_client.send_can_message(can::ids::NodeId::host, can::messages::ErrorMessage{.message_index = m.message_index, .severity = can::ids::ErrorSeverity::unrecoverable, .error_code = can::ids::ErrorCode::motor_driver_error_detected});
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.move(m);
}
Expand Down Expand Up @@ -170,7 +188,8 @@ class MotionControllerMessageHandler {
controller.send_usage_data(m.message_index, usage_client);
}

void handle(const motor_control_task_messages::RouteMotorDriverInterrupt& m) {
void handle(
const motor_control_task_messages::RouteMotorDriverInterrupt& m) {
if (m.debounce_count > 9) {
if (controller.read_tmc_diag0()) {
controller.stop(
Expand All @@ -194,12 +213,17 @@ class MotionControllerMessageHandler {
diag0_debounced = false;
} else {
vTaskDelay(pdMS_TO_TICKS(100));
motion_client.send_motion_controller_queue(increment_message_debounce_count(m));
motion_client.send_motion_controller_queue(
increment_message_debounce_count(m));
}
}

auto increment_message_debounce_count(const motor_control_task_messages::RouteMotorDriverInterrupt& m) -> motor_control_task_messages::RouteMotorDriverInterrupt {
return motor_control_task_messages::RouteMotorDriverInterrupt{.message_index = m.message_index, .debounce_count = static_cast<uint8_t>(m.debounce_count + 1)};
auto increment_message_debounce_count(
const motor_control_task_messages::RouteMotorDriverInterrupt& m)
-> motor_control_task_messages::RouteMotorDriverInterrupt {
return motor_control_task_messages::RouteMotorDriverInterrupt{
.message_index = m.message_index,
.debounce_count = static_cast<uint8_t>(m.debounce_count + 1)};
}

MotorControllerType& controller;
Expand Down
2 changes: 1 addition & 1 deletion include/motor-control/tests/mock_motor_driver_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ struct MockMotorDriverClient {
std::vector<tmc::tasks::TaskMessage> messages{};
};

} // namespace test_mocks
} // namespace test_mocks
3 changes: 2 additions & 1 deletion include/pipettes/core/gear_motor_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ auto start_tasks(
can::ids::NodeId id,
interfaces::gear_motor::GearMotorHardwareTasks& gmh_tsks,
eeprom::dev_data::DevDataTailAccessor<sensor_tasks::QueueClient>&
tail_accessor) -> std::tuple<interfaces::diag0_handler, interfaces::diag0_handler>;
tail_accessor)
-> std::tuple<interfaces::diag0_handler, interfaces::diag0_handler>;

void call_run_diag0_interrupt();

Expand Down
44 changes: 33 additions & 11 deletions include/pipettes/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "common/core/logging.h"
#include "motor-control/core/linear_motion_system.hpp"
#include "motor-control/core/stepper_motor/motion_controller.hpp"
#include "motor-control/core/tasks/usage_storage_task.hpp"
#include "motor-control/core/tasks/tmc_motor_driver_common.hpp"
#include "motor-control/core/tasks/usage_storage_task.hpp"
#include "pipettes/core/tasks/messages.hpp"

namespace pipettes {
Expand Down Expand Up @@ -79,7 +79,13 @@ class MotionControllerMessageHandler {
// TODO only toggle the enable pin once since all motors share
// a single enable pin line.
if (controller.read_tmc_diag0()) {
can_client.send_can_message(can::ids::NodeId::host, can::messages::ErrorMessage{.message_index = m.message_index, .severity = can::ids::ErrorSeverity::unrecoverable, .error_code = can::ids::ErrorCode::motor_driver_error_detected});
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.enable_motor();
can_client.send_can_message(can::ids::NodeId::host,
Expand Down Expand Up @@ -124,7 +130,13 @@ class MotionControllerMessageHandler {
"acceleration=%d, groupid=%d, seqid=%d\n",
m.velocity, m.acceleration, m.group_id, m.seq_id);
if (controller.read_tmc_diag0()) {
can_client.send_can_message(can::ids::NodeId::host, can::messages::ErrorMessage{.message_index = m.message_index, .severity = can::ids::ErrorSeverity::unrecoverable, .error_code = can::ids::ErrorCode::motor_driver_error_detected});
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.move(m);
}
Expand All @@ -142,7 +154,8 @@ class MotionControllerMessageHandler {
controller.send_usage_data(m.message_index, usage_client);
}

void handle(const pipettes::task_messages::motor_control_task_messages::RouteMotorDriverInterrupt& m) {
void handle(const pipettes::task_messages::motor_control_task_messages::
RouteMotorDriverInterrupt& m) {
if (m.debounce_count > 9) {
if (controller.read_tmc_diag0()) {
controller.stop(
Expand All @@ -166,12 +179,19 @@ class MotionControllerMessageHandler {
diag0_debounced = false;
} else {
vTaskDelay(pdMS_TO_TICKS(100));
motion_client.send_motion_controller_queue(increment_message_debounce_count(m));
motion_client.send_motion_controller_queue(
increment_message_debounce_count(m));
}
}

auto increment_message_debounce_count(const pipettes::task_messages::motor_control_task_messages::RouteMotorDriverInterrupt& m) -> pipettes::task_messages::motor_control_task_messages::RouteMotorDriverInterrupt {
return pipettes::task_messages::motor_control_task_messages::RouteMotorDriverInterrupt{.message_index = m.message_index, .debounce_count = static_cast<uint8_t>(m.debounce_count + 1)};
auto increment_message_debounce_count(
const pipettes::task_messages::motor_control_task_messages::
RouteMotorDriverInterrupt& m) -> pipettes::task_messages::
motor_control_task_messages::RouteMotorDriverInterrupt {
return pipettes::task_messages::motor_control_task_messages::
RouteMotorDriverInterrupt{
.message_index = m.message_index,
.debounce_count = static_cast<uint8_t>(m.debounce_count + 1)};
}

MotorControllerType& controller;
Expand Down Expand Up @@ -210,8 +230,9 @@ class MotionControllerTask {
controller,
CanClient* can_client, UsageClient* usage_client,
DriverClient* driver_client, MotionClient* motion_client) {
auto handler = MotionControllerMessageHandler{*controller, *can_client,
*usage_client, *driver_client, *motion_client, diag0_debounced};
auto handler = MotionControllerMessageHandler{
*controller, *can_client, *usage_client,
*driver_client, *motion_client, diag0_debounced};
TaskMessage message{};
for (;;) {
if (queue.try_read(&message, queue.max_delay)) {
Expand All @@ -225,8 +246,9 @@ class MotionControllerTask {
void run_diag0_interrupt() {
if (!diag0_debounced) {
static_cast<void>(queue.try_write_isr(
pipettes::task_messages::motor_control_task_messages::RouteMotorDriverInterrupt{
.message_index = 0, .debounce_count = 0}));
pipettes::task_messages::motor_control_task_messages::
RouteMotorDriverInterrupt{.message_index = 0,
.debounce_count = 0}));
diag0_debounced = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/spi/core/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ template <typename RegType>
}
} // namespace utils

} // namespace spi
} // namespace spi
11 changes: 5 additions & 6 deletions pipettes/core/gear_motor_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static auto move_status_task_builder_right = freertos_task::TaskStarter<
static auto left_usage_storage_task_builder =
freertos_task::TaskStarter<256, usage_storage_task::UsageStorageTask>{};


void call_run_diag0_left_interrupt() {
if (gear_motor_tasks::get_left_gear_tasks().motion_controller) {
return gear_motor_tasks::get_left_gear_tasks()
Expand All @@ -60,7 +59,8 @@ auto gear_motor_tasks::start_tasks(
can::ids::NodeId id,
interfaces::gear_motor::GearMotorHardwareTasks& gmh_tsks,
eeprom::dev_data::DevDataTailAccessor<sensor_tasks::QueueClient>&
tail_accessor) -> std::tuple<interfaces::diag0_handler, interfaces::diag0_handler> {
tail_accessor)
-> std::tuple<interfaces::diag0_handler, interfaces::diag0_handler> {
left_queue_client.set_node_id(id);
right_queue_client.set_node_id(id);

Expand All @@ -70,10 +70,9 @@ auto gear_motor_tasks::start_tasks(
auto& right_tasks = gear_motor_tasks::get_right_gear_tasks();

// Left Gear Motor Tasks
auto& motion_left = mc_task_builder_left.start(5, "motion controller",
motion_controllers.left,
left_queues, left_queues,
left_queues, left_queues);
auto& motion_left = mc_task_builder_left.start(
5, "motion controller", motion_controllers.left, left_queues,
left_queues, left_queues, left_queues);
auto& tmc2160_driver_left = tmc2160_driver_task_builder_left.start(
5, "tmc2160 driver", gear_driver_configs.left_gear_motor, left_queues,
spi_writer);
Expand Down
8 changes: 5 additions & 3 deletions pipettes/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ auto initialize_motor_tasks(
*central_tasks::get_tasks().can_writer, linear_motion_control,
peripheral_tasks::get_spi_client(), conf.linear_motor, id, lmh_tsk,
tail_accessor);
std::tie(call_left_gear_diag0_handler, call_right_gear_diag0_handler) = gear_motor_tasks::start_tasks(
*central_tasks::get_tasks().can_writer, gear_motion,
peripheral_tasks::get_spi_client(), conf, id, gmh_tsks, tail_accessor);
std::tie(call_left_gear_diag0_handler, call_right_gear_diag0_handler) =
gear_motor_tasks::start_tasks(*central_tasks::get_tasks().can_writer,
gear_motion,
peripheral_tasks::get_spi_client(), conf,
id, gmh_tsks, tail_accessor);
}
auto initialize_motor_tasks(
can::ids::NodeId id,
Expand Down
6 changes: 2 additions & 4 deletions pipettes/firmware/motor_configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ auto motor_configs::driver_config_by_axis(TMC2160PipetteAxis which)
switch (which) {
case TMC2160PipetteAxis::left_gear_motor:
return tmc2160::configs::TMC2160DriverConfig{
.registers = {.gconfig = {.en_pwm_mode = 1,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand All @@ -39,8 +38,7 @@ auto motor_configs::driver_config_by_axis(TMC2160PipetteAxis which)
}};
case TMC2160PipetteAxis::right_gear_motor:
return tmc2160::configs::TMC2160DriverConfig{
.registers = {.gconfig = {.en_pwm_mode = 1,
.diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand Down

0 comments on commit 36af4ba

Please sign in to comment.