Skip to content

Commit

Permalink
add a compile option to gate the pressure-based move
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Mar 7, 2024
1 parent 5f76e1f commit 8bb65f8
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/can/core/message_handlers/move_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace can::messages;
template <move_group_task::TaskClient Client>
class MoveGroupHandler {
public:
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
using MessageType =
std::variant<std::monostate, AddLinearMoveRequest,
ClearAllMoveGroupsRequest, ExecuteMoveGroupRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <lms::MotorMechanicalConfig MEConfig>
class MotionController {
public:
using GenericQueue =
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
freertos_message_queue::FreeRTOSMessageQueue<SensorSyncMove>;
#else
freertos_message_queue::FreeRTOSMessageQueue<Move>;
Expand Down Expand Up @@ -63,7 +63,7 @@ class MotionController {
-> const lms::LinearMotionSystemConfig<MEConfig>& {
return linear_motion_sys_config;
}
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
void move(const can::messages::AddSensorMoveRequest& can_msg) {
steps_per_tick velocity_steps =
fixed_point_multiply(steps_per_mm, can_msg.velocity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "motor-control/core/motor_messages.hpp"
#include "motor-control/core/stall_check.hpp"
#include "motor-control/core/tasks/move_status_reporter_task.hpp"
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
#include "pipettes/core/sensor_tasks.hpp"
#endif
namespace motor_handler {
Expand Down Expand Up @@ -378,7 +378,7 @@ class MotorInterruptHandler {
hardware.enable_encoder();
buffered_move.start_encoder_position =
hardware.get_encoder_pulses();
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) {
auto msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
Expand Down Expand Up @@ -471,7 +471,7 @@ class MotorInterruptHandler {
tick_count = 0x0;
stall_handled = false;
build_and_send_ack(ack_msg_id);
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) {
auto stop_msg = can::messages::BindSensorOutputRequest{
.message_index = buffered_move.message_index,
Expand Down Expand Up @@ -624,7 +624,7 @@ class MotorInterruptHandler {
hardware.set_step_tracker(
static_cast<uint32_t>(position_tracker >> 31));
}
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
void send_to_pressure_sensor_queue(
can::messages::BindSensorOutputRequest& m) {
std::ignore = sensor_tasks::get_queues()
Expand Down
2 changes: 1 addition & 1 deletion include/motor-control/core/tasks/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace motor_control_task_messages {

#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
using MotionControlTaskMessage = std::variant<
std::monostate, can::messages::AddLinearMoveRequest,
can::messages::DisableMotorRequest, can::messages::EnableMotorRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class MotionControllerMessageHandler {
controller.move(m);
}

#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
void handle(const can::messages::AddSensorMoveRequest& m) {
LOG("Received add linear move request: velocity=%d, acceleration=%d, "
"groupid=%d, seqid=%d, duration=%d, stopcondition=%d",
Expand Down
4 changes: 2 additions & 2 deletions include/motor-control/core/tasks/move_group_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace move_group_task {

constexpr std::size_t max_groups = 3;
constexpr std::size_t max_moves_per_group = 12;
#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
using MoveGroupType = move_group::MoveGroupManager<
max_groups, max_moves_per_group, can::messages::AddLinearMoveRequest,
can::messages::HomeRequest, can::messages::AddSensorMoveRequest>;
Expand Down Expand Up @@ -126,7 +126,7 @@ class MoveGroupMessageHandler {
mc_client.send_motion_controller_queue(m);
}

#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
void visit_move(const can::messages::AddSensorMoveRequest& m) {
mc_client.send_motion_controller_queue(m);
}
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 @@ -39,7 +39,7 @@ using GearMotorDispatchTarget = can::dispatch::DispatchParseTarget<
can::messages::GearWriteMotorDriverRegister,
can::messages::GearWriteMotorCurrentRequest>;

#ifdef PIPETTE_TYPE_DEFINE
#ifdef USE_PRESSURE_MOVE
using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget<
can::message_handlers::move_group::MoveGroupHandler<
linear_motor_tasks::QueueClient>,
Expand Down
6 changes: 5 additions & 1 deletion include/pipettes/core/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
#include "motor-control/core/tasks/motor_hardware_task.hpp"

namespace interfaces {

#ifdef USE_PRESSURE_MOVE
using MoveQueue = freertos_message_queue::FreeRTOSMessageQueue<
motor_messages::SensorSyncMove>;
#else
using MoveQueue =
freertos_message_queue::FreeRTOSMessageQueue<motor_messages::Move>;
#endif
using GearMoveQueue =
freertos_message_queue::FreeRTOSMessageQueue<motor_messages::GearMotorMove>;
using MotionControlType =
Expand Down
7 changes: 7 additions & 0 deletions include/pipettes/firmware/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@

namespace interfaces {

#ifdef USE_PRESSURE_MOVE
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::SensorSyncMove, motor_hardware::MotorHardware>;
#else
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client, motor_messages::Move,
motor_hardware::MotorHardware>;
#endif
template <typename Client>
using GearMotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
Expand Down
19 changes: 15 additions & 4 deletions include/pipettes/firmware/interfaces_g4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@

namespace interfaces {

#ifdef USE_PRESSURE_MOVE
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::SensorSyncMove, motor_hardware::MotorHardware>;
template <typename Client>
using GearMotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::GearMotorMove, motor_hardware::MotorHardware>;
template <typename Client>
using PipetteMotorInterruptHandlerType = pipettes::PipetteMotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::SensorSyncMove, motor_hardware::MotorHardware,
sensor_tasks::QueueClient>;
#else
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client, motor_messages::Move,
motor_hardware::MotorHardware>;
template <typename Client>
using PipetteMotorInterruptHandlerType = pipettes::PipetteMotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client, motor_messages::Move,
motor_hardware::MotorHardware, sensor_tasks::QueueClient>;
#endif
template <typename Client>
using GearMotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::GearMotorMove, motor_hardware::MotorHardware>;

template <PipetteType P>
auto get_interrupt_queues()
Expand Down
14 changes: 13 additions & 1 deletion include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include "sensors/core/sensors.hpp"
#include "sensors/core/utils.hpp"

#if PIPETTE_TYPE_DEFINE == NINETY_SIX_CHANNEL
#ifndef USE_PRESSURE_MOVE
constexpr size_t PRESSURE_SENSOR_BUFFER_SIZE = 0;
#elif PIPETTE_TYPE_DEFINE == NINETY_SIX_CHANNEL
constexpr size_t PRESSURE_SENSOR_BUFFER_SIZE = 1800;
#else
constexpr size_t PRESSURE_SENSOR_BUFFER_SIZE = 3000;
Expand Down Expand Up @@ -367,6 +369,7 @@ class MMR920 {
}

if (echo_this_time) {
#ifdef USE_PRESSURE_MOVE
// send a response with 9999 to make an overload of the buffer
// visible
if (pressure_buffer_index < PRESSURE_SENSOR_BUFFER_SIZE) {
Expand All @@ -380,6 +383,15 @@ class MMR920 {
.severity = can::ids::ErrorSeverity::warning,
.error_code = can::ids::ErrorCode::stop_requested});
}
#else
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ReadFromSensorResponse{
.message_index = m.message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = sensor_id,
.sensor_data = mmr920::reading_to_fixed_point(pressure)});
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions pipettes/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function(target_pipettes_core_common TARGET REVISION)
target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
target_link_libraries(${TARGET} PUBLIC common-core)
target_include_directories(${TARGET} INTERFACE ${CMAKE_SOURCE_DIR}/cpp-utils/include)
if(${USE_PRESSURE_MOVE})
add_compile_definitions(-DUSE_PRESSURE_MOVE)
endif()
endfunction()

function(target_pipettes_core_single TARGET REVISION)
Expand Down
6 changes: 6 additions & 0 deletions pipettes/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ auto linear_motor::get_interrupt_driver(
sim_motor_hardware_iface::SimMotorHardwareIface& hw, MoveQueue& queue,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient>& handler,
UpdatePositionQueue& update_queue)
#ifdef USE_PRESSURE_MOVE
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient, motor_messages::SensorSyncMove,
sim_motor_hardware_iface::SimMotorHardwareIface> {
#else
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient, motor_messages::Move,
sim_motor_hardware_iface::SimMotorHardwareIface> {
#endif
return motor_interrupt_driver::MotorInterruptDriver(queue, handler, hw,
update_queue);
}
Expand Down

0 comments on commit 8bb65f8

Please sign in to comment.