Skip to content

Commit

Permalink
move enable motor to motion controller task
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Apr 23, 2024
1 parent 32980c4 commit f0473d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class MotionController {
.stay_engaged = can_msg.stay_engaged,
.stop_condition = MoveStopCondition::none,
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

Expand All @@ -66,9 +63,6 @@ class MotionController {
.seq_id = can_msg.seq_id,
.stop_condition = MoveStopCondition::limit_switch,
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

Expand All @@ -84,16 +78,15 @@ class MotionController {
get_mechanical_config().get_encoder_um_per_pulse()),
.stop_condition = MoveStopCondition::encoder_position,
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

void enable_motor() {
hardware.activate_motor();
hardware.start_timer_interrupt();
enabled = true;
if (!enabled) {
hardware.activate_motor();
hardware.start_timer_interrupt();
enabled = true;
}
}

void disable_motor() {
Expand Down
35 changes: 10 additions & 25 deletions include/motor-control/core/stepper_motor/motion_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ class MotionController {
0,
hardware.get_usage_eeprom_config().get_distance_key(),
can_msg.sensor_id};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

Expand All @@ -101,9 +98,6 @@ class MotionController {
.stop_condition = can_msg.request_stop_condition,
.usage_key = hardware.get_usage_eeprom_config().get_distance_key(),
.sensor_id = can::ids::SensorId::UNUSED};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

Expand All @@ -121,9 +115,6 @@ class MotionController {
static_cast<uint8_t>(MoveStopCondition::limit_switch),
.usage_key = hardware.get_usage_eeprom_config().get_distance_key(),
.sensor_id = can::ids::SensorId::UNUSED};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}
#else
Expand All @@ -142,9 +133,6 @@ 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) {
enable_motor();
}
queue.try_write(msg);
}

Expand All @@ -161,9 +149,6 @@ class MotionController {
.stop_condition =
static_cast<uint8_t>(MoveStopCondition::limit_switch),
.usage_key = hardware.get_usage_eeprom_config().get_distance_key()};
if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

Expand Down Expand Up @@ -211,9 +196,11 @@ class MotionController {
auto read_tmc_diag0() -> bool { return hardware.read_tmc_diag0(); }

void enable_motor() {
hardware.start_timer_interrupt();
hardware.activate_motor();
enabled = true;
if (!enabled) {
hardware.start_timer_interrupt();
hardware.activate_motor();
enabled = true;
}
}

void disable_motor() {
Expand Down Expand Up @@ -330,10 +317,6 @@ class PipetteMotionController {
can_msg.action,
gear_motor_id,
can::ids::SensorId::UNUSED};

if (!enabled) {
enable_motor();
}
queue.try_write(msg);
}

Expand Down Expand Up @@ -369,9 +352,11 @@ class PipetteMotionController {
auto read_tmc_diag0() -> bool { return hardware.read_tmc_diag0(); }

void enable_motor() {
hardware.start_timer_interrupt();
hardware.activate_motor();
enabled = true;
if (!enabled) {
hardware.start_timer_interrupt();
hardware.activate_motor();
enabled = true;
}
}

void disable_motor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ class MotionControllerMessageHandler {
}

void handle(const can::messages::AddBrushedLinearMoveRequest& m) {
controller.enable_motor();
controller.move(m);
}

void handle(const can::messages::GripperGripRequest& m) {
controller.enable_motor();
controller.move(m);
}

void handle(const can::messages::GripperHomeRequest& m) {
controller.enable_motor();
controller.move(m);
}

Expand Down
3 changes: 3 additions & 0 deletions include/motor-control/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class MotionControllerMessageHandler {
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.enable_motor();
controller.move(m);
}
}
Expand All @@ -141,6 +142,7 @@ 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.enable_motor();
controller.move(m);
}
#endif
Expand All @@ -158,6 +160,7 @@ class MotionControllerMessageHandler {
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.enable_motor();
controller.move(m);
}
}
Expand Down
1 change: 1 addition & 0 deletions include/pipettes/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class MotionControllerMessageHandler {
.error_code =
can::ids::ErrorCode::motor_driver_error_detected});
} else {
controller.enable_motor();
controller.move(m);
}
}
Expand Down

0 comments on commit f0473d9

Please sign in to comment.