28 #include "VirtualRobot/XML/RobotIO.h"
30 #include "VirtualRobot/RobotNodeSet.h"
32 #include "../KinematicSolver.h"
34 #include "../Environment.h"
36 #include "../Util/OrientationConversion.h"
38 #include "../Visualization/DesignerTrajectoryPlayer.h"
41 #include <QGridLayout>
43 #define ROBOT_UPDATE_TIMER_MS 33
66 this->cs = IKSolver::CartesianSelection::All;
67 this->selectedWayPoint = 0;
68 this->selectedTransition = -1;
69 this->iKCallback =
true;
70 this->playerRunning =
false;
74 QWidget* viewerParent =
new QWidget();
77 dynamic_cast<QGridLayout*
>(parent->layout())->addWidget(viewSplitter, 0, 0, 1, 3);
78 if (environment != NULL && environment->getRobot())
83 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on init component";
88 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on connect component";
93 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on disconnect";
98 ARMARX_INFO <<
"RobotTrajectoryDesigner: RobotVisualizationController on exit components";
104 if (selectedWayPoint != this->viewer->getSelectedWaypoint())
106 selectedWayPoint = this->viewer->getSelectedWaypoint();
108 if (currentTrajectory &&
static_cast<unsigned>(viewer->getSelectedWaypoint()) < currentTrajectory->getAllUserWaypoints().size())
110 std::vector<double> angles = currentTrajectory->getUserWaypoint(viewer->getSelectedWaypoint())->getJointAngles();
111 viewer->setManipulator(currentTrajectory->getRns(), std::vector<float>(angles.begin(), angles.end()));
115 if (!selectedKinematicChain)
121 PoseBasePtr destination = PoseBasePtr(
new Pose(viewer->getManipulatorPose()));
122 std::string currentRnsName = selectedKinematicChain->getName();
123 std::vector<float>
jointAngles = ks->solveRecursiveIK(this->robot->getRobotNodeSet(currentRnsName), robot->getRobotNodeSet(currentRnsName)->getJointValues(), destination, cs);
126 robot->getRobotNodeSet(currentRnsName)->setJointValues(
jointAngles);
128 emit
tcpPoseChanged(robot->getRobotNodeSet(currentRnsName)->getTCP()->getGlobalPose());
138 viewer->setObserver(ctr);
160 this->environment = environment;
169 viewer->addRobotVisualization(this->robot,
"");
172 this->currentTrajectory = NULL;
173 this->selectedWayPoint = 0;
174 this->selectedTransition = -1;
185 viewer->clearTrajectory();
193 this->currentTrajectory = trajectory;
200 if (currentTrajectory->getAllUserWaypoints().size() == 0)
204 for (
UserWaypointPtr currentPoint : currentTrajectory->getAllUserWaypoints())
207 VirtualRobot::EndEffectorPtr endEffector = robot->getEndEffector(trajectory->getRns()->getTCP()->getName());
210 std::vector<VirtualRobot::EndEffectorPtr> eefs;
211 robot->getEndEffectors(eefs);
212 for (
auto eef : eefs)
214 if (eef->getTcp() == trajectory->getRns()->getTCP())
221 Pose localPose =
Pose(currentPoint->getPose()->position, currentPoint->getPose()->orientation);
225 viewer->addWaypointVisualization(i,
PosePtr(
new Pose(trajectory->getRns()->getKinematicRoot()->toGlobalCoordinateSystem(localPose.
toEigen()))), endEffector);
230 viewer->addWaypointVisualization(i,
PosePtr(
new Pose(trajectory->getRns()->getKinematicRoot()->toGlobalCoordinateSystem(localPose.
toEigen()))), NULL);
238 if (currentTrajectory->getAllUserWaypoints().size() == 1)
243 for (
unsigned int k = 0; k < currentTrajectory->getNrOfUserWaypoints() - 1; k++)
245 TrajectoryPtr currentTransition = currentTrajectory->getTransition(k)->getTrajectory();
246 std::vector<PoseBasePtr> curve = std::vector<PoseBasePtr>();
249 std::vector<double> jointValues = element.getPositions();
250 PoseBasePtr pose = ks->doForwardKinematic(currentTrajectory->getRns(), jointValues);
251 curve.push_back(pose);
253 viewer->addTransitionVisualization(k, curve);
254 if (
static_cast<signed>(k) == selectedTransition)
256 viewer->highlightTransitionVisualization(k, curve);
274 TrajectoryPtr selectedTransition = currentTrajectory->getTransition(
index)->getTrajectory();
276 std::vector<PoseBasePtr> curve = std::vector<PoseBasePtr>();
280 std::vector<double> jointValues = element.getPositions();
281 PoseBasePtr pose = ks->doForwardKinematic(currentTrajectory->getRns(), jointValues);
282 curve.push_back(pose);
287 if (currentTrajectory->getNrOfUserWaypoints() >
static_cast<unsigned>(this->selectedTransition + 1) && this->selectedTransition >= 0)
289 TrajectoryPtr deselectedTransition = currentTrajectory->getTransition(this->selectedTransition)->getTrajectory();
290 std::vector<PoseBasePtr> oldCurve = std::vector<PoseBasePtr>();
295 std::vector<double> jointValues = element.getPositions();
296 PoseBasePtr pose = ks->doForwardKinematic(currentTrajectory->getRns(), jointValues);
297 oldCurve.push_back(pose);
299 viewer->removeTransitionVisualization(this->selectedTransition);
300 viewer->addTransitionVisualization(this->selectedTransition, oldCurve);
302 viewer->highlightTransitionVisualization(
index, curve);
304 this->selectedTransition =
index;
309 viewer->clearTrajectory();
310 this->currentTrajectory = NULL;
318 this->cs = IKSolver::CartesianSelection::All;
324 viewer->removeAllWaypointVisualizations();
327 this->selectedKinematicChain = rns;
329 if (selectedKinematicChain)
332 jointAngles = std::vector<float>(robot->getRobotNodeSet(this->selectedKinematicChain->getName())->getJointValues());
333 viewer->setManipulator(this->selectedKinematicChain,
jointAngles);
353 Eigen::Vector3f position;
354 Eigen::Vector3f pointAtA = Eigen::Vector3f(0, 0, 0);
355 Eigen::Vector3f pointAtB;
361 position = Eigen::Vector3f(0, 2, 3.5);
362 pointAtB = Eigen::Vector3f(0, 0, 5);
367 position = Eigen::Vector3f(0, 0, 4);
368 pointAtB = Eigen::Vector3f(0, -360, 0);
373 position = Eigen::Vector3f(0, 5, 2);
374 pointAtB = Eigen::Vector3f(0, 0, 2);
378 position = Eigen::Vector3f(0, -5, 2);
379 pointAtB = Eigen::Vector3f(0, 0, 2);
384 position = Eigen::Vector3f(5, 0, 2);
385 pointAtB = Eigen::Vector3f(0, 0, 2);
389 position = Eigen::Vector3f(-5, 0, 2);
390 pointAtB = Eigen::Vector3f(0, 0, 2);
393 position = Eigen::Vector3f(0, 2, 3.5);
394 pointAtB = Eigen::Vector3f(0, 0, 5);
405 viewer->setSelectedWaypoint(
index);
406 if (currentTrajectory)
408 ARMARX_WARNING <<
"robot visualisation controller trying to update selected waypoint";
409 std::vector<double> jA = currentTrajectory->getUserWaypoint(
index)->getJointAngles();
410 std::vector<float>
jointAngles = std::vector<float>(jA.begin(), jA.end());
411 viewer->setManipulator(currentTrajectory->getRns(),
jointAngles);
423 player->addTrajectory(currentTrajectory);
424 this->playerStarter();
432 player->addTrajectory(current);
434 this->playerStarter();
443 viewer->setManipulator(selectedKinematicChain, robot->getRobotNodeSet(selectedKinematicChain->getName())->getJointValues());
444 playerRunning =
false;
449 void RobotVisualizationController::playerStarter()
451 if (playerRunning || !selectedKinematicChain)
455 playerRunning =
true;
459 viewer->clearTrajectory();
460 viewer->setManipulator(NULL, std::vector<float>());
462 player->startPlayback();