Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jan 29, 2024
1 parent 162179e commit 7ff6133
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 120 deletions.
9 changes: 5 additions & 4 deletions include/can/core/message_handlers/move_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class MoveGroupHandler {
using MessageType =
std::variant<std::monostate, AddLinearMoveRequest,
ClearAllMoveGroupsRequest, ExecuteMoveGroupRequest,
GetMoveGroupRequest, HomeRequest, StopRequest, AddSensorMoveRequest>;
GetMoveGroupRequest, HomeRequest, StopRequest,
AddSensorMoveRequest>;
#else
using MessageType =
std::variant<std::monostate, AddLinearMoveRequest,
ClearAllMoveGroupsRequest, ExecuteMoveGroupRequest,
GetMoveGroupRequest, HomeRequest, StopRequest>;
std::variant<std::monostate, AddLinearMoveRequest,
ClearAllMoveGroupsRequest, ExecuteMoveGroupRequest,
GetMoveGroupRequest, HomeRequest, StopRequest>;
#endif

MoveGroupHandler(Client &task_client) : task_client{task_client} {}
Expand Down
17 changes: 8 additions & 9 deletions include/can/core/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,21 +1591,20 @@ struct AddSensorMoveRequest : BaseMessage<MessageId::add_sensor_move_request> {
body = bit_utils::bytes_to_int(body, limit, request_stop_condition);
body = bit_utils::bytes_to_int(body, limit, sensor_id);
return AddSensorMoveRequest{
.message_index = msg_ind,
.group_id = group_id,
.seq_id = seq_id,
.duration = duration,
.acceleration = acceleration,
.velocity = velocity,
.request_stop_condition = request_stop_condition,
.sensor_id = static_cast<can::ids::SensorId>(sensor_id),
.message_index = msg_ind,
.group_id = group_id,
.seq_id = seq_id,
.duration = duration,
.acceleration = acceleration,
.velocity = velocity,
.request_stop_condition = request_stop_condition,
.sensor_id = static_cast<can::ids::SensorId>(sensor_id),
};
}

auto operator==(const AddSensorMoveRequest& other) const -> bool = default;
};


/**
* A variant of all message types we might send..
*/
Expand Down
20 changes: 10 additions & 10 deletions include/motor-control/core/motor_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ struct Move { // NOLINT(cppcoreguidelines-pro-type-member-init)
};

