Skip to content

Commit

Permalink
intermediate updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Apr 17, 2024
1 parent f66e7db commit 051bf38
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 132 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cross-compile-special-sensors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
pipettes-single,
pipettes-multi,
pipettes-96,
gripper,
]
fail-fast: false
name: Build ${{ matrix.target }}
Expand Down Expand Up @@ -89,6 +90,7 @@ jobs:
matrix:
target: [
pipettes,
gripper,
]
steps:
- name: Checkout ot3-firmware repo
Expand Down
2 changes: 1 addition & 1 deletion gripper/firmware/interfaces_z_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static motor_class::Motor z_motor{
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gripper_tasks::z_tasks::get_queues(),
gripper_tasks::z_tasks::get_queues(), motor_hardware_iface, stallcheck,
update_position_queue);
update_position_queue, gripper_tasks::get_main_queues()); // use USE_SENSOR_MOVE

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down
2 changes: 1 addition & 1 deletion include/bootloader/core/ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef enum {
can_messageid_peripheral_status_request = 0x8c,
can_messageid_peripheral_status_response = 0x8d,
can_messageid_baseline_sensor_response = 0x8e,
can_messageid_send_accumulated_pressure_data = 0x8f,
can_messageid_send_accumulated_sensor_data = 0x8f,
can_messageid_set_hepa_fan_state_request = 0x90,
can_messageid_get_hepa_fan_state_request = 0x91,
can_messageid_get_hepa_fan_state_response = 0x92,
Expand Down
3 changes: 2 additions & 1 deletion include/can/core/ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ enum class MessageId {
peripheral_status_request = 0x8c,
peripheral_status_response = 0x8d,
baseline_sensor_response = 0x8e,
send_accumulated_pressure_data = 0x8f,
send_accumulated_sensor_data = 0x8f,
set_hepa_fan_state_request = 0x90,
get_hepa_fan_state_request = 0x91,
get_hepa_fan_state_response = 0x92,
Expand Down Expand Up @@ -197,6 +197,7 @@ enum class SensorType {
pressure_temperature = 0x4,
humidity = 0x5,
temperature = 0x6,
UNUSED = 0x7,
};

/** Sensor IDs available.
Expand Down
20 changes: 14 additions & 6 deletions include/can/core/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,24 +786,28 @@ struct FirmwareUpdateStatusResponse
-> bool = default;
};

struct SendAccumulatedPressureDataRequest
: BaseMessage<MessageId::send_accumulated_pressure_data> {
struct SendAccumulatedSensorDataRequest
: BaseMessage<MessageId::send_accumulated_sensor_data> {
uint32_t message_index = 0;
uint8_t sensor_id = 0;
uint8_t sensor_type = 0;

template <bit_utils::ByteIterator Input, typename Limit>
static auto parse(Input body, Limit limit)
-> SendAccumulatedPressureDataRequest {
-> SendAccumulatedSensorDataRequest {
uint32_t msg_ind = 0;
uint8_t sensor_id = 0;
uint8_t sensor_type = 0;

body = bit_utils::bytes_to_int(body, limit, msg_ind);
body = bit_utils::bytes_to_int(body, limit, sensor_id);
return SendAccumulatedPressureDataRequest{.message_index = msg_ind,
.sensor_id = sensor_id};
body = bit_utils::bytes_to_int(body, limit, sensor_type);
return SendAccumulatedSensorDataRequest{.message_index = msg_ind,
.sensor_id = sensor_id,
.sensor_type = sensor_type};
}

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

Expand Down Expand Up @@ -1772,6 +1776,7 @@ struct AddSensorMoveRequest : BaseMessage<MessageId::add_sensor_move_request> {
mm_per_tick velocity;
uint8_t request_stop_condition;
can::ids::SensorId sensor_id{};
can::ids::SensorType sensor_type{};

template <bit_utils::ByteIterator Input, typename Limit>
static auto parse(Input body, Limit limit) -> AddSensorMoveRequest {
Expand All @@ -1783,6 +1788,7 @@ struct AddSensorMoveRequest : BaseMessage<MessageId::add_sensor_move_request> {
uint8_t request_stop_condition = 0;
uint32_t msg_ind = 0;
uint8_t sensor_id = 0;
uint8_t sensor_type = 0;

body = bit_utils::bytes_to_int(body, limit, msg_ind);
body = bit_utils::bytes_to_int(body, limit, group_id);
Expand All @@ -1792,6 +1798,7 @@ struct AddSensorMoveRequest : BaseMessage<MessageId::add_sensor_move_request> {
body = bit_utils::bytes_to_int(body, limit, velocity);
body = bit_utils::bytes_to_int(body, limit, request_stop_condition);
body = bit_utils::bytes_to_int(body, limit, sensor_id);
body = bit_utils::bytes_to_int(body, limit, sensor_type);
return AddSensorMoveRequest{
.message_index = msg_ind,
.group_id = group_id,
Expand All @@ -1801,6 +1808,7 @@ struct AddSensorMoveRequest : BaseMessage<MessageId::add_sensor_move_request> {
.velocity = velocity,
.request_stop_condition = request_stop_condition,
.sensor_id = static_cast<can::ids::SensorId>(sensor_id),
.sensor_type = static_cast<can::ids::SensorType>(sensor_type),
};
}

Expand Down
2 changes: 1 addition & 1 deletion include/gripper/core/can_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using GripperInfoDispatchTarget = can::dispatch::DispatchParseTarget<
using SensorDispatchTarget = can::dispatch::DispatchParseTarget<
sensors::handlers::SensorHandler<gripper_tasks::QueueClient>,
can::messages::TipStatusQueryRequest, can::messages::ReadFromSensorRequest,
can::messages::SendAccumulatedPressureDataRequest,
can::messages::SendAccumulatedSensorDataRequest,
can::messages::WriteToSensorRequest, can::messages::BaselineSensorRequest,
can::messages::SetSensorThresholdRequest,
can::messages::BindSensorOutputRequest,
Expand Down
2 changes: 2 additions & 0 deletions include/motor-control/core/motor_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct SensorSyncMove { // NOLINT(cppcoreguidelines-pro-type-member-init)
int32_t start_encoder_position;
uint16_t usage_key;
can::ids::SensorId sensor_id;
can::ids::SensorType sensor_type;

auto build_ack(uint32_t position, int32_t pulses, uint8_t flags,
AckMessageId _id) -> Ack {
Expand Down Expand Up @@ -119,6 +120,7 @@ struct GearMotorMove // NOLINT(cppcoreguidelines-pro-type-member-init)
can::ids::PipetteTipActionType action;
can::ids::GearMotorId gear_motor_id;
can::ids::SensorId sensor_id;
can::ids::SensorType sensor_type;
auto build_ack(uint32_t position, int32_t pulses, uint8_t flags,
AckMessageId _id) -> GearMotorAck {
return GearMotorAck{message_index, group_id,
Expand Down
12 changes: 8 additions & 4 deletions include/motor-control/core/stepper_motor/motion_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class MotionController {
can_msg.request_stop_condition,
0,
hardware.get_usage_eeprom_config().get_distance_key(),
can_msg.sensor_id};
can_msg.sensor_id,
can_msg.sensor_type};
if (!enabled) {
enable_motor();
}
Expand All @@ -100,7 +101,8 @@ 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(),
.sensor_id = can::ids::SensorId::UNUSED};
.sensor_id = can::ids::SensorId::UNUSED,
.sensor_type = can::ids::SensorType::UNUSED};
if (!enabled) {
enable_motor();
}
Expand All @@ -120,7 +122,8 @@ class MotionController {
.stop_condition =
static_cast<uint8_t>(MoveStopCondition::limit_switch),
.usage_key = hardware.get_usage_eeprom_config().get_distance_key(),
.sensor_id = can::ids::SensorId::UNUSED};
.sensor_id = can::ids::SensorId::UNUSED,
.sensor_type = can::ids::SensorType::UNUSED};
if (!enabled) {
enable_motor();
}
Expand Down Expand Up @@ -329,7 +332,8 @@ class PipetteMotionController {
hardware.get_step_tracker(),
can_msg.action,
gear_motor_id,
can::ids::SensorId::UNUSED};
can::ids::SensorId::UNUSED,
can::ids::SensorType::UNUSED};

if (!enabled) {
enable_motor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include "motor-control/core/stall_check.hpp"
#include "motor-control/core/tasks/move_status_reporter_task.hpp"
#include "motor-control/core/tasks/tmc_motor_driver_common.hpp"
#ifdef USE_SENSOR_MOVE
#include "pipettes/core/sensor_tasks.hpp"
#endif

namespace motor_handler {

Expand Down Expand Up @@ -45,8 +42,28 @@ using namespace motor_messages;
* Note: The position tracker should never be allowed to go below zero.
*/

// take macros up a level to this?
//see tabs
struct Empty {};

template <class SensorClient>
struct SensorAccessHelper {
inline static void send_to_pressure_sensor_queue(SensorClient& sensor_client, can::messages::BindSensorOutputRequest& m) {
sensor_client.send_to_pressure_sensor_queue(m); // handle return type/data. use send_to_isr like previously
}
inline static void send_to_capacitive_sensor_queue(SensorClient& sensor_client, can::messages::BindSensorOutputRequest& m) {
sensor_client.send_to_capacitive_sensor_queue(m);
}
}

template<> struct SensorAccessHelper<Empty> {
inline static void send_to_pressure_sensor_queue(Empty& sensor_client, can::messages::BindSensorOutputRequest& m) {}
inline static void send_to_capacitive_sensor_queue(Empty& sensor_client, can::messages::BindSensorOutputRequest& m) {}
}

template <template <class> class QueueImpl, class StatusClient,
class DriverClient, typename MotorMoveMessage, typename MotorHardware>
class DriverClient, typename MotorMoveMessage, typename MotorHardware,
class SensorClient = Empty>
requires MessageQueue<QueueImpl<MotorMoveMessage>, MotorMoveMessage> &&
std::is_base_of_v<motor_hardware::MotorHardwareIface, MotorHardware>
class MotorInterruptHandler {
Expand All @@ -60,13 +77,15 @@ class MotorInterruptHandler {
DriverClient& driver_queue,
MotorHardware& hardware_iface,
stall_check::StallCheck& stall,
UpdatePositionQueue& incoming_update_position_queue)
UpdatePositionQueue& incoming_update_position_queue,
SensorClient& sensor_queue_client) // make optional, default nullopt
: move_queue(incoming_move_queue),
status_queue_client(outgoing_queue),
driver_client(driver_queue),
hardware(hardware_iface),
stall_checker{stall},
update_position_queue(incoming_update_position_queue) {
update_position_queue(incoming_update_position_queue),
sensor_client(sensor_client) {
hardware.unstep();
}
~MotorInterruptHandler() = default;
Expand Down Expand Up @@ -388,13 +407,23 @@ class MotorInterruptHandler {
hardware.get_encoder_pulses();
#ifdef USE_SENSOR_MOVE
if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) {
auto msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = buffered_move.sensor_id,
.binding = static_cast<uint8_t>(0x3) // sync and report
};
send_to_pressure_sensor_queue(msg);
if (buffered_move.sensor_type == can::ids::SensorType::pressure) {
auto msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = buffered_move.sensor_id,
.binding = static_cast<uint8_t>(0x3) // sync and report
};
send_to_pressure_sensor_queue(msg);
} else if (buffered_move.sensor_type == can::ids::SensorType::capacitive) {
auto msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
.sensor = can::ids::SensorType::capacitive,
.sensor_id = buffered_move.sensor_id,
.binding = static_cast<uint8_t>(0x3) // sync and report
};
send_to_capacitive_sensor_queue(msg);
}
}
#endif
}
Expand Down Expand Up @@ -486,13 +515,23 @@ class MotorInterruptHandler {
build_and_send_ack(ack_msg_id);
#ifdef USE_SENSOR_MOVE
if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) {
auto stop_msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = buffered_move.sensor_id,
.binding =
static_cast<uint8_t>(can::ids::SensorOutputBinding::sync)};
send_to_pressure_sensor_queue(stop_msg);
if (buffered_move.sensor_type == can::ids::SensorType::pressure) {
auto stop_msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = buffered_move.sensor_id,
.binding =
static_cast<uint8_t>(can::ids::SensorOutputBinding::sync)};
send_to_pressure_sensor_queue(stop_msg);
} else if (buffered_move.sensor_type == can::ids::SensorType::pressure) {
auto stop_msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
.sensor = can::ids::SensorType::capacitive,
.sensor_id = buffered_move.sensor_id,
.binding =
static_cast<uint8_t>(can::ids::SensorOutputBinding::sync)};
send_to_capacitive_sensor_queue(stop_msg);
}
}
#endif
set_buffered_move(MotorMoveMessage{});
Expand Down Expand Up @@ -640,9 +679,11 @@ class MotorInterruptHandler {
#ifdef USE_SENSOR_MOVE
void send_to_pressure_sensor_queue(
can::messages::BindSensorOutputRequest& m) {
std::ignore = sensor_tasks::get_queues()
.pressure_sensor_queue_rear->try_write_isr(m);
// if (!success) {this->cancel_and_clear_moves();}
SensorClientHelper<SensorClient>::send_to_pressure_sensor_queue(sensor_client, m);
}
void send_to_capacitive_sensor_queue(
can::messages::BindSensorOutputRequest& m) {
SensorClientHelper<SensorClient>::send_to_capacitive_sensor_queue(sensor_client, m);
}
#endif
uint64_t tick_count = 0x0;
Expand All @@ -656,6 +697,7 @@ class MotorInterruptHandler {
MotorHardware& hardware;
stall_check::StallCheck& stall_checker;
UpdatePositionQueue& update_position_queue;
SensorClient& sensor_client;
MotorMoveMessage buffered_move = MotorMoveMessage{};
bool clear_queue_until_empty = false;
bool stall_handled = false;
Expand Down
2 changes: 1 addition & 1 deletion include/pipettes/core/dispatch_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ using SystemDispatchTarget = can::dispatch::DispatchParseTarget<
using SensorDispatchTarget = can::dispatch::DispatchParseTarget<
sensors::handlers::SensorHandler<sensor_tasks::QueueClient>,
can::messages::TipStatusQueryRequest, can::messages::ReadFromSensorRequest,
can::messages::SendAccumulatedPressureDataRequest,
can::messages::SendAccumulatedSensorDataRequest,
can::messages::WriteToSensorRequest, can::messages::BaselineSensorRequest,
can::messages::SetSensorThresholdRequest,
can::messages::BindSensorOutputRequest,
Expand Down
50 changes: 0 additions & 50 deletions include/pipettes/core/motor_interrupt_handler.hpp

This file was deleted.

Loading

0 comments on commit 051bf38

Please sign in to comment.