|
| 1 | +#include <QApplication> |
| 2 | +#include <QPushButton> |
| 3 | +#include <QVBoxLayout> |
| 4 | +#include <QDoubleSpinBox> |
| 5 | +#include <QWidget> |
| 6 | +#include <QLabel> |
| 7 | +#include <rclcpp/rclcpp.hpp> |
| 8 | +#include <std_msgs/msg/float64_multi_array.hpp> |
| 9 | + |
| 10 | +class StiffnessGUI : public QWidget { |
| 11 | + Q_OBJECT |
| 12 | + |
| 13 | +public: |
| 14 | + StiffnessGUI(std::shared_ptr<rclcpp::Node> node) : node_(node) { |
| 15 | + publisher_ = node_->create_publisher<std_msgs::msg::Float64MultiArray>("/joint_stiffness_controller/command", 10); |
| 16 | + |
| 17 | + auto *layout = new QVBoxLayout(this); |
| 18 | + |
| 19 | + pos_spin1 = new QDoubleSpinBox(); |
| 20 | + pos_spin2 = new QDoubleSpinBox(); |
| 21 | + stiff_spin1 = new QDoubleSpinBox(); |
| 22 | + stiff_spin2 = new QDoubleSpinBox(); |
| 23 | + |
| 24 | + layout->addWidget(new QLabel("Position Joint 1")); |
| 25 | + layout->addWidget(pos_spin1); |
| 26 | + layout->addWidget(new QLabel("Stiffness Joint 1")); |
| 27 | + layout->addWidget(stiff_spin1); |
| 28 | + layout->addWidget(new QLabel("Position Joint 2")); |
| 29 | + layout->addWidget(pos_spin2); |
| 30 | + layout->addWidget(new QLabel("Stiffness Joint 2")); |
| 31 | + layout->addWidget(stiff_spin2); |
| 32 | + |
| 33 | + auto *send_btn = new QPushButton("Send Command"); |
| 34 | + layout->addWidget(send_btn); |
| 35 | + connect(send_btn, &QPushButton::clicked, this, &StiffnessGUI::send_command); |
| 36 | + } |
| 37 | + |
| 38 | +private slots: |
| 39 | + void send_command() { |
| 40 | + auto msg = std_msgs::msg::Float64MultiArray(); |
| 41 | + msg.data = { |
| 42 | + pos_spin1->value(), pos_spin2->value(), |
| 43 | + stiff_spin1->value(), stiff_spin2->value() |
| 44 | + }; |
| 45 | + publisher_->publish(msg); |
| 46 | + } |
| 47 | + |
| 48 | +private: |
| 49 | + std::shared_ptr<rclcpp::Node> node_; |
| 50 | + rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr publisher_; |
| 51 | + |
| 52 | + QDoubleSpinBox *pos_spin1; |
| 53 | + QDoubleSpinBox *pos_spin2; |
| 54 | + QDoubleSpinBox *stiff_spin1; |
| 55 | + QDoubleSpinBox *stiff_spin2; |
| 56 | +}; |
| 57 | + |
| 58 | +int main(int argc, char **argv) { |
| 59 | + rclcpp::init(argc, argv); |
| 60 | + QApplication app(argc, argv); |
| 61 | + |
| 62 | + auto node = rclcpp::Node::make_shared("stiffness_gui"); |
| 63 | + StiffnessGUI gui(node); |
| 64 | + gui.show(); |
| 65 | + |
| 66 | + std::thread spin_thread([&]() { rclcpp::spin(node); }); |
| 67 | + |
| 68 | + int ret = app.exec(); |
| 69 | + rclcpp::shutdown(); |
| 70 | + spin_thread.join(); |
| 71 | + return ret; |
| 72 | +} |
| 73 | +#include "control_gui.moc" |
0 commit comments