KinematicUnitGuiPlugin.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::Component::KinematicUnitGuiPlugin
17* @author Christian Boege <boege at kit dot edu>
18* @copyright 2011 Christian Böge
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21
22*/
23
24#pragma once
25
26/* ArmarX headers */
29
32
34#include <RobotAPI/interface/units/KinematicUnitInterface.h>
36
37/* Qt headers */
38#include <mutex>
39
40#include <boost/circular_buffer.hpp>
41
42#include <QMainWindow>
43#include <QStyledItemDelegate>
44#include <QToolBar>
45
46#include <VirtualRobot/VirtualRobot.h>
47
50
51#include <Inventor/Qt/SoQt.h>
52#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
53#include <Inventor/nodes/SoEventCallback.h>
54#include <Inventor/nodes/SoNode.h>
55#include <Inventor/nodes/SoSeparator.h>
56#include <Inventor/sensors/SoTimerSensor.h>
57
58// C++ includes
59#include <memory>
60
61// ui_KinematicUnitGuiPlugin.h is included by the .cpp, not here: moc textually inlines every
62// #include it can resolve, and parsing the uic-generated header alongside this one
63// makes moc mis-qualify this class as Ui::armarx::*.
64namespace Ui
65{
66 class KinematicUnitGuiPlugin;
67}
68
69namespace armarx
70{
72
73 /*!
74 \class KinematicUnitGuiPlugin
75 \brief This plugin provides a generic widget showing position and velocity of all joints. Optionally a 3d robot model can be visualized.
76 \see KinematicUnitWidget
77 */
79 {
80 Q_OBJECT
81 Q_INTERFACES(ArmarXGuiInterface)
82 Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
83 public:
85
86 QString
87 getPluginName() override
88 {
89 return "KinematicUnitGuiPlugin";
90 }
91 };
92
93 class RangeValueDelegate : public QStyledItemDelegate
94 {
95 void paint(QPainter* painter,
96 const QStyleOptionViewItem& option,
97 const QModelIndex& index) const override;
98 };
99
100 /*!
101 \page RobotAPI-GuiPlugins-KinematicUnitPlugin KinematicUnitPlugin
102
103 \brief This widget shows position and velocity of all joints. Optionally a 3d robot model can be visualized.
104
105 \image html KinematicUnitGUI.png
106 When you add the widget to the Gui, you need to specify the following parameters:
107
108 Parameter Name | Example Value | Required? | Description
109 :---------------- | :-------------: | :-------------- |:--------------------
110 Robot model filepath | $ArmarX_Core/Armar3/data/Armar3/robotmodel/ArmarIII.xml | Yes | The robot model to use. This needs to be the same model the kinematic unit is using.
111 Robot nodeset name | Robot | Yes | ?
112 Kinematic unit name - Proxy | Armar3KinematicUnit | Yes | The kinematic unit you wish to observe/control.
113 RobotState Topic Name | RobotState | ? | ?
114
115 This widget allows you to both observe and control a kinematic unit. All joints are listed in
116 the table in the center of the widget. The 3D viewer shows the current state of the robot.
117
118 On the top you can select the joint you wish to control and the control mode. You can control
119 a joint with the slider below.
120 */
122 public ArmarXComponentWidgetControllerTemplate<KinematicUnitWidgetController>
123 // public KinematicUnitListener
124 {
125 Q_OBJECT
126 public:
127 /**
128 * @brief Holds the column index for the joint tabel.
129 * Used to avoid magic numbers.
130 */
146
147 enum Roles
148 {
149 eJointAngleRole = Qt::UserRole + 1,
152 };
153
156
157 // inherited from Component
158 void onInitComponent() override;
159 void onConnectComponent() override;
160 void onDisconnectComponent() override;
161 void onExitComponent() override;
162
163 // inherited of ArmarXWidget
164 static QString
166 {
167 return "RobotControl.KinematicUnitGUI";
168 }
169
170 static QIcon
172 {
173 return QIcon("://icons/kinematic_icon.svg");
174 }
175
176 QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
177 void loadSettings(QSettings* settings) override;
178 void saveSettings(QSettings* settings) override;
179 void configured() override;
180
181 SoNode* getScene() override;
182
184
185 void modelUpdateCB();
186
187 void updateGuiElements();
188
189 // overwrite setMutex, so that we can inform the debugdrawer
190 void setMutex3D(RecursiveMutexPtr const& mutex3D) override;
191
192 QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
193
194 signals:
195
203
204 void onDebugInfoReceived(const DebugInfo& debugInfo);
205
206 public slots:
207
208 // KinematicUnit
210
214
215 void selectJoint(int i);
216 void selectJointFromTableWidget(int row, int column);
217 void sliderValueChanged(int i);
218
219 /**
220 * @brief Sets the Slider ui->horizontalSliderKinematicUnitPos to 0 if
221 * this->selectedControlMode is eVelocityControl.
222 */
223 void resetSlider();
225
226 void updateJointAnglesTable(const NameValueMap& reportedJointAngles);
227 void updateJointVelocitiesTable(const NameValueMap& reportedJointVelocities);
228 void updateJointTorquesTable(const NameValueMap& reportedJointTorques);
229 void updateJointCurrentsTable(const NameValueMap& reportedJointCurrents,
230 const NameStatusMap& reportedJointStatuses);
231 void updateMotorTemperaturesTable(const NameValueMap& reportedMotorTemperatures);
232 void updateJointStatusesTable(const NameStatusMap& reportedJointStatuses);
233 void updateControlModesTable(const NameControlModeMap& reportedJointControlModes);
234
236
237 void fetchData();
238
239
240 protected:
241 void connectSlots();
242 void initializeUi(const DebugInfo& debugInfo);
243
244 QString translateStatus(OperationStatus status);
245 QString translateStatus(ErrorStatus status);
246
247 std::unique_ptr<Ui::KinematicUnitGuiPlugin> ui;
248
249 // ice proxies
250 KinematicUnitInterfacePrx kinematicUnitInterfacePrx; // send commands to kinematic unit
251
253
254 std::string kinematicUnitFile;
256 std::string kinematicUnitName;
257 //std::string robotStateComponentName;
258 std::string topicName;
259 std::string robotNodeSetName;
260
262 VirtualRobot::RobotNodeSetPtr robotNodeSet;
263 VirtualRobot::RobotNodePtr currentNode;
264
265 VirtualRobot::CoinVisualizationPtr kinematicUnitVisualization;
267 SoSeparator* rootVisu;
268 SoSeparator* robotVisu;
269
270 SoSeparator* debugLayerVisu;
272
273 void updateModel(const NameValueMap& jointAngles);
274
275 void highlightCriticalValues(const NameStatusMap& reportedJointStatuses);
276
277 protected slots:
278
279 void showVisuLayers(bool show);
280 void copyToClipboard();
282
284 void debugInfoReceived(const DebugInfo& debugInfo);
285
286
287 private:
288 std::recursive_mutex mutexNodeSet;
289 // init stuff
290 VirtualRobot::RobotPtr loadRobotFile(std::string fileName);
291 VirtualRobot::CoinVisualizationPtr getCoinVisualization(VirtualRobot::RobotPtr robot);
292 VirtualRobot::RobotNodeSetPtr getRobotNodeSet(VirtualRobot::RobotPtr robot,
293 std::string nodeSetName);
294 bool initGUIComboBox(VirtualRobot::RobotNodeSetPtr robotNodeSet);
295 bool initGUIJointListTable(VirtualRobot::RobotNodeSetPtr robotNodeSet);
296
297 bool enableValueValidator;
298 bool viewerEnabled = true;
299 Ice::Long historyTime;
300 // DatafieldFilterBasePtr jointAnglesUpdateFrequency;
301 armarx::DateTime lastJointAngleUpdateTimestamp;
302 float currentValueMax;
303
304 boost::circular_buffer<NameValueMap> jointCurrentHistory;
305
306 QPointer<QWidget> __widget;
307 QPointer<KinematicUnitConfigDialog> dialog;
308
309 RangeValueDelegate delegate;
310 /**
311 * @brief The zero position of the slider
312 */
313 static const int SLIDER_ZERO_POSITION = 0;
314
315 /**
316 * @brief Returns values in
317 * (-ui->jitterThresholdSpinBox->value(),ui->jitterThresholdSpinBox->value())
318 * as 0. (Other values remain unchanged)
319 * @param value The value with jitter.
320 * @return The value without jitter.
321 */
322 float cutJitter(float value);
323
324 QPointer<QToolBar> customToolbar;
325
326 protected:
327 void runUpdate();
328
330
331 ControlMode getSelectedControlMode() const;
332 void setControlModeRadioButtonGroup(const ControlMode& controlMode);
333 };
334 using FloatVector = ::std::vector<::Ice::Float>;
335 using KinematicUnitGuiPluginPtr = std::shared_ptr<KinematicUnitWidgetController>;
336
337
338} // namespace armarx
uint8_t index
#define option(type, fn)
The main gui interface.
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
std::shared_ptr< std::recursive_mutex > mutex3D
void initializeUi(const DebugInfo &debugInfo)
void highlightCriticalValues(const NameStatusMap &reportedJointStatuses)
void onInitComponent() override
Pure virtual hook for the subclass.
void updateJointTorquesTable(const NameValueMap &reportedJointTorques)
armarx::RunningTask< KinematicUnitWidgetController >::pointer_type updateTask
void updateJointVelocitiesTable(const NameValueMap &reportedJointVelocities)
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void updateModel(const NameValueMap &jointAngles)
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
SoNode * getScene() override
Reimplementing this function and returning a SoNode* will show this SoNode in the 3DViewerWidget,...
void setMutex3D(RecursiveMutexPtr const &mutex3D) override
This mutex is used to protect 3d scene updates. Usually called by the ArmarXGui main window on creati...
armarx::DebugDrawerComponentPtr debugDrawer
void updateJointCurrentsTable(const NameValueMap &reportedJointCurrents, const NameStatusMap &reportedJointStatuses)
QString translateStatus(OperationStatus status)
void updateControlModesTable(const NameControlModeMap &reportedJointControlModes)
VirtualRobot::CoinVisualizationPtr kinematicUnitVisualization
JointTabelColumnIndex
Holds the column index for the joint tabel.
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void setControlModeRadioButtonGroup(const ControlMode &controlMode)
VirtualRobot::RobotNodeSetPtr robotNodeSet
void updateJointStatusesTable(const NameStatusMap &reportedJointStatuses)
void onConnectComponent() override
Pure virtual hook for the subclass.
void updateJointAnglesTable(const NameValueMap &reportedJointAngles)
void resetSlider()
Sets the Slider ui->horizontalSliderKinematicUnitPos to 0 if this->selectedControlMode is eVelocityCo...
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
void onExitComponent() override
Hook for subclass.
void onDebugInfoReceived(const DebugInfo &debugInfo)
KinematicUnitInterfacePrx kinematicUnitInterfacePrx
std::unique_ptr< Ui::KinematicUnitGuiPlugin > ui
void debugInfoReceived(const DebugInfo &debugInfo)
void updateMotorTemperaturesTable(const NameValueMap &reportedMotorTemperatures)
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
Represents a point in time.
Definition DateTime.h:25
ArmarX Headers.
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::std::vector<::Ice::Float > FloatVector
IceInternal::Handle< DebugDrawerComponent > DebugDrawerComponentPtr
std::shared_ptr< KinematicUnitWidgetController > KinematicUnitGuiPluginPtr