35#include "VirtualRobot/RobotNodeSet.h"
36#include "VirtualRobot/XML/RobotIO.h"
38#define ROBOT_UPDATE_TIMER_MS 33
61 this->cs = IKSolver::CartesianSelection::All;
62 this->selectedWayPoint = 0;
63 this->selectedTransition = -1;
64 this->iKCallback =
true;
65 this->playerRunning =
false;
69 QWidget* viewerParent =
new QWidget();
72 dynamic_cast<QGridLayout*
>(parent->layout())
73 ->addWidget(viewSplitter,
78 if (environment != NULL && environment->getRobot())
83 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on init component";
89 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on connect component";
95 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on disconnect";
101 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on exit components";
108 if (selectedWayPoint != this->viewer->getSelectedWaypoint())
110 selectedWayPoint = this->viewer->getSelectedWaypoint();
112 if (currentTrajectory &&
static_cast<unsigned>(viewer->getSelectedWaypoint()) <
113 currentTrajectory->getAllUserWaypoints().size())
115 std::vector<double> angles =
116 currentTrajectory->getUserWaypoint(viewer->getSelectedWaypoint())->getJointAngles();
117 viewer->setManipulator(currentTrajectory->getRns(),
118 std::vector<float>(angles.begin(), angles.end()));
122 if (!selectedKinematicChain)
128 PoseBasePtr destination = PoseBasePtr(
new Pose(viewer->getManipulatorPose()));
129 std::string currentRnsName = selectedKinematicChain->getName();
130 std::vector<float> jointAngles =
131 ks->solveRecursiveIK(this->robot->getRobotNodeSet(currentRnsName),
132 robot->getRobotNodeSet(currentRnsName)->getJointValues(),
135 if (jointAngles.size() != 0 && iKCallback)
137 robot->getRobotNodeSet(currentRnsName)->setJointValues(jointAngles);
139 emit
tcpPoseChanged(robot->getRobotNodeSet(currentRnsName)->getTCP()->getGlobalPose());
150 viewer->setObserver(ctr);
159 this->viewSplitter->addWidget();
165 this->viewSplitter->removeWidget();
175 this->environment = environment;
185 viewer->addRobotVisualization(this->robot,
"");
188 this->currentTrajectory = NULL;
189 this->selectedWayPoint = 0;
190 this->selectedTransition = -1;
201 viewer->clearTrajectory();
216 if (currentTrajectory->getAllUserWaypoints().size() == 0)
220 for (
UserWaypointPtr currentPoint : currentTrajectory->getAllUserWaypoints())
223 VirtualRobot::EndEffectorPtr endEffector =
224 robot->getEndEffector(
trajectory->getRns()->getTCP()->getName());
227 std::vector<VirtualRobot::EndEffectorPtr> eefs;
228 robot->getEndEffectors(eefs);
229 for (
auto eef : eefs)
231 if (eef->getTcp() ==
trajectory->getRns()->getTCP())
239 Pose(currentPoint->getPose()->position, currentPoint->getPose()->orientation);
243 viewer->addWaypointVisualization(
252 viewer->addWaypointVisualization(
263 if (currentTrajectory->getAllUserWaypoints().size() == 1)
268 for (
unsigned int k = 0; k < currentTrajectory->getNrOfUserWaypoints() - 1; k++)
270 TrajectoryPtr currentTransition = currentTrajectory->getTransition(k)->getTrajectory();
271 std::vector<PoseBasePtr> curve = std::vector<PoseBasePtr>();
274 std::vector<double> jointValues = element.getPositions();
275 PoseBasePtr pose = ks->doForwardKinematic(currentTrajectory->getRns(), jointValues);
276 curve.push_back(pose);
278 viewer->addTransitionVisualization(k, curve);
279 if (
static_cast<signed>(k) == selectedTransition)
281 viewer->highlightTransitionVisualization(k, curve);
297 TrajectoryPtr selectedTransition = currentTrajectory->getTransition(
index)->getTrajectory();
299 std::vector<PoseBasePtr> curve = std::vector<PoseBasePtr>();
303 std::vector<double> jointValues = element.getPositions();
304 PoseBasePtr pose = ks->doForwardKinematic(currentTrajectory->getRns(), jointValues);
305 curve.push_back(pose);
310 if (currentTrajectory->getNrOfUserWaypoints() >
311 static_cast<unsigned>(this->selectedTransition + 1) &&
312 this->selectedTransition >= 0)
315 currentTrajectory->getTransition(this->selectedTransition)->getTrajectory();
316 std::vector<PoseBasePtr> oldCurve = std::vector<PoseBasePtr>();
321 std::vector<double> jointValues = element.getPositions();
322 PoseBasePtr pose = ks->doForwardKinematic(currentTrajectory->getRns(), jointValues);
323 oldCurve.push_back(pose);
325 viewer->removeTransitionVisualization(this->selectedTransition);
326 viewer->addTransitionVisualization(this->selectedTransition, oldCurve);
328 viewer->highlightTransitionVisualization(
index, curve);
330 this->selectedTransition =
index;
336 viewer->clearTrajectory();
337 this->currentTrajectory = NULL;
345 VirtualRobot::IKSolver::CartesianSelection cs)
347 this->cs = IKSolver::CartesianSelection::All;
354 viewer->removeAllWaypointVisualizations();
357 this->selectedKinematicChain = rns;
359 if (selectedKinematicChain)
361 std::vector<float> jointAngles;
362 jointAngles = std::vector<float>(
363 robot->getRobotNodeSet(this->selectedKinematicChain->getName())->getJointValues());
364 viewer->setManipulator(this->selectedKinematicChain, jointAngles);
372 iKCallback = enabled;
387 Eigen::Vector3f position;
388 Eigen::Vector3f pointAtA = Eigen::Vector3f(0, 0, 0);
389 Eigen::Vector3f pointAtB;
395 position = Eigen::Vector3f(0, 2, 3.5);
396 pointAtB = Eigen::Vector3f(0, 0, 5);
401 position = Eigen::Vector3f(0, 0, 4);
402 pointAtB = Eigen::Vector3f(0, -360, 0);
407 position = Eigen::Vector3f(0, 5, 2);
408 pointAtB = Eigen::Vector3f(0, 0, 2);
412 position = Eigen::Vector3f(0, -5, 2);
413 pointAtB = Eigen::Vector3f(0, 0, 2);
418 position = Eigen::Vector3f(5, 0, 2);
419 pointAtB = Eigen::Vector3f(0, 0, 2);
423 position = Eigen::Vector3f(-5, 0, 2);
424 pointAtB = Eigen::Vector3f(0, 0, 2);
427 position = Eigen::Vector3f(0, 2, 3.5);
428 pointAtB = Eigen::Vector3f(0, 0, 5);
430 this->viewSplitter->setCameraOfFocused(position, pointAtA, pointAtB);
439 viewer->setSelectedWaypoint(
index);
440 if (currentTrajectory)
442 ARMARX_WARNING <<
"robot visualisation controller trying to update selected waypoint";
443 std::vector<double> jA = currentTrajectory->getUserWaypoint(
index)->getJointAngles();
444 std::vector<float> jointAngles = std::vector<float>(jA.begin(), jA.end());
445 viewer->setManipulator(currentTrajectory->getRns(), jointAngles);
447 currentTrajectory->getUserWaypoint(
index)->getIKSelection());
459 player->addTrajectory(currentTrajectory);
460 this->playerStarter();
469 player->addTrajectory(current);
471 this->playerStarter();
481 viewer->setManipulator(
482 selectedKinematicChain,
483 robot->getRobotNodeSet(selectedKinematicChain->getName())->getJointValues());
484 playerRunning =
false;
490RobotVisualizationController::playerStarter()
492 if (playerRunning || !selectedKinematicChain)
496 playerRunning =
true;
500 viewer->clearTrajectory();
501 viewer->setManipulator(NULL, std::vector<float>());
503 player->startPlayback();
The CoinRobotViewerAdapter class.
static std::shared_ptr< KinematicSolver > getInstance(VirtualRobot::ScenePtr scenario, VirtualRobot::RobotPtr robot)
SINGLETON-FEATURES///////////////////////////////////////////////////////////////////////////////////...
virtual Eigen::Matrix4f toEigen() const
void environmentChanged(EnvironmentPtr environment)
environmentChanged updates the environment that is currently visualized
void onInitComponent() override
Initializes the controller.
void playTrajectory()
PLAY TRAJECTORY.
void tcpPoseChanged(Eigen::Matrix4f globalPose)
tcpPoseChanged informs all releveant controllers about the new global pose of the manipulator
void addConnection(std::shared_ptr< RobotVisualizationController > ctr)
void wayPointSelected(int index)
wayPointSelected informs all relevant controllers that the currently selected Waypoit has been change...
void removeView()
removeView removes RobotViewer with index
void cartesianSelectionChanged(VirtualRobot::IKSolver::CartesianSelection cs)
IK CALLBACK METHODS.
void onDisconnectComponent() override
Called whenever a component is disconnected.
void selectedTransitionChanged(int index)
selectedTransitionChanged highlights the Transition with index
void displayAllWayPoints(bool display)
displayAllWayPoints Enables Visualization and threfore selection of all waypoints of the current Traj...
void refresh() override
refresh gets all relevant data from subject an updates itself accoringly should be called by subject ...
void poseReachable(bool reachable)
poseReachable informs all relevant controllers whether the pose of the manipulator is reachable
void kinematicChainChanged(VirtualRobot::RobotNodeSetPtr rns)
kinematicChainChanged removes all visualization from the previously selected Trajectory and changes t...
void manipulatorChanged(Eigen::Matrix4f globalPose)
manipulatorChanged informs all relevant controllers that the pose of the manipulator has changed and ...
void trajectoryPlayerPlaying(bool playing)
void updateViews(DesignerTrajectoryPtr trajectory)
UPDATING OF VISUALIZATION.
void setIKCallbackEnabled(bool enabled)
setIKCallbackEnabled sets whther the robot Model tries to reach the Pose determined by the Manipulato...
RobotVisualizationController(QWidget *parent)
RobotVisualizationController creates a new RobotVisualizationController.
void playTrajectories(std::vector< DesignerTrajectoryPtr > trajectories)
playTrajectories plays all trajectories at the same time
~RobotVisualizationController()
void selectedWayPointChanged(int index)
selectedWayPointChanged highlights the waypoint with index and moves the manipulator to its Pose
void onConnectComponent() override
Connects all signals and slots of the controller.
void trajectoryPlayerNotPlaying(bool playing)
trajectoryPlayerNotPlaying
void setCamera()
CAMERA UPDATING METHODS.
void robotChanged(VirtualRobot::RobotPtr robot)
robotChanged updates the robot model that is currently visualized Removes the robot that is visualize...
void onExitComponent() override
Called on exit, cleans.
void addView()
PARALLEL VIEWS.
void trajectoryPlayerStopped()
trajectoryPlayerStopped restarts the visualization of the whole scene after the debug drawer does not...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< class Robot > RobotPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< KinematicSolver > KinematicSolverPtr
std::shared_ptr< DesignerTrajectoryPlayer > DesignerTrajectoryPlayerPtr
IceInternal::Handle< Trajectory > TrajectoryPtr
IceInternal::Handle< Pose > PosePtr
std::shared_ptr< Environment > EnvironmentPtr
std::shared_ptr< RobotVisualizationController > RobotVisualizationControllerPtr
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
std::shared_ptr< UserWaypoint > UserWaypointPtr
std::shared_ptr< RobotVisualization > RobotVisualizationPtr