15 ARMARX_INFO <<
"RobotTrajectoryDesigner: TrajectoryController on init";
21 ARMARX_INFO <<
"RobotTrajectoryDesigner: TrajectoryController on connect";
27 ARMARX_INFO <<
"RobotTrajectoryDesigner: TrajectoryController on disconnect";
33 ARMARX_INFO <<
"RobotTrajectoryDesigner: TrajectoryController on exit";
47 if (environment->getRobot() == NULL || holder == NULL)
52 VirtualRobot::RobotNodeSetPtr helpRns =
53 environment->getRobot()->getRobotNodeSet(tcp.toStdString());
54 if (manager != NULL && !manager->getIsInitialized())
56 holder->deleteDesignerTrajectoryManager(rns->getName());
63 helpCreateDesignerTrajectoryManager();
65 else if (rns == helpRns)
69 else if (holder->rnsIsPartOfExistingRns(helpRns->getName()))
71 if (holder->rnsExists(helpRns->getName()))
74 manager = holder->getTrajectoryManager(helpRns->getName());
78 addTransitionWaypointGui(manager->getDesignerTrajectory());
83 QMessageBox* rnsIsPartOfExistingRns =
new QMessageBox;
84 rnsIsPartOfExistingRns->setWindowTitle(QString::fromStdString(
"Error Message"));
85 rnsIsPartOfExistingRns->setText(
86 QString::fromStdString(
"Selected TCP is part of an existing TCP."));
87 rnsIsPartOfExistingRns->exec();
96 helpCreateDesignerTrajectoryManager();
111 changeTransitionWaypointGui(manager->getDesignerTrajectory());
112 helpEnableUndoRedo();
115 catch (LocalException& e)
117 helpExceptionMessageBox(e.getReason());
119 manager->getDesignerTrajectory()->getTransition(transition);
120 helpChangeTransitionGui(transitionPtr, transition);
122 catch (InvalidArgumentException& e)
124 helpExceptionMessageBox(e.reason);
126 manager->getDesignerTrajectory()->getTransition(transition);
127 helpChangeTransitionGui(transitionPtr, transition);
139 manager->setTransitionUserDuration(transition, duration);
141 changeTransitionWaypointGui(manager->getDesignerTrajectory());
142 helpEnableUndoRedo();
145 catch (InvalidArgumentException& e)
148 manager->getDesignerTrajectory()->getTransition(transition);
149 helpChangeTransitionGui(transitionPtr, transition);
161 manager->editWaypointPoseBase(waypoint, parseToPoseBasePtr(values));
163 changeTransitionWaypointGui(manager->getDesignerTrajectory());
164 helpEnableUndoRedo();
167 catch (LocalException& e)
170 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
171 helpChangeWaypointGui(waypointPtr, waypoint);
173 catch (InvalidArgumentException& e)
176 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
177 helpChangeWaypointGui(waypointPtr, waypoint);
189 manager->editWaypointPoseBase(
191 *
new PoseBasePtr(
new Pose(rns->getKinematicRoot()->toLocalCoordinateSystem(
192 rns->getTCP()->getGlobalPose()))));
194 changeTransitionWaypointGui(manager->getDesignerTrajectory());
195 helpEnableUndoRedo();
198 catch (LocalException& e)
200 helpExceptionMessageBox(e.getReason());
202 catch (InvalidArgumentException& e)
204 helpExceptionMessageBox(e.reason);
216 manager->editWaypointPoseBase(waypoint, newPoseBase);
218 changeTransitionWaypointGui(manager->getDesignerTrajectory());
219 helpEnableUndoRedo();
222 catch (LocalException& e)
224 helpExceptionMessageBox(e.getReason());
226 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
227 helpChangeWaypointGui(waypointPtr, waypoint);
229 catch (InvalidArgumentException& e)
231 helpExceptionMessageBox(e.reason);
233 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
234 helpChangeWaypointGui(waypointPtr, waypoint);
246 manager->editWaypointIKSelection(
247 waypoint, (VirtualRobot::IKSolver::CartesianSelection)cartesianSelection);
249 changeTransitionWaypointGui(manager->getDesignerTrajectory());
251 manager->getDesignerTrajectory()->getUserWaypoint(waypoint)->getIKSelection());
252 helpEnableUndoRedo();
255 catch (LocalException& e)
257 helpExceptionMessageBox(e.getReason());
259 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
260 helpChangeWaypointGui(waypointPtr, waypoint);
262 catch (InvalidArgumentException& e)
264 helpExceptionMessageBox(e.reason);
266 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
267 helpChangeWaypointGui(waypointPtr, waypoint);
282 manager->setWaypointAsBreakpoint(waypoint, isBreakpoint);
284 changeTransitionWaypointGui(manager->getDesignerTrajectory());
285 helpEnableUndoRedo();
287 catch (LocalException& e)
289 helpExceptionMessageBox(e.getReason());
291 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
292 helpChangeWaypointGui(waypointPtr, waypoint);
294 catch (InvalidArgumentException& e)
296 helpExceptionMessageBox(e.reason);
298 manager->getDesignerTrajectory()->getUserWaypoint(waypoint);
299 helpChangeWaypointGui(waypointPtr, waypoint);
311 unsigned int helpWaypoint =
static_cast<unsigned>(waypoint);
312 if (!manager->getIsInitialized())
314 std::vector<double> jointValues;
315 for (
double newValue : rns->getJointValues())
317 jointValues.push_back((
double)newValue);
319 manager->initializeDesignerTrajectory(jointValues);
321 helpAddWaypointGui(manager->getDesignerTrajectory()->getUserWaypoint(waypoint),
326 else if (helpWaypoint == manager->getDesignerTrajectory()->getNrOfUserWaypoints() -
327 static_cast<unsigned>(1) &&
332 manager->addWaypoint(
333 *
new PoseBasePtr(
new Pose(rns->getKinematicRoot()->toLocalCoordinateSystem(
334 rns->getTCP()->getGlobalPose()))));
336 helpAddWaypointGui(manager->getDesignerTrajectory()->getUserWaypoint(waypoint + 1),
338 helpAddTransitionGui(manager->getDesignerTrajectory()->getTransition(waypoint),
340 changeTransitionWaypointGui(manager->getDesignerTrajectory());
343 catch (LocalException& e)
345 helpExceptionMessageBox(e.getReason());
347 catch (InvalidArgumentException& e)
349 helpExceptionMessageBox(e.reason);
352 else if (helpWaypoint < manager->getDesignerTrajectory()->getNrOfUserWaypoints() -
353 static_cast<unsigned>(1) &&
354 waypoint >= 0 && insertAfter)
358 manager->insertWaypoint(
360 *
new PoseBasePtr(
new Pose(rns->getKinematicRoot()->toLocalCoordinateSystem(
361 rns->getTCP()->getGlobalPose()))));
363 helpAddWaypointGui(manager->getDesignerTrajectory()->getUserWaypoint(waypoint + 1),
365 helpAddTransitionGui(manager->getDesignerTrajectory()->getTransition(waypoint + 1),
367 changeTransitionWaypointGui(manager->getDesignerTrajectory());
370 catch (LocalException& e)
372 helpExceptionMessageBox(e.getReason());
375 else if (helpWaypoint < manager->getDesignerTrajectory()->getNrOfUserWaypoints() &&
376 waypoint >= 0 && !insertAfter)
380 manager->insertWaypoint(
382 *
new PoseBasePtr(
new Pose(rns->getKinematicRoot()->toLocalCoordinateSystem(
383 rns->getTCP()->getGlobalPose()))));
385 helpAddWaypointGui(manager->getDesignerTrajectory()->getUserWaypoint(waypoint),
387 helpAddTransitionGui(manager->getDesignerTrajectory()->getTransition(waypoint),
389 changeTransitionWaypointGui(manager->getDesignerTrajectory());
392 catch (LocalException& e)
394 helpExceptionMessageBox(e.getReason());
396 catch (InvalidArgumentException& e)
398 helpExceptionMessageBox(e.reason);
402 helpEnableUndoRedo();
413 if (!manager->getIsInitialized())
418 unsigned int helpWaypoint =
static_cast<unsigned>(waypoint);
419 if (waypoint == 0 && manager->getDesignerTrajectory()->getNrOfUserWaypoints() == 1)
423 manager->deleteWaypoint(waypoint);
426 catch (LocalException& e)
428 helpExceptionMessageBox(e.getReason());
430 catch (InvalidArgumentException& e)
432 helpExceptionMessageBox(e.reason);
435 else if (helpWaypoint == manager->getDesignerTrajectory()->getNrOfUserWaypoints() -
436 static_cast<unsigned>(1))
440 manager->deleteWaypoint(waypoint);
444 changeTransitionWaypointGui(manager->getDesignerTrajectory());
447 catch (LocalException& e)
449 helpExceptionMessageBox(e.getReason());
451 catch (InvalidArgumentException& e)
453 helpExceptionMessageBox(e.reason);
456 else if (waypoint >= 0 &&
457 helpWaypoint < manager->getDesignerTrajectory()->getNrOfUserWaypoints() -
458 static_cast<unsigned>(1))
462 manager->deleteWaypoint(waypoint);
466 changeTransitionWaypointGui(manager->getDesignerTrajectory());
469 catch (LocalException& e)
471 helpExceptionMessageBox(e.getReason());
473 catch (InvalidArgumentException& e)
475 helpExceptionMessageBox(e.reason);
478 helpEnableUndoRedo();
487 if (holder->rnsIsPartOfExistingRns(designerTrajectory->getRns()->getName()))
489 QMessageBox::StandardButton reply;
490 reply = QMessageBox::question(0,
492 "Do you want to override the existing Trajectory?",
493 QMessageBox::Yes | QMessageBox::No);
494 if (reply == QMessageBox::Yes)
497 helpImportDesignerTrajectory(designerTrajectory);
501 QMessageBox* importFailed =
new QMessageBox;
502 importFailed->setWindowTitle(QString::fromStdString(
"Error Message"));
503 importFailed->setText(QString::fromStdString(
"Import failed."));
504 importFailed->exec();
509 helpImportDesignerTrajectory(designerTrajectory);
513 helpEnableUndoRedo();
523 std::vector<DesignerTrajectoryPtr> designerTrajectories;
524 for (VirtualRobot::RobotNodeSetPtr s : environment->getRobot()->getRobotNodeSets())
526 if (holder->rnsExists(s->getName()) &&
527 holder->getTrajectoryManager(s->getName())->getIsInitialized())
530 designerTrajectories.push_back(
531 holder->getTrajectoryManager(s->getName())->getDesignerTrajectory());
543 std::vector<DesignerTrajectoryPtr> designerTrajectories;
544 for (VirtualRobot::RobotNodeSetPtr s : environment->getRobot()->getRobotNodeSets())
546 if (holder->rnsExists(s->getName()) &&
547 holder->getTrajectoryManager(s->getName())->getIsInitialized())
549 designerTrajectories.push_back(
550 holder->getTrajectoryManager(s->getName())->getDesignerTrajectory());
566 addTransitionWaypointGui(manager->getDesignerTrajectory());
569 helpEnableUndoRedo();
583 addTransitionWaypointGui(manager->getDesignerTrajectory());
586 helpEnableUndoRedo();
594 std::vector<DesignerTrajectoryPtr> designerTrajectories;
595 for (VirtualRobot::RobotNodeSetPtr s : environment->getRobot()->getRobotNodeSets())
597 if (holder->rnsExists(s->getName()))
599 designerTrajectories.push_back(
600 holder->getTrajectoryManager(s->getName())->getDesignerTrajectory());
609 this->environment = environment;
610 holder = std::make_shared<DesignerTrajectoryHolder>(environment);
615 helpEnableUndoRedo();
622 this->activeColModelName = activeColModelName.toStdString();
629 this->bodyColModelsNames.clear();
630 for (QString name : bodyColModelsNames)
632 this->bodyColModelsNames.push_back(name.toStdString());
642 TrajectoryController::parseToCoordinate(PoseBasePtr pose)
644 float x = pose->position->x;
645 float y = pose->position->y;
646 float z = pose->position->z;
648 orientation->qw = pose->orientation->qw;
649 orientation->qx = pose->orientation->qx;
650 orientation->qy = pose->orientation->qy;
651 orientation->qz = pose->orientation->qz;
653 return {
x, y, z, eulerAngle[0], eulerAngle[1], eulerAngle[2]};
657 TrajectoryController::parseToPoseBasePtr(std::vector<double> values)
660 QuaternionBasePtr orientation =
662 return new FramedPose(position, orientation,
"",
"");
668 TrajectoryController::helpAddWaypointGui(
UserWaypointPtr waypoint,
int waypointIndex)
670 std::vector<double>
values = parseToCoordinate(waypoint->getPose());
671 bool isBreakpoint = waypoint->getIsTimeOptimalBreakpoint();
672 emit
addWaypointGui(waypointIndex, values, waypoint->getIKSelection(), isBreakpoint);
676 TrajectoryController::helpAddTransitionGui(
TransitionPtr transition,
int transitionIndex)
678 double duration = transition->getUserDuration();
679 double startTime = transition->getStart()->getUserTimestamp();
689 for (
unsigned int i = 0; i < trajectory->getNrOfUserWaypoints(); i++)
692 helpAddWaypointGui(waypoint, i);
695 for (
unsigned int i = 0; i < trajectory->getNrOfUserWaypoints() - 1; i++)
698 helpAddTransitionGui(transition, i);
710 TrajectoryController::helpChangeTransitionGui(
TransitionPtr transition,
int transitionIndex)
712 double duration = transition->getUserDuration();
713 double startTime = transition->getStart()->getUserTimestamp();
719 TrajectoryController::helpChangeWaypointGui(
UserWaypointPtr waypoint,
int waypointIndex)
721 std::vector<double>
values = parseToCoordinate(waypoint->getPose());
722 bool isBreakpoint = waypoint->getIsTimeOptimalBreakpoint();
723 emit
changeWaypointGui(waypointIndex, values, waypoint->getIKSelection(), isBreakpoint);
729 for (
unsigned int i = 0; i < trajectory->getNrOfUserWaypoints(); i++)
732 helpChangeWaypointGui(waypoint, i);
735 for (
unsigned int i = 0; i < trajectory->getNrOfUserWaypoints() - 1; i++)
738 helpChangeTransitionGui(transition, i);
748 holder->import(designerTrajectory,
true);
749 manager = holder->getTrajectoryManager(designerTrajectory->getRns()->getName());
750 rns = manager->getDesignerTrajectory()->getRns();
755 addTransitionWaypointGui(manager->getDesignerTrajectory());
761 TrajectoryController::helpCreateDesignerTrajectoryManager()
763 holder->createDesignerTrajectoryManager(rns->getName());
764 manager = holder->getTrajectoryManager(rns->getName());
771 TrajectoryController::helpEnableExportPreviewAll()
774 for (VirtualRobot::RobotNodeSetPtr s : environment->getRobot()->getRobotNodeSets())
776 if (holder->rnsExists(
s->getName()) &&
777 holder->getTrajectoryManager(
s->getName())->getIsInitialized())
779 if (holder->getTrajectoryManager(
s->getName())
780 ->getDesignerTrajectory()
781 ->getNrOfUserWaypoints() > 1)
795 TrajectoryController::helpEnableUndoRedo()
810 TrajectoryController::helpEnableButtons()
817 if (manager->getIsInitialized())
819 unsigned int nrWaypoints = manager->getDesignerTrajectory()->getNrOfUserWaypoints();
821 if (nrWaypoints >= 1)
824 if (nrWaypoints >= 2)
856 TrajectoryController::helpExceptionMessageBox(std::string errorMessage)
858 QMessageBox* errorMessageBox =
new QMessageBox;
859 errorMessageBox->setWindowTitle(QString::fromStdString(
"Error Message"));
860 errorMessageBox->setText(QString::fromStdString(errorMessage));
861 errorMessageBox->exec();
867 TrajectoryController::helpCollision()
874 if (holder->isInCollision(activeColModelName, bodyColModelsNames, 100))
876 QMessageBox* changeInterpolationFailed =
new QMessageBox;
877 changeInterpolationFailed->setWindowTitle(QString::fromStdString(
"Information"));
878 changeInterpolationFailed->setText(QString::fromStdString(
"A collision is detected."));
879 changeInterpolationFailed->exec();
The FramedOrientation class.
static std::vector< double > toEulerAngle(QuaternionBasePtr q)
static QuaternionBasePtr toQuaternion(const double roll, const double pitch, const double yaw)
void removeTransitionWaypointGui()
Notifies WaypointTab and Transition to delete all ListWidgets.
void environmentChanged(EnvironmentPtr environment)
Set the enviroment.
void onInitComponent() override
void setActiveColModelName(QString activeColModelName)
Sets the active collision model name.
void enableIKSolutionButton(bool enable)
Enables or disables the new IK solution button.
void deleteWaypoint(int waypoint)
Deletes the given waypoint.
void undo()
Undo trajectroy.
TrajectoryController()
Creates a new TrajectoryController and assigns a QWidget to handle.
void updateTransition(int transition, int it)
Updates all values of a given transition.
void enableAdd(bool enable)
Enables or disables the add button/shortcut.
void enablePreviewAll(bool enable)
Enables or disables the prview all button/shortcut.
void addWaypointGui(int waypoint, std::vector< double > values, int cartesianSelection, bool isBreakpoint)
Notifies other controllers about the addition of a waypoint.
void cartesianSelectionChanged(VirtualRobot::IKSolver::CartesianSelection cs)
cartesianSelectionChanged recalculates the configuration of the robot joints to fit the new selection
void updateTCP(QString tcp)
Updates the selected TCP.
void onDisconnectComponent() override
void enableExportButtons(bool enable)
Enables or disables the export buttons.
void removeAllTrajectories()
Removes all trajectories from the TCP selection combo box.
void rnsChanged(VirtualRobot::RobotNodeSetPtr rns)
Notifies the VisualizationController about a changed RobotNodeSet.
void addWaypoint(int waypoint, bool insertAfter)
Adds a new waypoint relative to the given waypoint.
void updateSelectedTCP(QString trajectory)
Updates the currently displayed trajectory of the corresponding TCP.
void removeWaypointGui(int index)
Notifies other controllers about the deletion of a given waypoint.
void enableDeleteChange(bool enable)
Enables or disables the delete and change button/shortcut.
void exportTrajectory()
Stages the given trajectory for export.
void changeWaypointGui(int index, std::vector< double > values, int cartesianSelection, bool isBreakpoint)
Notfies other controllers about changes of an existing waypoint.
void changeTransitionGui(int transition, double duration, double start, int it)
Notifies other controllers about changes of an existing transition.
void redo()
Redo trajectory.
void enableUndo(bool enable)
Enables or disables the undo button/shortcut.
void onConnectComponent() override
void updateWaypoint(int waypoint, std::vector< double > values)
Updates all values of a given waypoint.
void enablePreview(bool enable)
Enables or disables the prview button/shortcut.
void removeTransitionGui(int index)
Notifies other controllers about the deletion of a given transtion.
void playTrajectories()
Play all trajectories.
void setBodyColModelsNames(QStringList bodyColModelsNames)
Sets the body collision models names.
void addTransitionGui(int transition, double duration, double start, int it)
Notifies other controllers about the addition of a transition.
void onExitComponent() override
void enableRedo(bool enable)
Enables or disables the redo button/shortcut.
void removeTrajectory(QString trajectory)
Removes the given trajectory from the TCP selection combo box.
void newTrajectory(QString trajectory)
Notifies the TCPSelcetionController about a new Trajectory.
void import(DesignerTrajectoryPtr designerTrajectory)
Imports a given trajectory into the model.
void showTrajectory(DesignerTrajectoryPtr designerTrajectory)
Provides the trajectory for VisualizationController.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
const VariantTypeId FramedPose
double s(double t, double s0, double v0, double a0, double j)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
std::shared_ptr< Environment > EnvironmentPtr
InterpolationType
The InterpolationType enum lists all available interpolation types eLinearInterpolation: represents l...
std::shared_ptr< Transition > TransitionPtr
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
std::shared_ptr< UserWaypoint > UserWaypointPtr