Skip to content

Commit

Permalink
debugging commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Nov 8, 2023
1 parent 9267d1c commit 2776462
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MotionController {
.seq_id = can_msg.seq_id,
.stop_condition = can_msg.request_stop_condition,
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
if (!enabled && !read_tmc_diag0()) {
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
Expand All @@ -92,7 +92,7 @@ class MotionController {
.stop_condition =
static_cast<uint8_t>(MoveStopCondition::limit_switch),
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
if (!enabled && !read_tmc_diag0()) {
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
Expand Down Expand Up @@ -257,7 +257,7 @@ class PipetteMotionController {
can_msg.action,
gear_motor_id};

if (!enabled && !read_tmc_diag0()) {
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
Expand Down
64 changes: 33 additions & 31 deletions include/motor-control/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class MotionControllerMessageHandler {

void handle(const can::messages::EnableMotorRequest& m) {
LOG("Received enable motor request");
if (!controller.read_tmc_diag0()) {
controller.enable_motor();
can_client.send_can_message(can::ids::NodeId::host,
can::messages::ack_from_request(m));
} else {
if (controller.read_tmc_diag0()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::MotorDriverInErrorState{.message_index = 0});
} else {
controller.enable_motor();
can_client.send_can_message(can::ids::NodeId::host,
can::messages::ack_from_request(m));
}
}

Expand Down Expand Up @@ -102,14 +102,26 @@ class MotionControllerMessageHandler {
"groupid=%d, seqid=%d, duration=%d, stopcondition=%d",
m.velocity, m.acceleration, m.group_id, m.seq_id, m.duration,
m.request_stop_condition);
controller.move(m);
if (controller.read_tmc_diag0()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::MotorDriverInErrorState{.message_index = 0});
} else {
controller.move(m);
}
}

void handle(const can::messages::HomeRequest& m) {
LOG("Motion Controller Received home request: velocity=%d, "
"groupid=%d, seqid=%d\n",
m.velocity, m.group_id, m.seq_id);
controller.move(m);
if (controller.read_tmc_diag0()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::MotorDriverInErrorState{.message_index = 0});
} else {
controller.move(m);
}
}

void handle(const can::messages::ReadLimitSwitchRequest& m) {
Expand Down Expand Up @@ -162,41 +174,31 @@ class MotionControllerMessageHandler {
}

void handle(const can::messages::MotorDriverErrorEncountered& m) {
// if (!driver_error_handled()) {
controller.stop(can::ids::ErrorSeverity::unrecoverable,
can::ids::ErrorCode::motor_driver_error_detected);
if (!controller.is_timer_interrupt_running()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
driver_client.send_motor_driver_queue(
can::messages::ReadMotorDriverErrorStatus{
.message_index = m.message_index});
}
// }
controller.stop(can::ids::ErrorSeverity::unrecoverable,
can::ids::ErrorCode::motor_driver_error_detected);
if (!controller.is_timer_interrupt_running()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
driver_client.send_motor_driver_queue(
can::messages::ReadMotorDriverErrorStatus{.message_index =
m.message_index});
}
}

void handle(const can::messages::ResetMotorDriverErrorHandling& m) {
static_cast<void>(m);
driver_error_handled_flag.exchange(false);
controller.clear_cancel_request();
}

auto driver_error_handled() -> bool {
return driver_error_handled_flag.exchange(true);
}

MotorControllerType& controller;
CanClient& can_client;
UsageClient& usage_client;
DriverClient& driver_client;
std::atomic<bool> driver_error_handled_flag =
false; // can get rid of this if indefinite interrupt trigger issue
// gets resolved
};

/**
Expand Down
18 changes: 12 additions & 6 deletions include/pipettes/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ class MotionControllerMessageHandler {
LOG("Received enable motor request");
// TODO only toggle the enable pin once since all motors share
// a single enable pin line.
if (!controller.read_tmc_diag0()) {
controller.enable_motor();
can_client.send_can_message(can::ids::NodeId::host,
can::messages::ack_from_request(m));
} else {
if (controller.read_tmc_diag0()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::MotorDriverInErrorState{.message_index = 0});
} else {
controller.enable_motor();
can_client.send_can_message(can::ids::NodeId::host,
can::messages::ack_from_request(m));
}
}

Expand Down Expand Up @@ -108,7 +108,13 @@ class MotionControllerMessageHandler {
LOG("Motion Controller Received a tip action request: velocity=%d, "
"acceleration=%d, groupid=%d, seqid=%d\n",
m.velocity, m.acceleration, m.group_id, m.seq_id);
controller.move(m);
if (controller.read_tmc_diag0()) {
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::MotorDriverInErrorState{.message_index = 0});
} else {
controller.move(m);
}
}

void handle(const can::messages::ReadLimitSwitchRequest& m) {
Expand Down

0 comments on commit 2776462

Please sign in to comment.