struct SensorSyncMove // NOLINT(cppcoreguidelines-pro-type-member-init)
: public Move {
: public Move {
can::ids::SensorId sensor_id;

auto build_ack(int32_t pulses, uint8_t flags, AckMessageId _id) -> Ack {
return Ack{
.message_index = message_index,
.group_id = group_id,
.seq_id = seq_id,
.current_position_steps = 0,
.encoder_position = pulses,
.position_flags = flags,
.ack_id = _id,
.start_encoder_position = start_encoder_position,
.usage_key = usage_key,
.message_index = message_index,
.group_id = group_id,
.seq_id = seq_id,
.current_position_steps = 0,
.encoder_position = pulses,
.position_flags = flags,
.ack_id = _id,
.start_encoder_position = start_encoder_position,
.usage_key = usage_key,
};
}
};
Expand Down
24 changes: 12 additions & 12 deletions include/motor-control/core/stepper_motor/motion_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ class MotionController {

void move(const can::messages::AddSensorMoveRequest& can_msg) {
steps_per_tick velocity_steps =
fixed_point_multiply(steps_per_mm, can_msg.velocity);
fixed_point_multiply(steps_per_mm, can_msg.velocity);
steps_per_tick_sq acceleration_steps =
fixed_point_multiply(steps_per_um, can_msg.acceleration);
fixed_point_multiply(steps_per_um, can_msg.acceleration);
SensorSyncMove msg{
can_msg.message_index,
can_msg.duration,
velocity_steps,
acceleration_steps,
can_msg.group_id,
can_msg.seq_id,
can_msg.request_stop_condition,
0,
hardware.get_usage_eeprom_config().get_distance_key(),
can_msg.sensor_id};
can_msg.message_index,
can_msg.duration,
velocity_steps,
acceleration_steps,
can_msg.group_id,
can_msg.seq_id,
can_msg.request_stop_condition,
0,
hardware.get_usage_eeprom_config().get_distance_key(),
can_msg.sensor_id};
if (!enabled) {
enable_motor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,26 +594,26 @@ class MotorInterruptHandler {
return has_active_move() && buffered_move.velocity != 0;
}

protected:
void update_hardware_step_tracker() {
hardware.set_step_tracker(
static_cast<uint32_t>(position_tracker >> 31));
}

uint64_t tick_count = 0x0;
static constexpr const q31_31 tick_flag = 0x80000000;
static constexpr const uint64_t overflow_flag = 0x8000000000000000;
// Tracks position with sub-microstep accuracy
q31_31 position_tracker{0};
MoveQueue& move_queue;
StatusClient& status_queue_client;
MotorHardware& hardware;
stall_check::StallCheck& stall_checker;
UpdatePositionQueue& update_position_queue;
MotorMoveMessage buffered_move = MotorMoveMessage{};
bool clear_queue_until_empty = false;
bool stall_handled = false;
bool in_estop = false;
std::atomic_bool _has_active_move = false;
protected:
void update_hardware_step_tracker() {
hardware.set_step_tracker(
static_cast<uint32_t>(position_tracker >> 31));
}

uint64_t tick_count = 0x0;
static constexpr const q31_31 tick_flag = 0x80000000;
static constexpr const uint64_t overflow_flag = 0x8000000000000000;
// Tracks position with sub-microstep accuracy
q31_31 position_tracker{0};
MoveQueue& move_queue;
StatusClient& status_queue_client;
MotorHardware& hardware;
stall_check::StallCheck& stall_checker;
UpdatePositionQueue& update_position_queue;
MotorMoveMessage buffered_move = MotorMoveMessage{};
bool clear_queue_until_empty = false;
bool stall_handled = false;
bool in_estop = false;
std::atomic_bool _has_active_move = false;
};
} // namespace motor_handler
32 changes: 16 additions & 16 deletions include/motor-control/core/tasks/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ using MoveGroupTaskMessage =
can::messages::ClearAllMoveGroupsRequest,
can::messages::ExecuteMoveGroupRequest,
can::messages::GetMoveGroupRequest, can::messages::HomeRequest,
can::messages::StopRequest, can::messages::AddSensorMoveRequest>;
can::messages::StopRequest,
can::messages::AddSensorMoveRequest>;
#else
using MotionControlTaskMessage = std::variant<
std::monostate, can::messages::AddLinearMoveRequest,
can::messages::DisableMotorRequest, can::messages::EnableMotorRequest,
can::messages::GetMotionConstraintsRequest,
can::messages::SetMotionConstraints, can::messages::StopRequest,
can::messages::MotorPositionRequest, can::messages::ReadLimitSwitchRequest,
can::messages::HomeRequest,
can::messages::UpdateMotorPositionEstimationRequest,
can::messages::GetMotorUsageRequest>;
std::monostate, can::messages::AddLinearMoveRequest,
can::messages::DisableMotorRequest, can::messages::EnableMotorRequest,
can::messages::GetMotionConstraintsRequest,
can::messages::SetMotionConstraints, can::messages::StopRequest,
can::messages::MotorPositionRequest, can::messages::ReadLimitSwitchRequest,
can::messages::HomeRequest,
can::messages::UpdateMotorPositionEstimationRequest,
can::messages::GetMotorUsageRequest>;

using MoveGroupTaskMessage =
std::variant<std::monostate, can::messages::AddLinearMoveRequest,
can::messages::ClearAllMoveGroupsRequest,
can::messages::ExecuteMoveGroupRequest,
can::messages::GetMoveGroupRequest, can::messages::HomeRequest,
can::messages::StopRequest>;
using MoveGroupTaskMessage =
std::variant<std::monostate, can::messages::AddLinearMoveRequest,
can::messages::ClearAllMoveGroupsRequest,
can::messages::ExecuteMoveGroupRequest,
can::messages::GetMoveGroupRequest, can::messages::HomeRequest,
can::messages::StopRequest>;
#endif


using MotorDriverTaskMessage =
std::variant<std::monostate, can::messages::ReadMotorDriverRegister,
can::messages::WriteMotorDriverRegister,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ class MotionControllerMessageHandler {
controller.send_usage_data(m.message_index, usage_client);
}


MotorControllerType& controller;
CanClient& can_client;
UsageClient& usage_client;
Expand Down
12 changes: 5 additions & 7 deletions include/motor-control/core/tasks/move_group_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ namespace move_group_task {
constexpr std::size_t max_groups = 3;
constexpr std::size_t max_moves_per_group = 12;
#ifdef PIPETTE_TYPE_DEFINE
using MoveGroupType = move_group::MoveGroupManager<
max_groups, max_moves_per_group, can::messages::AddLinearMoveRequest,
can::messages::HomeRequest, can::messages::AddSensorMoveRequest>;
#else
using MoveGroupType =
move_group::MoveGroupManager<max_groups, max_moves_per_group,
can::messages::AddLinearMoveRequest,
can::messages::HomeRequest,
can::messages::AddSensorMoveRequest>;
#else
using MoveGroupType =
move_group::MoveGroupManager<max_groups, max_moves_per_group,
can::messages::AddLinearMoveRequest,
can::messages::HomeRequest>;
can::messages::HomeRequest>;
#endif

using TaskMessage = motor_control_task_messages::MoveGroupTaskMessage;
Expand Down
7 changes: 4 additions & 3 deletions include/pipettes/core/dispatch_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget<
can::messages::AddLinearMoveRequest,
can::messages::ClearAllMoveGroupsRequest,
can::messages::ExecuteMoveGroupRequest, can::messages::GetMoveGroupRequest,
can::messages::HomeRequest, can::messages::StopRequest, can::messages::AddSensorMoveRequest>;
can::messages::HomeRequest, can::messages::StopRequest,
can::messages::AddSensorMoveRequest>;
#else
using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget<
using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget<
can::message_handlers::move_group::MoveGroupHandler<
linear_motor_tasks::QueueClient>,
linear_motor_tasks::QueueClient>,
can::messages::AddLinearMoveRequest,
can::messages::ClearAllMoveGroupsRequest,
can::messages::ExecuteMoveGroupRequest, can::messages::GetMoveGroupRequest,
Expand Down
63 changes: 30 additions & 33 deletions include/pipettes/core/motor_interrupt_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ template <template <class> class QueueImpl, class StatusClient,
requires MessageQueue<QueueImpl<MotorMoveMessage>, MotorMoveMessage> &&
std::is_base_of_v<motor_hardware::MotorHardwareIface, MotorHardware>
class PipetteMotorInterruptHandler
: public motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, StatusClient,
MotorMoveMessage, MotorHardware> {
: public motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, StatusClient,
MotorMoveMessage, MotorHardware> {
public:
using MoveQueue = QueueImpl<MotorMoveMessage>;
using UpdatePositionQueue =
Expand All @@ -22,13 +22,13 @@ class PipetteMotorInterruptHandler
MoveQueue& incoming_move_queue, StatusClient& outgoing_queue,
MotorHardware& hardware_iface, stall_check::StallCheck& stall,
UpdatePositionQueue& incoming_update_position_queue,
SensorClient& sensor_queue_client) :
motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, StatusClient,
MotorMoveMessage, MotorHardware>(incoming_move_queue, outgoing_queue, hardware_iface,
stall, incoming_update_position_queue),
sensor_client(sensor_queue_client) {
}
SensorClient& sensor_queue_client)
: motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, StatusClient,
MotorMoveMessage, MotorHardware>(
incoming_move_queue, outgoing_queue, hardware_iface, stall,
incoming_update_position_queue),
sensor_client(sensor_queue_client) {}

~PipetteMotorInterruptHandler() = default;

Expand Down Expand Up @@ -64,83 +64,80 @@ class PipetteMotorInterruptHandler
this->in_estop = true;
} else if (this->hardware.has_cancel_request()) {
this->cancel_and_clear_moves(can::ids::ErrorCode::stop_requested,
can::ids::ErrorSeverity::warning);
can::ids::ErrorSeverity::warning);
} else {
// Normal Move logic
this->run_normal_interrupt();
}
}

