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 <Eigen/Eigen>
26 
27 #include "RobotAPI/interface/core/PoseBase.h"
29 
30 #include "../Environment.h"
31 #include "../Model/DesignerTrajectory.h"
32 #include "../Visualization/CoinRobotViewerAdapter.h"
33 #include "../Visualization/DesignerTrajectoryPlayer.h"
34 #include "../Visualization/RobotVisualizationWidget.h"
35 #include "../Visualization/VisualizationObserver.h"
36 #include "AbstractController.h"
37 #include "VirtualRobot/IK/IKSolver.h"
38 #include <../Visualization/RobotVisualization.h>
39 #include <Inventor/sensors/SoTimerSensor.h>
40 
41 namespace armarx
42 {
43 
44  /**
45  * @brief The RobotVisualizationController
46  * A Controller to control the visualization of the robot. Hides the concrete visualization Method(Coin,OSG) from the rest of the application.
47  * Provides Methods for adding Visualization of one Robot at a time, waypoints and transitions between waypoints. Supports up to four parallel views.
48  * Informs other Controllers about the Position of the Manipulator, the TCP and the selected waypoint.
49  */
51  {
52  Q_OBJECT
53  friend class RobotVisualization;
54 
55  public:
56  /**
57  * @brief RobotVisualizationController creates a new RobotVisualizationController
58  * @param parent the widget in which th viewer should be placed in
59  */
60  RobotVisualizationController(QWidget* parent);
62 
63  //inherited by abstract controller
64  void onInitComponent() override;
65  void onConnectComponent() override;
66  void onDisconnectComponent() override;
67  void onExitComponent() override;
68 
69  //inherited by VisualizationObserver
70  void refresh() override;
71  void addConnection(std::shared_ptr<RobotVisualizationController> ctr);
72 
73  public slots:
74 
75  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76  /// PARALLEL VIEWS
77  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78  /**
79  * @brief addView adds new RobotViewer
80  */
81  void addView();
82  /**
83  * @brief removeView removes RobotViewer with index
84  * @param index the index of the view to remove
85  */
86  void removeView();
87 
88  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89  /// UPDATING OF VISUALIZATION
90  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91  /**
92  * @brief updateViews Removes the current visualization of all Waypoints and Transitions and replaces them with the visualization of the new Trajectory
93  * @param trajectory the trajectory to display next
94  */
95  void updateViews(DesignerTrajectoryPtr trajectory);
96 
97  /**
98  * @brief robotChanged updates the robot model that is currently visualized
99  * Removes the robot that is visualized prior to this one
100  * @param robot the new Robot to visualize
101  */
103 
104  /**
105  * @brief environmentChanged updates the environment that is currently visualized
106  * @param environment the new environment
107  */
108  void environmentChanged(EnvironmentPtr environment);
109 
110  /**
111  * @brief displayAllWayPoints Enables Visualization and threfore selection of all waypoints of the current Trajectory and not only userWaypoints
112  * @param display
113  */
114  void displayAllWayPoints(bool display);
115 
116  /**
117  * @brief selectedWayPointChanged highlights the waypoint with index and moves the manipulator to its Pose
118  * @param index the index of the waypoint to select next
119  */
120  void selectedWayPointChanged(int index);
121 
122  /**
123  * @brief selectedTransitionChanged highlights the Transition with index
124  * @param index the index of the transition that should be highlighted
125  */
127 
128  void clearView();
129  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
130  /// IK CALLBACK METHODS
131  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132  /**
133  * @brief cartesianSelectionChanged recalculates the configuration of the robot joints to fit the new selection
134  * @param cs the new CartesianSelection
135  */
137 
138  /**
139  * @brief kinematicChainChanged removes all visualization from the previously selected Trajectory and changes the Visualization of the
140  * Manipulator to look like the endeffector of the kinematic chain
141  * @param selectedChain
142  */
143  void kinematicChainChanged(VirtualRobot::RobotNodeSetPtr rns);
144 
145  /**
146  * @brief setIKCallbackEnabled sets whther the robot Model tries to reach the Pose determined by the Manipulator
147  * @param enabled if true the robot follows the manipulator
148  */
149  void setIKCallbackEnabled(bool enabled);
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  signals:
192  /**
193  * @brief wayPointSelected informs all relevant controllers that the currently selected Waypoit has been changed via click on the waypoint in the RobotViewer
194  * @param index
195  */
196  void wayPointSelected(int index);
197  /**
198  * @brief manipulatorChanged informs all relevant controllers that the pose of the manipulator has changed and therefore the currently selected Waypoint is also changed
199  */
200  void manipulatorChanged(Eigen::Matrix4f globalPose);
201  /**
202  * @brief tcpPoseChanged informs all releveant controllers about the new global pose of the manipulator
203  * @param globalPose the pose of the manipulator relative to the global frame
204  */
205  void tcpPoseChanged(Eigen::Matrix4f globalPose);
206  /**
207  * @brief poseReachable informs all relevant controllers whether the pose of the manipulator is reachable
208  * @param reachable true when there is an IK-solution for the manipulator could be found
209  */
210  void poseReachable(bool reachable);
211  /**
212  * @brief trajectoryPlayerNotPlaying
213  * @param playing
214  */
215  void trajectoryPlayerNotPlaying(bool playing);
216 
217  void trajectoryPlayerPlaying(bool playing);
218 
219  private:
220  RobotVisualizationPtr viewer;
221  QWidget* parent;
222  RobotVisualizationWidget* viewSplitter;
223  bool iKCallback;
224  DesignerTrajectoryPtr currentTrajectory;
226  int selectedWayPoint;
227  int selectedTransition;
229  VirtualRobot::RobotNodeSetPtr selectedKinematicChain;
230  EnvironmentPtr environment;
231 
232  bool playerRunning;
234  void playerStarter();
235  };
236 
237  using RobotVisualizationControllerPtr = std::shared_ptr<RobotVisualizationController>;
238 } // namespace armarx
239 
240 #endif
armarx::RobotVisualizationController::removeView
void removeView()
removeView removes RobotViewer with index
Definition: RobotVisualizationController.cpp:163
armarx::RobotVisualizationController::onExitComponent
void onExitComponent() override
Called on exit, cleans.
Definition: RobotVisualizationController.cpp:99
armarx::RobotVisualizationController::playTrajectories
void playTrajectories(std::vector< DesignerTrajectoryPtr > trajectories)
playTrajectories plays all trajectories at the same time
Definition: RobotVisualizationController.cpp:464
armarx::RobotVisualizationController::onInitComponent
void onInitComponent() override
Initializes the controller.
Definition: RobotVisualizationController.cpp:58
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:294
index
uint8_t index
Definition: EtherCATFrame.h:59
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::RobotVisualizationController::environmentChanged
void environmentChanged(EnvironmentPtr environment)
environmentChanged updates the environment that is currently visualized
Definition: RobotVisualizationController.cpp:173
armarx::RobotVisualizationController::addConnection
void addConnection(std::shared_ptr< RobotVisualizationController > ctr)
Definition: RobotVisualizationController.cpp:148
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:288
armarx::RobotVisualizationController::kinematicChainChanged
void kinematicChainChanged(VirtualRobot::RobotNodeSetPtr rns)
kinematicChainChanged removes all visualization from the previously selected Trajectory and changes t...
Definition: RobotVisualizationController.cpp:352
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:475
armarx::DesignerTrajectoryPlayerPtr
std::shared_ptr< DesignerTrajectoryPlayer > DesignerTrajectoryPlayerPtr
Definition: DesignerTrajectoryPlayer.h:81
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:93
armarx::RobotVisualizationController::RobotVisualizationController
RobotVisualizationController(QWidget *parent)
RobotVisualizationController creates a new RobotVisualizationController.
Definition: RobotVisualizationController.cpp:47
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:180
AbstractController.h
armarx::RobotVisualization
Definition: RobotVisualization.h:38
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:87
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:370
armarx::VisualizationObserver
The AdvancedVisualizationFactory class is the abstract decorator of the Decorator-Pattern and decorat...
Definition: VisualizationObserver.h:34
armarx::RobotVisualizationController::setCamera
void setCamera()
CAMERA UPDATING METHODS.
Definition: RobotVisualizationController.cpp:379
armarx::RobotVisualizationController::selectedWayPointChanged
void selectedWayPointChanged(int index)
selectedWayPointChanged highlights the waypoint with index and moves the manipulator to its Pose
Definition: RobotVisualizationController.cpp:437
armarx::RobotVisualizationController::trajectoryPlayerNotPlaying
void trajectoryPlayerNotPlaying(bool playing)
trajectoryPlayerNotPlaying
armarx::RobotVisualizationController::clearView
void clearView()
Definition: RobotVisualizationController.cpp:334
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:105
armarx::RobotVisualizationPtr
std::shared_ptr< RobotVisualization > RobotVisualizationPtr
Definition: RobotVisualization.h:165
Trajectory.h
armarx::RobotVisualizationController::~RobotVisualizationController
~RobotVisualizationController()
Definition: RobotVisualizationController.cpp:53
armarx::RobotVisualizationController::playTrajectory
void playTrajectory()
PLAY TRAJECTORY.
Definition: RobotVisualizationController.cpp:456
armarx::DesignerTrajectoryPtr
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
Definition: DesignerTrajectory.h:163
armarx::RobotVisualizationControllerPtr
std::shared_ptr< RobotVisualizationController > RobotVisualizationControllerPtr
Definition: RobotVisualizationController.h:237
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:157
armarx::RobotVisualizationController
The RobotVisualizationController A Controller to control the visualization of the robot.
Definition: RobotVisualizationController.h:50
armarx::RobotVisualizationController::cartesianSelectionChanged
void cartesianSelectionChanged(VirtualRobot::IKSolver::CartesianSelection cs)
IK CALLBACK METHODS.
Definition: RobotVisualizationController.cpp:344
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RobotVisualizationController::updateViews
void updateViews(DesignerTrajectoryPtr trajectory)
UPDATING OF VISUALIZATION.
Definition: RobotVisualizationController.cpp:195
armarx::AbstractController
Abstract controller providing a set of methods which must be implemented by every controller.
Definition: AbstractController.h:37
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19