robotiq_3f_rviz.cpp
Go to the documentation of this file.
1 # include <rviz/panel.h>
2 #include <ui_panel.h> // generated from "panel.ui" using CMAKE_AUTOMOC
3 #include <ros/ros.h>
4 #include <robotiq_3f_gripper_articulated_msgs/Robotiq3FGripperRobotOutput.h>
5 #include <robotiq_3f_gripper_articulated_msgs/Robotiq3FGripperRobotInput.h>
6 #include <atomic>
7 
8 namespace robotiq_3f_rviz {
9 
11  Q_OBJECT
12 public:
13  Robotiq3FingerPanel(QWidget* parent = nullptr);
14 
15 // slots
16 private slots:
17  // auto-connected slots: on_<object_name>_<signal_name>(<signal parameters>)
18 
19  // buttons
21 
22  void on_button_on_clicked();
23  void on_button_off_clicked();
24 
29 
32 
33  // sliders
34  void on_slider_position_valueChanged(const int value);
35  void on_slider_force_valueChanged(const int value);
36  void on_slider_speed_valueChanged(const int value);
37 
38  void on_check_send_clicked(const bool checked);
39 
40 // typdefs
41 private:
42  typedef robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput RQ3Fout;
43  typedef robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput RQ3Fin;
44 
45 // methods
46 private:
47  void send(); // publish message
48  void auto_send_check(); // check for auto send
49  void set_mode(const uint8_t mode);
50  void set_PRA(const uint8_t PRA);
51  void on_status(const RQ3Fin &status);
52  void set_button_active(QPushButton *button, const bool active);
53 
54 // members
55 private:
56  Ui::Robotiq3FingerForm ui;
57 
61 
62  RQ3Fout command; // current state
63 
64  std::atomic_bool auto_send = ATOMIC_FLAG_INIT;
65 };
66 
68  // setup ROS
69  pub_command = n.advertise<RQ3Fout>("Robotiq3FGripperRobotOutput", 1);
70  sub_status = n.subscribe("Robotiq3FGripperRobotInput", 1, &Robotiq3FingerPanel::on_status, this);
71 
72  // load ui form and auto-connect slots
73  ui.setupUi(this);
74 }
75 
77  send();
78 }
79 
81  command = RQ3Fout();
82  command.rACT = 1;
83  command.rGTO = 1;
84  command.rSPA = 255;
85  command.rFRA = 150;
86  send();
87 }
88 
90  command = RQ3Fout();
91  command.rACT = 0;
92  send();
93 }
94 
96 
98 
100 
102 
104 
106 
108  set_PRA(uint8_t(value));
109 }
110 
112  command.rFRA = uint8_t(value);
113  auto_send_check();
114 
115  // force: 15 + value * 0.175 N (max: 60 N)
116  static constexpr double min_force = 15;
117  static constexpr double delta_force = 0.175;
118  ui.force_value->setNum(int(min_force+value*delta_force));
119 }
120 
122  command.rSPA = uint8_t(value);
123  auto_send_check();
124 
125  // speed: 22 + value * 0.34 mm/s (max: 110 mm/s)
126  static constexpr double min_speed = 22;
127  static constexpr double delta_speed = 0.34;
128  ui.speed_value->setNum(int(min_speed+value*delta_speed));
129 }
130 
132  ui.button_send->setDown(checked);
133  ui.button_send->setDisabled(checked);
134  auto_send = checked;
135 }
136 
138 
140 
142  command.rMOD = mode;
143  auto_send_check();
144 }
145 
147  command.rPRA = PRA;
148  auto_send_check();
149 }
150 
152  set_button_active(ui.button_on, status.gACT==1);
153  set_button_active(ui.button_off, status.gACT==0);
154 
155  set_button_active(ui.button_basic, status.gMOD==0);
156  set_button_active(ui.button_pinch, status.gMOD==1);
157  set_button_active(ui.button_wide, status.gMOD==2);
158  set_button_active(ui.button_scissor, status.gMOD==3);
159 
160  // individual finger position
161  ui.pos_a->setNum(status.gPOA);
162  ui.pos_b->setNum(status.gPOB);
163  ui.pos_c->setNum(status.gPOC);
164  ui.pos_s->setNum(status.gPOS);
165 
166  // individual finger current
167  // current: 0.1 * value mA
168  ui.cur_a->setNum(0.1*status.gCUA);
169  ui.cur_b->setNum(0.1*status.gCUB);
170  ui.cur_c->setNum(0.1*status.gCUC);
171  ui.cur_s->setNum(0.1*status.gCUS);
172 }
173 
174 void Robotiq3FingerPanel::set_button_active(QPushButton *button, const bool active) {
175  const QString style = active ? "QPushButton {color: red;}" : "QPushButton {}";
176  button->setStyleSheet(style);
177 }
178 
179 } // robotiq_3f_rviz
180 
181 #include "robotiq_3f_rviz.moc"
182 
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput RQ3Fin
unsigned char uint8_t
void on_slider_position_valueChanged(const int value)
void set_button_active(QPushButton *button, const bool active)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void on_slider_speed_valueChanged(const int value)
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput RQ3Fout
Panel(QWidget *parent=0)
void on_slider_force_valueChanged(const int value)
Robotiq3FingerPanel(QWidget *parent=nullptr)
void on_status(const RQ3Fin &status)
void on_check_send_clicked(const bool checked)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


robotiq_3f_rviz
Author(s):
autogenerated on Tue Jun 1 2021 02:30:03