Skip to content

Commit

Permalink
feat(pipettes): add acceleration to TipActionRequest message (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jul 27, 2023
1 parent 087c080 commit 4693209
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 12 deletions.
6 changes: 5 additions & 1 deletion include/can/core/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ struct TipActionRequest
mm_per_tick velocity;
can::ids::PipetteTipActionType action;
uint8_t request_stop_condition;
um_per_tick_sq acceleration;

template <bit_utils::ByteIterator Input, typename Limit>
static auto parse(Input body, Limit limit) -> TipActionRequest {
Expand All @@ -1261,6 +1262,7 @@ struct TipActionRequest
mm_per_tick velocity = 0;
uint8_t _action = 0;
uint8_t request_stop_condition = 0;
um_per_tick_sq acceleration = 0;
uint32_t msg_ind = 0;

body = bit_utils::bytes_to_int(body, limit, msg_ind);
Expand All @@ -1270,6 +1272,7 @@ struct TipActionRequest
body = bit_utils::bytes_to_int(body, limit, velocity);
body = bit_utils::bytes_to_int(body, limit, _action);
body = bit_utils::bytes_to_int(body, limit, request_stop_condition);
body = bit_utils::bytes_to_int(body, limit, acceleration);

return TipActionRequest{
.message_index = msg_ind,
Expand All @@ -1278,7 +1281,8 @@ struct TipActionRequest
.duration = duration,
.velocity = velocity,
.action = static_cast<can::ids::PipetteTipActionType>(_action),
.request_stop_condition = request_stop_condition};
.request_stop_condition = request_stop_condition,
.acceleration = acceleration};
}

auto operator==(const TipActionRequest& other) const -> bool = default;
Expand Down
2 changes: 2 additions & 0 deletions include/eeprom/core/update_data_rev_task.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <vector>

#include "common/core/bit_utils.hpp"
#include "eeprom/core/data_rev.hpp"
#include "eeprom/core/dev_data.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/motor-control/core/motor_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct GearMotorAck : public Ack {
uint32_t start_step_position;
can::ids::PipetteTipActionType action;
can::ids::GearMotorId gear_motor_id;
uint8_t position_flags;
};

struct Move { // NOLINT(cppcoreguidelines-pro-type-member-init)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class PipetteMotionController {
hardware(hardware_iface),
motion_constraints(constraints),
queue(queue),
steps_per_um(convert_to_fixed_point_64_bit(
linear_motion_sys_config.get_usteps_per_um(), 31)),
steps_per_mm(convert_to_fixed_point_64_bit(
linear_motion_sys_config.get_usteps_per_mm(), 31)),
um_per_step(convert_to_fixed_point_64_bit(
Expand All @@ -229,11 +231,13 @@ class PipetteMotionController {
void move(const can::messages::TipActionRequest& can_msg) {
steps_per_tick velocity_steps =
fixed_point_multiply(steps_per_mm, can_msg.velocity);
steps_per_tick_sq acceleration_steps =
fixed_point_multiply(steps_per_um, can_msg.acceleration);
GearMotorMove msg{
can_msg.message_index,
can_msg.duration,
velocity_steps,
0,
acceleration_steps,
can_msg.group_id,
can_msg.seq_id,
can_msg.request_stop_condition,
Expand Down Expand Up @@ -317,6 +321,8 @@ class PipetteMotionController {
StepperMotorHardwareIface& hardware;
MotionConstraints motion_constraints;
GenericQueue& queue;

sq31_31 steps_per_um{0};
sq31_31 steps_per_mm{0};
sq31_31 um_per_step{0};
bool enabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class MotorInterruptHandler {
using MoveQueue = QueueImpl<MotorMoveMessage>;
using UpdatePositionQueue =
QueueImpl<can::messages::UpdateMotorPositionEstimationRequest>;

MotorInterruptHandler() = delete;
MotorInterruptHandler(MoveQueue& incoming_move_queue,
StatusClient& outgoing_queue,
Expand Down Expand Up @@ -289,6 +288,7 @@ class MotorInterruptHandler {
auto homing_stopped() -> bool {
if (limit_switch_triggered()) {
position_tracker = 0;
hardware.reset_step_tracker();
finish_current_move(AckMessageId::stopped_by_condition);
return true;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ class MotorInterruptHandler {
* message and update the motor position if such a message exists.
*/
auto handle_update_position_queue() -> void {
can::messages::UpdateMotorPositionEstimationRequest msg;
can::messages::UpdateMotorPositionEstimationRequest msg = {};

if (update_position_queue.try_read_isr(&msg)) {
auto encoder_pulses = hardware.get_encoder_pulses();
Expand Down Expand Up @@ -549,16 +549,16 @@ class MotorInterruptHandler {

/**
* @brief While a move is active, this function should be called to
* check if there is a pending UpdateMotorPositionEstimationRequest and send
* an error message over CAN if such a message exists.
* check if there is a pending UpdateMotorPositionEstimationRequest and
* send an error message over CAN if such a message exists.
*
*/
auto handle_update_position_queue_error() -> void {
if (!update_position_queue.has_message_isr()) {
return;
}

can::messages::UpdateMotorPositionEstimationRequest msg;
can::messages::UpdateMotorPositionEstimationRequest msg = {};
if (update_position_queue.try_read_isr(&msg)) {
auto response = can::messages::ErrorMessage{
.message_index = msg.message_index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MoveStatusMessageHandler {
.seq_id = message.seq_id,
.current_position_um = end_position,
.encoder_position_um = 0,
.position_flags = 0,
.position_flags = message.position_flags,
.ack_id = static_cast<uint8_t>(message.ack_id),
.action = message.action,
// TODO: In a follow-up PR, tip sense reporting will
Expand Down
4 changes: 2 additions & 2 deletions include/pipettes/core/tasks/motion_controller_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class MotionControllerMessageHandler {

void handle(const can::messages::TipActionRequest& m) {
LOG("Motion Controller Received a tip action request: velocity=%d, "
"groupid=%d, seqid=%d\n",
m.velocity, m.group_id, m.seq_id);
"acceleration=%d, groupid=%d, seqid=%d\n",
m.velocity, m.acceleration, m.group_id, m.seq_id);
controller.move(m);
}

Expand Down
2 changes: 1 addition & 1 deletion motor-control/tests/test_limit_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SCENARIO("MoveStopCondition::limit_switch with the limit switch triggered") {
std::get<Ack>(test_objs.reporter.messages.back());
REQUIRE(read_ack.ack_id == AckMessageId::stopped_by_condition);
REQUIRE(read_ack.encoder_position == 50);
REQUIRE(read_ack.current_position_steps == 350);
REQUIRE(read_ack.current_position_steps == 0);
}
THEN(
"the stepper position flag and encoder position flags are "
Expand Down
2 changes: 1 addition & 1 deletion motor-control/tests/test_motor_pulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ TEST_CASE("Finishing a move") {
auto msg = std::get<Ack>(test_objs.reporter.messages[0]);
REQUIRE(msg.group_id == move.group_id);
REQUIRE(msg.seq_id == move.seq_id);
REQUIRE(msg.current_position_steps == 100);
REQUIRE(msg.current_position_steps == 0);
REQUIRE(msg.encoder_position == 200);
REQUIRE(msg.position_flags == 0x0);

Expand Down

0 comments on commit 4693209

Please sign in to comment.