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/gui-plugins/KinematicUnitPlugin/ui_kinematicunitguiplugin.h>
35#include <RobotAPI/interface/units/KinematicUnitInterface.h>
37
38/* Qt headers */
39#include <mutex>
40
41#include <boost/circular_buffer.hpp>
42
43#include <QMainWindow>
44#include <QStyledItemDelegate>
45#include <QToolBar>
46
47#include <VirtualRobot/VirtualRobot.h>
48
51
52#include <Inventor/Qt/SoQt.h>
53#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
54#include <Inventor/nodes/SoEventCallback.h>
55#include <Inventor/nodes/SoNode.h>
56#include <Inventor/nodes/SoSeparator.h>
57#include <Inventor/sensors/SoTimerSensor.h>
58
59namespace armarx
60{
62
63 /*!
64 \class KinematicUnitGuiPlugin
65 \brief This plugin provides a generic widget showing position and velocity of all joints. Optionally a 3d robot model can be visualized.
66 \see KinematicUnitWidget
67 */
69 {
70 Q_OBJECT
71 Q_INTERFACES(ArmarXGuiInterface)
72 Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
73 public:
75
76 QString
77 getPluginName() override
78 {
79 return "KinematicUnitGuiPlugin";
80 }
81 };
82
83 class RangeValueDelegate : public QStyledItemDelegate
84 {
85 void paint(QPainter* painter,
86 const QStyleOptionViewItem& option,
87 const QModelIndex& index) const override;
88 };
89
90 /*!
91 \page RobotAPI-GuiPlugins-KinematicUnitPlugin KinematicUnitPlugin
92
93 \brief This widget shows position and velocity of all joints. Optionally a 3d robot model can be visualized.
94
95 \image html KinematicUnitGUI.png
96 When you add the widget to the Gui, you need to specify the following parameters:
97
98 Parameter Name | Example Value | Required? | Description
99 :---------------- | :-------------: | :-------------- |:--------------------
100 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.
101 Robot nodeset name | Robot | Yes | ?
102 Kinematic unit name - Proxy | Armar3KinematicUnit | Yes | The kinematic unit you wish to observe/control.
103 RobotState Topic Name | RobotState | ? | ?
104
105 This widget allows you to both observe and control a kinematic unit. All joints are listed in
106 the table in the center of the widget. The 3D viewer shows the current state of the robot.
107
108 On the top you can select the joint you wish to control and the control mode. You can control
109 a joint with the slider below.
110 */
112 public ArmarXComponentWidgetControllerTemplate<KinematicUnitWidgetController>
113 // public KinematicUnitListener
114 {
115 Q_OBJECT
116 public:
117 /**
118 * @brief Holds the column index for the joint tabel.
119 * Used to avoid magic numbers.
120 */
136
137 enum Roles
138 {
139 eJointAngleRole = Qt::UserRole + 1,
142 };
143
146
147 // inherited from Component
148 void onInitComponent() override;
149 void onConnectComponent() override;
150 void onDisconnectComponent() override;
151 void onExitComponent() override;
152
153 // inherited of ArmarXWidget
154 static QString
156 {
157 return "RobotControl.KinematicUnitGUI";
158 }
159
160 static QIcon
162 {
163 return QIcon("://icons/kinematic_icon.svg");
164 }
165
166 QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
167 void loadSettings(QSettings* settings) override;
168 void saveSettings(QSettings* settings) override;
169 void configured() override;
170
171 SoNode* getScene() override;
172
174
175 void modelUpdateCB();
176
177 void updateGuiElements();
178
179 // overwrite setMutex, so that we can inform the debugdrawer
180 void setMutex3D(RecursiveMutexPtr const& mutex3D) override;
181
182 QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
183
184 signals:
185
193
194 void onDebugInfoReceived(const DebugInfo& debugInfo);
195
196
197 public slots:
198
199 // KinematicUnit
201
205
206 void selectJoint(int i);
207 void selectJointFromTableWidget(int row, int column);
208 void sliderValueChanged(int i);
209
210 /**
211 * @brief Sets the Slider ui.horizontalSliderKinematicUnitPos to 0 if
212 * this->selectedControlMode is eVelocityControl.
213 */
214 void resetSlider();
216
217 void updateJointAnglesTable(const NameValueMap& reportedJointAngles);
218 void updateJointVelocitiesTable(const NameValueMap& reportedJointVelocities);
219 void updateJointTorquesTable(const NameValueMap& reportedJointTorques);
220 void updateJointCurrentsTable(const NameValueMap& reportedJointCurrents,
221 const NameStatusMap& reportedJointStatuses);
222 void updateMotorTemperaturesTable(const NameValueMap& reportedMotorTemperatures);
223 void updateJointStatusesTable(const NameStatusMap& reportedJointStatuses);
224 void updateControlModesTable(const NameControlModeMap& reportedJointControlModes);
225
227
228 void fetchData();
229
230
231 protected:
232 void connectSlots();
233 void initializeUi(const DebugInfo& debugInfo);
234
235 QString translateStatus(OperationStatus status);
236 QString translateStatus(ErrorStatus status);
237
238 Ui::KinematicUnitGuiPlugin ui;
239
240 // ice proxies
241 KinematicUnitInterfacePrx kinematicUnitInterfacePrx; // send commands to kinematic unit
242
244
245 std::string kinematicUnitFile;
247 std::string kinematicUnitName;
248 //std::string robotStateComponentName;
249 std::string topicName;
250 std::string robotNodeSetName;
251
253 VirtualRobot::RobotNodeSetPtr robotNodeSet;
254 VirtualRobot::RobotNodePtr currentNode;
255
256 VirtualRobot::CoinVisualizationPtr kinematicUnitVisualization;
258 SoSeparator* rootVisu;
259 SoSeparator* robotVisu;
260
261 SoSeparator* debugLayerVisu;
263
264 void updateModel(const NameValueMap& jointAngles);
265
266 void highlightCriticalValues(const NameStatusMap& reportedJointStatuses);
267
268 protected slots:
269
270 void showVisuLayers(bool show);
271 void copyToClipboard();
273
275 void debugInfoReceived(const DebugInfo& debugInfo);
276
277
278 private:
279 std::recursive_mutex mutexNodeSet;
280 // init stuff
281 VirtualRobot::RobotPtr loadRobotFile(std::string fileName);
282 VirtualRobot::CoinVisualizationPtr getCoinVisualization(VirtualRobot::RobotPtr robot);
283 VirtualRobot::RobotNodeSetPtr getRobotNodeSet(VirtualRobot::RobotPtr robot,
284 std::string nodeSetName);
285 bool initGUIComboBox(VirtualRobot::RobotNodeSetPtr robotNodeSet);
286 bool initGUIJointListTable(VirtualRobot::RobotNodeSetPtr robotNodeSet);
287
288 bool enableValueValidator;
289 bool viewerEnabled = true;
290 Ice::Long historyTime;
291 // DatafieldFilterBasePtr jointAnglesUpdateFrequency;
292 armarx::DateTime lastJointAngleUpdateTimestamp;
293 float currentValueMax;
294
295 boost::circular_buffer<NameValueMap> jointCurrentHistory;
296
297 QPointer<QWidget> __widget;
298 QPointer<KinematicUnitConfigDialog> dialog;
299
300 RangeValueDelegate delegate;
301 /**
302 * @brief The zero position of the slider
303 */
304 static const int SLIDER_ZERO_POSITION = 0;
305
306 /**
307 * @brief Returns values in
308 * (-ui.jitterThresholdSpinBox->value(),ui.jitterThresholdSpinBox->value())
309 * as 0. (Other values remain unchanged)
310 * @param value The value with jitter.
311 * @return The value without jitter.
312 */
313 float cutJitter(float value);
314
315 QPointer<QToolBar> customToolbar;
316
317 protected:
318 void runUpdate();
319
321
322 ControlMode getSelectedControlMode() const;
323 void setControlModeRadioButtonGroup(const ControlMode& controlMode);
324 };
325 using FloatVector = ::std::vector<::Ice::Float>;
326 using KinematicUnitGuiPluginPtr = std::shared_ptr<KinematicUnitWidgetController>;
327
328
329} // 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 eVelocityCon...
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
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
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