void handle_move_type(motor_messages::Move m) {
}
void handle_move_type(motor_messages::Move m) {}

void handle_move_type(motor_messages::SensorSyncMove m) {
auto msg = can::messages::BindSensorOutputRequest{
.message_index = m.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = m.sensor_id,
.binding = can::ids::SensorOutputBinding::report
};
.binding = can::ids::SensorOutputBinding::report};
send_to_pressure_sensor_queue(&msg);
}

void update_move() {
this->_has_active_move = this->move_queue.try_read_isr(&this->buffered_move);
this->_has_active_move =
this->move_queue.try_read_isr(&this->buffered_move);
if (this->_has_active_move) {
handle_move_type(this->buffered_move);
this->hardware.enable_encoder();
this->buffered_move.start_encoder_position =
this->hardware.get_encoder_pulses();
this->hardware.get_encoder_pulses();
}
if (this->set_direction_pin()) {
this->hardware.positive_direction();
} else {
this->hardware.negative_direction();
}
if (this->_has_active_move && this->buffered_move.check_stop_condition(
MoveStopCondition::limit_switch)) {
MoveStopCondition::limit_switch)) {
this->position_tracker = 0x7FFFFFFFFFFFFFFF;
this->update_hardware_step_tracker();
this->hardware.position_flags.clear_flag(
can::ids::MotorPositionFlags::stepper_position_ok);
can::ids::MotorPositionFlags::stepper_position_ok);
this->hardware.position_flags.clear_flag(
can::ids::MotorPositionFlags::encoder_position_ok);
can::ids::MotorPositionFlags::encoder_position_ok);
}
}

