RobotIKGuiPlugin.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::
17 * @author Philipp Schmidt
18 * @date 2015
19 * @license http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 
22 */
23 
24 #pragma once
25 
26 //Gui
27 #include <RobotComponents/gui-plugins/RobotIKPlugin/ui_RobotIKGuiPlugin.h>
28 
29 //Visualization
31 
32 //ArmarX includes
34 
38 
39 #include <RobotAPI/interface/core/RobotState.h>
41 
42 #include <RobotComponents/interface/components/RobotIK.h>
43 
44 //Qt includes
45 #include <QObject>
46 
47 //VirtualRobot includes
48 #include <VirtualRobot/Robot.h>
49 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
50 
51 //Inventor includes
52 #include <Inventor/manips/SoTransformerManip.h>
53 #include <Inventor/nodes/SoMaterial.h>
54 #include <Inventor/nodes/SoSphere.h>
55 #include <Inventor/sensors/SoTimerSensor.h>
56 
57 namespace armarx
58 {
59 
61  {
62  Q_OBJECT
63  Q_INTERFACES(ArmarXGuiInterface)
64  Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
65  public:
67 
68  QString
69  getPluginName() override
70  {
71  return "RobotIKGuiPlugin";
72  }
73  };
74 
75  /**
76  * \class RobotIKWidget
77  * \page RobotComponents-GuiPlugins-RobotIK "The RobotIK Gui Plugin"
78  *
79  * \brief The RobotIK Gui Plugin can be used for IK computation.
80  *
81  * This gui plugin can be used for Cartesian control of a robot (arm). It connects to the KinemticUnit of the robot
82  * in order to execute the computed configurations via position control.
83  * Via the plugin the kinematic chain of the robot can be specified allowing to move different end effectors with varying subsets of the robot's joints.
84  *
85  *
86  * \image html RobotIKGui_small.png "The RobotIK Gui Plugin is used to move the right end effector of Armar-III."
87  *
88  * Demonstration video of the RobotIK Gui:
89  * \htmlonly
90  * <p align="middle">
91  * <iframe align="center" width="560" height="315" src="https://www.youtube.com/embed/jyPdg5QlcH4?rel=0?ecver=1" frameborder="0" allowfullscreen></iframe>
92  * </p>
93  * \endhtmlonly
94  *
95  *
96  */
97  // * \ingroup RobotAPI-ArmarXGuiPlugins ArmarXGuiPlugins
98 
100  public ArmarXComponentWidgetControllerTemplate<RobotIKWidgetController>
101  {
102  Q_OBJECT
103 
104  public:
106 
108  {
109  }
110 
111  // inherited from Component
112  void onInitComponent() override;
113  void onConnectComponent() override;
114  void onDisconnectComponent() override;
115  void onExitComponent() override;
116 
117  // inherited of ArmarXWidget
118  static QString
120  {
121  return "RobotControl.RobotIK";
122  }
123 
124  QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
125  void loadSettings(QSettings* settings) override;
126  void saveSettings(QSettings* settings) override;
127  void configured() override;
128 
129  public slots:
130  void initWidget();
131  void solveIK();
132  void kinematicChainChanged(const QString& arg1);
133  void caertesianSelectionChanged(const QString& arg1);
134  void autoFollowChanged(bool checked);
135  void resetManip();
136  void updateSolutionDisplay();
137  void showCurrentRobotChanged(bool checked);
138  void showPreviewRobotChanged(bool checked);
139 
140  protected:
142  KinematicUnitInterfacePrx kinematicUnitInterfacePrx;
143  RobotIKInterfacePrx robotIKPrx;
144 
145  Ui::RobotIKGuiPlugin ui;
146 
147  private slots:
148  void on_btnCopyCurrentPoseToClipboard_clicked();
149  void onDisconnect();
150 
151  void updatePreviewRobot();
152  void on_btnSetDesiredPose_clicked();
153  void executeMotion();
154 
155  private:
156  void ikCallbackExecuteMotion(const Ice::AsyncResultPtr& r);
157  void ikCallbackDisplaySolution(const Ice::AsyncResultPtr& r);
158  void connectSlots();
159  std::string robotStateComponentName;
160  std::string kinematicUnitComponentName;
161  std::string robotIKComponentName;
162 
163  QPointer<SimpleConfigDialog> dialog;
164 
166  Ice::StringSeq getIncludePaths() const;
167  VirtualRobot::RobotPtr loadRobot(Ice::StringSeq includePaths);
168 
169  ManipulatorVisualization* visualization;
170 
171  static void manipFinishCallback(void* data, SoDragger* manip);
172  static void manipMovedCallback(void* data, SoDragger* manip);
173 
174  SoTimerSensor* robotUpdateSensor;
175  static void robotUpdateTimerCB(void* data, SoSensor* sensor);
176 
177  SoTimerSensor* textFieldUpdateSensor;
178  static void textFieldUpdateTimerCB(void* data, SoSensor* sensor);
179 
180  SoTimerSensor* autoFollowSensor;
181  static void autoFollowSensorTimerCB(void* data, SoSensor* sensor);
182  bool manipulatorMoved;
183 
184  static void startIKSolving(RobotIKWidgetController* controller);
185  ExtendedIKResult improveCurrentSolution(ExtendedIKResult& solution);
186  VirtualRobot::RobotPtr cartesianControlRobot;
187  ExtendedIKResult getIKSolution() const;
188 
189  CartesianSelection convertOption(std::string option) const;
190 
191  bool startUpCameraPositioningFlag;
192  Mutex solutionMutex;
193  armarx::ExtendedIKResult currentSolution;
194 
195  VirtualRobot::RobotPtr previewRobot;
196  VirtualRobot::CoinVisualizationPtr previewRobotVisualization;
197  VirtualRobot::CoinVisualizationPtr currentRobotVisualization;
198  };
199 
200  using RobotIKGuiPluginPtr = std::shared_ptr<RobotIKWidgetController>;
202 } // namespace armarx
armarx::RobotIKGuiPlugin::RobotIKGuiPlugin
RobotIKGuiPlugin()
Definition: RobotIKGuiPlugin.cpp:59
armarx::RobotIKWidgetController::showPreviewRobotChanged
void showPreviewRobotChanged(bool checked)
Definition: RobotIKGuiPlugin.cpp:418
RemoteRobot.h
armarx::RobotIKWidgetController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: RobotIKGuiPlugin.cpp:221
armarx::RobotIKWidgetController::RobotIKWidgetController
RobotIKWidgetController()
Definition: RobotIKGuiPlugin.cpp:64
armarx::RobotIKWidgetController::initWidget
void initWidget()
Definition: RobotIKGuiPlugin.cpp:261
boost::shared_ptr< VirtualRobot::CoinVisualization >
armarx::RobotIKWidgetController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: RobotIKGuiPlugin.cpp:215
armarx::ArmarXGuiPlugin
Definition: ArmarXGuiPlugin.h:46
armarx::RobotIKWidgetController::showCurrentRobotChanged
void showCurrentRobotChanged(bool checked)
Definition: RobotIKGuiPlugin.cpp:398
ManipulatorVisualization.h
armarx::RobotIKWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: RobotIKGuiPlugin.cpp:245
armarx::RobotIKWidgetController::~RobotIKWidgetController
virtual ~RobotIKWidgetController()
Definition: RobotIKGuiPlugin.h:107
armarx::RobotIKWidgetController::caertesianSelectionChanged
void caertesianSelectionChanged(const QString &arg1)
Definition: RobotIKGuiPlugin.cpp:349
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
SimpleConfigDialog.h
armarx::RobotIKWidgetController::kinematicChainChanged
void kinematicChainChanged(const QString &arg1)
Definition: RobotIKGuiPlugin.cpp:315
ArmarXGuiInterface
The main gui interface.
Definition: ArmarXGuiInterface.h:80
armarx::RobotIKWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: RobotIKGuiPlugin.cpp:236
ArmarXGuiPlugin.h
armarx::RobotIKWidgetController
Definition: RobotIKGuiPlugin.h:99
armarx::RobotIKWidgetController::resetManip
void resetManip()
Definition: RobotIKGuiPlugin.cpp:359
controller
Definition: AddOperation.h:39
ArmarXComponentWidgetController.h
armarx::RobotIKWidgetController::GetWidgetName
static QString GetWidgetName()
Definition: RobotIKGuiPlugin.h:119
CoinVisualizationPtr
boost::shared_ptr< VirtualRobot::CoinVisualization > CoinVisualizationPtr
Definition: ManipulatorVisualization.h:56
armarx::RobotIKWidgetController::robotStateComponentPrx
RobotStateComponentInterfacePrx robotStateComponentPrx
Definition: RobotIKGuiPlugin.h:141
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
armarx::RobotIKWidgetController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: RobotIKGuiPlugin.cpp:253
Synchronization.h
armarx::RobotIKGuiPlugin
Definition: RobotIKGuiPlugin.h:60
armarx::RobotIKGuiPluginPtr
std::shared_ptr< RobotIKWidgetController > RobotIKGuiPluginPtr
Definition: RobotIKGuiPlugin.h:200
option
#define option(type, fn)
armarx::RobotIKWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: RobotIKGuiPlugin.cpp:209
armarx::RobotIKWidgetController::solveIK
void solveIK()
Definition: RobotIKGuiPlugin.cpp:275
armarx::RobotIKWidgetController::robotIKPrx
RobotIKInterfacePrx robotIKPrx
Definition: RobotIKGuiPlugin.h:143
armarx::RobotIKGuiPlugin::getPluginName
QString getPluginName() override
Definition: RobotIKGuiPlugin.h:69
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ManipulatorVisualization
Definition: ManipulatorVisualization.h:55
armarx::RobotIKWidgetController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: RobotIKGuiPlugin.cpp:91
armarx::Mutex
boost::mutex Mutex
Definition: Synchronization.h:149
armarx::RobotIKWidgetController::autoFollowChanged
void autoFollowChanged(bool checked)
Definition: RobotIKGuiPlugin.cpp:833
armarx::RobotIKWidgetController::kinematicUnitInterfacePrx
KinematicUnitInterfacePrx kinematicUnitInterfacePrx
Definition: RobotIKGuiPlugin.h:142
armarx::RobotIKWidgetController::updateSolutionDisplay
void updateSolutionDisplay()
Definition: RobotIKGuiPlugin.cpp:366
armarx::RobotIKWidgetController::ui
Ui::RobotIKGuiPlugin ui
Definition: RobotIKGuiPlugin.h:145
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RobotIKWidgetController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: RobotIKGuiPlugin.cpp:80
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19