RobotVisualizationController.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 ArmarXGuiPlugins::RobotTrajectoryDesigner::Controllers
17  * @author Timo Birr
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 #ifndef ROBOTVIEWERCONTROLLER_H
23 #define ROBOTVIEWERCONTROLLER_H
24 
25 #include "AbstractController.h"
26 #include "RobotAPI/interface/core/PoseBase.h"
27 #include <Eigen/Eigen>
29 #include <../Visualization/RobotVisualization.h>
30 #include "../Visualization/DesignerTrajectoryPlayer.h"
31 #include "../Model/DesignerTrajectory.h"
32 #include "VirtualRobot/IK/IKSolver.h"
33 #include "../Visualization/CoinRobotViewerAdapter.h"
34 #include "../Visualization/RobotVisualizationWidget.h"
35 #include <Inventor/sensors/SoTimerSensor.h>
36 #include "../Visualization/VisualizationObserver.h"
37 #include "../Environment.h"
38 
39 namespace armarx
40 {
41 
42  /**
43  * @brief The RobotVisualizationController
44  * A Controller to control the visualization of the robot. Hides the concrete visualization Method(Coin,OSG) from the rest of the application.
45  * Provides Methods for adding Visualization of one Robot at a time, waypoints and transitions between waypoints. Supports up to four parallel views.
46  * Informs other Controllers about the Position of the Manipulator, the TCP and the selected waypoint.
47  */
49  {
50  Q_OBJECT
51  friend class RobotVisualization;
52 
53  public:
54  /**
55  * @brief RobotVisualizationController creates a new RobotVisualizationController
56  * @param parent the widget in which th viewer should be placed in
57  */
58  RobotVisualizationController(QWidget* parent);
60 
61  //inherited by abstract controller
62  void onInitComponent() override;
63  void onConnectComponent() override;
64  void onDisconnectComponent() override;
65  void onExitComponent() override;
66 
67  //inherited by VisualizationObserver
68  void refresh() override;
69  void addConnection(std::shared_ptr<RobotVisualizationController> ctr);
70 
71  public slots:
72 
73  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74  /// PARALLEL VIEWS
75  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76  /**
77  * @brief addView adds new RobotViewer
78  */
79  void addView();
80  /**
81  * @brief removeView removes RobotViewer with index
82  * @param index the index of the view to remove
83  */
84  void removeView();
85 
86  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87  /// UPDATING OF VISUALIZATION
88  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89  /**
90  * @brief updateViews Removes the current visualization of all Waypoints and Transitions and replaces them with the visualization of the new Trajectory
91  * @param trajectory the trajectory to display next
92  */
93  void updateViews(DesignerTrajectoryPtr trajectory);
94 
95  /**
96  * @brief robotChanged updates the robot model that is currently visualized
97  * Removes the robot that is visualized prior to this one
98  * @param robot the new Robot to visualize
99  */
101 
102  /**
103  * @brief environmentChanged updates the environment that is currently visualized
104  * @param environment the new environment
105  */
106  void environmentChanged(EnvironmentPtr environment);
107 
108  /**
109  * @brief displayAllWayPoints Enables Visualization and threfore selection of all waypoints of the current Trajectory and not only userWaypoints
110  * @param display
111  */
112  void displayAllWayPoints(bool display);
113 
114  /**
115  * @brief selectedWayPointChanged highlights the waypoint with index and moves the manipulator to its Pose
116  * @param index the index of the waypoint to select next
117  */
118  void selectedWayPointChanged(int index);
119 
120  /**
121  * @brief selectedTransitionChanged highlights the Transition with index
122  * @param index the index of the transition that should be highlighted
123  */
125 
126  void clearView();
127  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128  /// IK CALLBACK METHODS
129  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
130  /**
131  * @brief cartesianSelectionChanged recalculates the configuration of the robot joints to fit the new selection
132  * @param cs the new CartesianSelection
133  */
135 
136  /**
137  * @brief kinematicChainChanged removes all visualization from the previously selected Trajectory and changes the Visualization of the
138  * Manipulator to look like the endeffector of the kinematic chain
139  * @param selectedChain
140  */
141  void kinematicChainChanged(VirtualRobot::RobotNodeSetPtr rns);
142 
143  /**
144  * @brief setIKCallbackEnabled sets whther the robot Model tries to reach the Pose determined by the Manipulator
145  * @param enabled if true the robot follows the manipulator
146  */
147  void setIKCallbackEnabled(bool enabled);
148 
149 
150 
151 
152  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
153  /// CAMERA UPDATING METHODS
154  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155  /**
156  * @brief setCamera Sets the camera of all views to standard Position
157  * sets camera to standard perspective
158  */
159  void setCamera();
160 
161  /**
162  * @brief setCamera sets camera to the Perspective with index perspective in the corresponding enum
163  * @param perspective the selected perspective
164  * 0 - High Angle
165  * 1 - Top
166  * 2 - Front
167  * 3 - Back
168  * 4 - Left
169  * 5 - Right
170  */
171  void setCamera(int perspective);
172  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
173  /// PLAY TRAJECTORY
174  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
175 
176  /**
177  * @brief playTrajectories plays the currently selected trajectory and disables all other visualization features
178  */
179  void playTrajectory();
180  /**
181  * @brief playTrajectories plays all trajectories at the same time
182  * @param trajectories the trajectories to play - no duplicates of selected robot node sets allowed!
183  */
184  void playTrajectories(std::vector<DesignerTrajectoryPtr> trajectories);
185  /**
186  * @brief trajectoryPlayerStopped restarts the visualization of the whole scene after the debug drawer does not longer visualize the trajectory
187  */
189 
190 
191 
192 
193  signals:
194  /**
195  * @brief wayPointSelected informs all relevant controllers that the currently selected Waypoit has been changed via click on the waypoint in the RobotViewer
196  * @param index
197  */
198  void wayPointSelected(int index);
199  /**
200  * @brief manipulatorChanged informs all relevant controllers that the pose of the manipulator has changed and therefore the currently selected Waypoint is also changed
201  */
202  void manipulatorChanged(Eigen::Matrix4f globalPose);
203  /**
204  * @brief tcpPoseChanged informs all releveant controllers about the new global pose of the manipulator
205  * @param globalPose the pose of the manipulator relative to the global frame
206  */
207  void tcpPoseChanged(Eigen::Matrix4f globalPose);
208  /**
209  * @brief poseReachable informs all relevant controllers whether the pose of the manipulator is reachable
210  * @param reachable true when there is an IK-solution for the manipulator could be found
211  */
212  void poseReachable(bool reachable);
213  /**
214  * @brief trajectoryPlayerNotPlaying
215  * @param playing
216  */
217  void trajectoryPlayerNotPlaying(bool playing);
218 
219  void trajectoryPlayerPlaying(bool playing);
220 
221  private:
222 
223  RobotVisualizationPtr viewer;
224  QWidget* parent;
225  RobotVisualizationWidget* viewSplitter;
226  bool iKCallback;
227  DesignerTrajectoryPtr currentTrajectory;
229  int selectedWayPoint;
230  int selectedTransition;
232  VirtualRobot::RobotNodeSetPtr selectedKinematicChain;
233  EnvironmentPtr environment;
234 
235  bool playerRunning;
237  void playerStarter();
238  };
239 
240 
241  using RobotVisualizationControllerPtr = std::shared_ptr<RobotVisualizationController>;
242 }
243 
244 #endif
armarx::RobotVisualizationController::removeView
void removeView()
removeView removes RobotViewer with index
Definition: RobotVisualizationController.cpp:149
armarx::RobotVisualizationController::onExitComponent
void onExitComponent() override
Called on exit, cleans.
Definition: RobotVisualizationController.cpp:96
armarx::RobotVisualizationController::playTrajectories
void playTrajectories(std::vector< DesignerTrajectoryPtr > trajectories)
playTrajectories plays all trajectories at the same time
Definition: RobotVisualizationController.cpp:427
armarx::RobotVisualizationController::onInitComponent
void onInitComponent() override
Initializes the controller.
Definition: RobotVisualizationController.cpp:63
armarx::RobotVisualizationController::wayPointSelected
void wayPointSelected(int index)
wayPointSelected informs all relevant controllers that the currently selected Waypoit has been change...
armarx::RobotVisualizationWidget
The RobotVisualizationWidget class Holds the original viewer and reproduces it tosupport parallel vie...
Definition: RobotVisualizationWidget.h:40
armarx::RobotVisualizationController::selectedTransitionChanged
void selectedTransitionChanged(int index)
selectedTransitionChanged highlights the Transition with index
Definition: RobotVisualizationController.cpp:271
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::RobotVisualizationController::environmentChanged
void environmentChanged(EnvironmentPtr environment)
environmentChanged updates the environment that is currently visualized
Definition: RobotVisualizationController.cpp:158
armarx::RobotVisualizationController::addConnection
void addConnection(std::shared_ptr< RobotVisualizationController > ctr)
Definition: RobotVisualizationController.cpp:136
display
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this display
Definition: license.txt:11
armarx::RobotVisualizationController::displayAllWayPoints
void displayAllWayPoints(bool display)
displayAllWayPoints Enables Visualization and threfore selection of all waypoints of the current Traj...
Definition: RobotVisualizationController.cpp:266
armarx::RobotVisualizationController::kinematicChainChanged
void kinematicChainChanged(VirtualRobot::RobotNodeSetPtr rns)
kinematicChainChanged removes all visualization from the previously selected Trajectory and changes t...
Definition: RobotVisualizationController.cpp:322
armarx::RobotVisualizationController::trajectoryPlayerPlaying
void trajectoryPlayerPlaying(bool playing)
armarx::RobotVisualizationController::tcpPoseChanged
void tcpPoseChanged(Eigen::Matrix4f globalPose)
tcpPoseChanged informs all releveant controllers about the new global pose of the manipulator
armarx::RobotVisualizationController::poseReachable
void poseReachable(bool reachable)
poseReachable informs all relevant controllers whether the pose of the manipulator is reachable
armarx::RobotVisualizationController::trajectoryPlayerStopped
void trajectoryPlayerStopped()
trajectoryPlayerStopped restarts the visualization of the whole scene after the debug drawer does not...
Definition: RobotVisualizationController.cpp:437
armarx::DesignerTrajectoryPlayerPtr
std::shared_ptr< DesignerTrajectoryPlayer > DesignerTrajectoryPlayerPtr
Definition: DesignerTrajectoryPlayer.h:85
armarx::EnvironmentPtr
std::shared_ptr< Environment > EnvironmentPtr
Definition: Environment.h:29
armarx::RobotVisualizationController::onDisconnectComponent
void onDisconnectComponent() override
Called whenever a component is disconnected.
Definition: RobotVisualizationController.cpp:91
armarx::RobotVisualizationController::RobotVisualizationController
RobotVisualizationController(QWidget *parent)
RobotVisualizationController creates a new RobotVisualizationController.
Definition: RobotVisualizationController.cpp:52
armarx::RobotVisualizationController::robotChanged
void robotChanged(VirtualRobot::RobotPtr robot)
robotChanged updates the robot model that is currently visualized Removes the robot that is visualize...
Definition: RobotVisualizationController.cpp:164
AbstractController.h
armarx::RobotVisualization
Definition: RobotVisualization.h:39
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::RobotVisualizationController::onConnectComponent
void onConnectComponent() override
Connects all signals and slots of the controller.
Definition: RobotVisualizationController.cpp:86
armarx::RobotVisualizationController::setIKCallbackEnabled
void setIKCallbackEnabled(bool enabled)
setIKCallbackEnabled sets whther the robot Model tries to reach the Pose determined by the Manipulato...
Definition: RobotVisualizationController.cpp:338
armarx::VisualizationObserver
The AdvancedVisualizationFactory class is the abstract decorator of the Decorator-Pattern and decorat...
Definition: VisualizationObserver.h:35
armarx::RobotVisualizationController::setCamera
void setCamera()
CAMERA UPDATING METHODS.
Definition: RobotVisualizationController.cpp:346
armarx::RobotVisualizationController::selectedWayPointChanged
void selectedWayPointChanged(int index)
selectedWayPointChanged highlights the waypoint with index and moves the manipulator to its Pose
Definition: RobotVisualizationController.cpp:403
armarx::RobotVisualizationController::trajectoryPlayerNotPlaying
void trajectoryPlayerNotPlaying(bool playing)
trajectoryPlayerNotPlaying
armarx::RobotVisualizationController::clearView
void clearView()
Definition: RobotVisualizationController.cpp:307
armarx::RobotVisualizationController::refresh
void refresh() override
refresh gets all relevant data from subject an updates itself accoringly should be called by subject ...
Definition: RobotVisualizationController.cpp:101
armarx::RobotVisualizationPtr
std::shared_ptr< RobotVisualization > RobotVisualizationPtr
Definition: RobotVisualization.h:161
Trajectory.h
armarx::RobotVisualizationController::~RobotVisualizationController
~RobotVisualizationController()
Definition: RobotVisualizationController.cpp:58
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::RobotVisualizationController::playTrajectory
void playTrajectory()
PLAY TRAJECTORY.
Definition: RobotVisualizationController.cpp:420
armarx::DesignerTrajectoryPtr
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
Definition: DesignerTrajectory.h:165
armarx::RobotVisualizationControllerPtr
std::shared_ptr< RobotVisualizationController > RobotVisualizationControllerPtr
Definition: RobotVisualizationController.h:241
armarx::RobotVisualizationController::manipulatorChanged
void manipulatorChanged(Eigen::Matrix4f globalPose)
manipulatorChanged informs all relevant controllers that the pose of the manipulator has changed and ...
armarx::RobotVisualizationController::addView
void addView()
PARALLEL VIEWS.
Definition: RobotVisualizationController.cpp:144
armarx::RobotVisualizationController
The RobotVisualizationController A Controller to control the visualization of the robot.
Definition: RobotVisualizationController.h:48
armarx::RobotVisualizationController::cartesianSelectionChanged
void cartesianSelectionChanged(VirtualRobot::IKSolver::CartesianSelection cs)
IK CALLBACK METHODS.
Definition: RobotVisualizationController.cpp:316
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotVisualizationController::updateViews
void updateViews(DesignerTrajectoryPtr trajectory)
UPDATING OF VISUALIZATION.
Definition: RobotVisualizationController.cpp:179
armarx::AbstractController
Abstract controller providing a set of methods which must be implemented by every controller.
Definition: AbstractController.h:35
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18