void finish_current_move(
AckMessageId ack_msg_id = AckMessageId::complete_without_condition) {
AckMessageId ack_msg_id = AckMessageId::complete_without_condition) {
this->_has_active_move = false;
this->tick_count = 0x0;
this->stall_handled = false;
this->build_and_send_ack(ack_msg_id); // might want to overwrite this func
this->build_and_send_ack(
ack_msg_id); // might want to overwrite this func
(MotorMoveMessage{});
// update the stall check ideal encoder counts based on
// last known location

if (!this->has_move_messages()) {
this->stall_checker.reset_itr_counts(this->hardware.get_step_tracker());
this->stall_checker.reset_itr_counts(
this->hardware.get_step_tracker());
auto& stop_msg = can::messages::BindSensorOutputRequest{
.message_index = this->buffered_move.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = this->buffered_move.sensor_id,
.binding = can::ids::SensorOutputBinding::none
};
.message_index = this->buffered_move.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = this->buffered_move.sensor_id,
.binding = can::ids::SensorOutputBinding::none};
send_to_pressure_sensor_queue(&stop_msg);
}
}

void send_to_pressure_sensor_queue(can::messages::SensorOutputBinding& m) {
if(this->buffered_move.sensor_id == can::ids::SensorId::S1) {
if (this->buffered_move.sensor_id == can::ids::SensorId::S1) {
sensor_client.send_pressure_sensor_queue_front(m);
}
else {
} else {
sensor_client.send_pressure_sensor_queue_rear(m);
}
}



private:
SensorClient& sensor_client;
};
Expand Down
Loading

0 comments on commit 7ff6133

Please sign in to comment.