|
| 1 | +// send_command_module.h |
| 2 | +// Motor command panel — send position/stop commands, hold-to-jog, and |
| 3 | +// multi-axis zero. |
| 4 | +// |
| 5 | +// JogButton implements a hold-to-move pattern: jogPressed fires when the mouse |
| 6 | +// button goes down and triggers a continuous velocity command; jogReleased fires |
| 7 | +// on mouse-up and sends velocity 0 to stop the motor. Standard QPushButton |
| 8 | +// clicked() is not used because it only fires on release. |
| 9 | +// |
| 10 | +// Commands are published to /arm/hmi_log as formatted strings (via log_pub_) |
| 11 | +// so CommandLogModule can display them without any direct coupling between |
| 12 | +// modules. |
| 13 | + |
| 14 | +#pragma once |
| 15 | + |
| 16 | +#include <rover_hmi_core/gui_module.h> |
| 17 | +#include "arm_types.h" |
| 18 | + |
| 19 | +#include <QComboBox> |
| 20 | +#include <QDoubleSpinBox> |
| 21 | +#include <QPushButton> |
| 22 | +#include <QCheckBox> |
| 23 | +#include <QMouseEvent> |
| 24 | +#include <array> |
| 25 | +#include <cmath> |
| 26 | + |
| 27 | +#include "rclcpp/rclcpp.hpp" |
| 28 | +#include "rover_msgs/msg/arm_command.hpp" |
| 29 | +#include "std_msgs/msg/string.hpp" |
| 30 | + |
| 31 | +constexpr int NUM_ZERO_AXES = 6; |
| 32 | + |
| 33 | +class JogButton : public QPushButton { |
| 34 | + Q_OBJECT |
| 35 | +public: |
| 36 | + JogButton(const QString& text, QWidget* parent = nullptr); |
| 37 | +signals: |
| 38 | + void jogPressed(); |
| 39 | + void jogReleased(); |
| 40 | +protected: |
| 41 | + void mousePressEvent(QMouseEvent* e) override; |
| 42 | + void mouseReleaseEvent(QMouseEvent* e) override; |
| 43 | +}; |
| 44 | + |
| 45 | +class SendCommandModule : public rover_hmi_core::GuiModule { |
| 46 | +public: |
| 47 | + std::string name() const override { return "Send Command"; } |
| 48 | + std::string layoutHint() const override { return "right"; } |
| 49 | + QWidget* createWidget(QWidget* parent) override; |
| 50 | + void setNode(rclcpp::Node::SharedPtr node) override; |
| 51 | + void start() override {} |
| 52 | + void stop() override {} |
| 53 | + |
| 54 | +private: |
| 55 | + void sendPosition(int motor_id, double pos, double vel, double max_torque); |
| 56 | + void sendVelocity(int motor_id, double velocity); |
| 57 | + void sendStop(int motor_id); |
| 58 | + void sendStopAll(); |
| 59 | + void sendZero(int motor_id); |
| 60 | + void logCmd(const QString& cmd); |
| 61 | + |
| 62 | + rclcpp::Publisher<rover_msgs::msg::ArmCommand>::SharedPtr cmd_pub_; |
| 63 | + rclcpp::Publisher<std_msgs::msg::String>::SharedPtr log_pub_; |
| 64 | + |
| 65 | + QComboBox* motor_select_ = nullptr; |
| 66 | + QComboBox* cmd_type_ = nullptr; |
| 67 | + QDoubleSpinBox* position_spin_ = nullptr; |
| 68 | + QDoubleSpinBox* velocity_spin_ = nullptr; |
| 69 | + QDoubleSpinBox* torque_spin_ = nullptr; |
| 70 | + QDoubleSpinBox* jog_speed_spin_ = nullptr; |
| 71 | + QCheckBox* pos_enable_ = nullptr; |
| 72 | + QCheckBox* vel_enable_ = nullptr; |
| 73 | + QCheckBox* torque_enable_ = nullptr; |
| 74 | + std::array<QCheckBox*, NUM_ZERO_AXES> zero_checks_{}; |
| 75 | +}; |
0 commit comments