environment.cpp
Go to the documentation of this file.
1 
29 #include <boost/serialization/access.hpp>
30 #include <boost/serialization/nvp.hpp>
31 #include <boost/serialization/shared_ptr.hpp>
32 #include <boost/serialization/unique_ptr.hpp>
33 #include <boost/serialization/binary_object.hpp>
34 #include <boost/serialization/vector.hpp>
36 
41 
46 
48 
51 #include <tesseract_srdf/utils.h>
52 
58 
63 
66 
69 
72 
73 #include <console_bridge/console.h>
74 
75 #include <utility>
76 
77 namespace tesseract_environment
78 {
80 {
81 public:
82  EnvironmentContactAllowedValidator() = default; // Required for serialization
83  EnvironmentContactAllowedValidator(std::shared_ptr<const tesseract_scene_graph::SceneGraph> scene_graph)
84  : scene_graph_(std::move(scene_graph))
85  {
86  }
87 
88  bool operator()(const std::string& link_name1, const std::string& link_name2) const override
89  {
90  return scene_graph_->isCollisionAllowed(link_name1, link_name2);
91  }
92 
93 protected:
94  std::shared_ptr<const tesseract_scene_graph::SceneGraph> scene_graph_;
95 
96 private:
99  template <class Archive>
100  void serialize(Archive& ar, const unsigned int /*version*/) // NOLINT
101  {
102  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(ContactAllowedValidator);
103  ar& BOOST_SERIALIZATION_NVP(scene_graph_);
104  }
105 };
106 
107 void getCollisionObject(std::vector<std::shared_ptr<const tesseract_geometry::Geometry>>& shapes,
109  const tesseract_scene_graph::Link& link)
110 {
111  for (const auto& c : link.collision)
112  {
113  shapes.push_back(c->geometry);
114  shape_poses.push_back(c->origin);
115  }
116 }
117 
118 std::vector<std::shared_ptr<const Command>>
120  const std::shared_ptr<const tesseract_srdf::SRDFModel>& srdf_model = nullptr)
121 {
122  Commands commands;
123 
124  tesseract_scene_graph::SceneGraph::Ptr local_sg = scene_graph.clone();
125  if (local_sg == nullptr)
126  {
127  CONSOLE_BRIDGE_logError("Null pointer to Scene Graph");
128  return {};
129  }
130 
131  if (!local_sg->getLink(local_sg->getRoot()))
132  {
133  CONSOLE_BRIDGE_logError("The scene graph has an invalid root.");
134  return {};
135  }
136 
137  if (srdf_model != nullptr)
138  tesseract_srdf::processSRDFAllowedCollisions(*local_sg, *srdf_model);
139 
140  commands.push_back(std::make_shared<AddSceneGraphCommand>(*local_sg));
141 
142  if (srdf_model)
143  {
144  commands.push_back(std::make_shared<AddContactManagersPluginInfoCommand>(srdf_model->contact_managers_plugin_info));
145  commands.push_back(std::make_shared<AddKinematicsInformationCommand>(srdf_model->kinematics_information));
146 
147  // Apply calibration information
148  for (const auto& cal : srdf_model->calibration_info.joints)
149  commands.push_back(std::make_shared<ChangeJointOriginCommand>(cal.first, cal.second));
150 
151  // Check srdf for collision margin data
152  if (srdf_model->collision_margin_data)
153  {
154  commands.push_back(std::make_shared<ChangeCollisionMarginsCommand>(
155  srdf_model->collision_margin_data->getDefaultCollisionMargin(),
156  srdf_model->collision_margin_data->getCollisionMarginPairData(),
158  }
159  }
160 
161  return commands;
162 }
163 
165 {
166  ~Implementation() = default;
167 
172  bool initialized{ false };
173 
178  int revision{ 0 };
179 
181  int init_revision{ 0 };
182 
184  std::vector<std::shared_ptr<const Command>> commands{};
185 
190  std::shared_ptr<tesseract_scene_graph::SceneGraph> scene_graph{ nullptr };
191 
194 
196  std::chrono::system_clock::time_point timestamp{ std::chrono::system_clock::now() };
197 
199  std::chrono::system_clock::time_point current_state_timestamp{ std::chrono::system_clock::now() };
200 
205  std::unique_ptr<tesseract_scene_graph::MutableStateSolver> state_solver{ nullptr };
206 
211 
216  std::vector<FindTCPOffsetCallbackFn> find_tcp_cb{};
217 
222  std::map<std::size_t, EventCallbackFn> event_cb{};
223 
225  std::shared_ptr<const tesseract_common::ResourceLocator> resource_locator{ nullptr };
226 
232 
238 
244 
250 
256 
261  mutable std::unique_ptr<tesseract_collision::DiscreteContactManager> discrete_manager{ nullptr };
262  mutable std::shared_mutex discrete_manager_mutex;
263 
268  mutable std::unique_ptr<tesseract_collision::ContinuousContactManager> continuous_manager{ nullptr };
269  mutable std::shared_mutex continuous_manager_mutex;
270 
276  mutable std::unordered_map<std::string, std::vector<std::string>> group_joint_names_cache{};
277  mutable std::shared_mutex group_joint_names_cache_mutex;
278 
284  mutable std::unordered_map<std::string, std::shared_ptr<const tesseract_kinematics::JointGroup>> joint_group_cache{};
285  mutable std::shared_mutex joint_group_cache_mutex;
286 
292  mutable std::map<std::pair<std::string, std::string>, std::shared_ptr<const tesseract_kinematics::KinematicGroup>>
294  mutable std::shared_mutex kinematic_group_cache_mutex;
295 
296  bool operator==(const Implementation& rhs) const;
297 
298  bool initHelper(const std::vector<std::shared_ptr<const Command>>& commands);
299 
300  void setState(const std::unordered_map<std::string, double>& joints,
301  const tesseract_common::TransformMap& floating_joints = {});
302 
303  void setState(const std::vector<std::string>& joint_names,
304  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
305  const tesseract_common::TransformMap& floating_joints = {});
306 
307  void setState(const tesseract_common::TransformMap& floating_joints);
308 
309  Eigen::VectorXd getCurrentJointValues() const;
310 
311  Eigen::VectorXd getCurrentJointValues(const std::vector<std::string>& joint_names) const;
312 
314 
315  tesseract_common::TransformMap getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const;
316 
317  std::vector<std::string> getStaticLinkNames(const std::vector<std::string>& joint_names) const;
318 
319  void clear();
320 
321  bool reset();
322 
324  void currentStateChanged();
325 
327  void environmentChanged();
328 
331 
334 
336  void triggerCallbacks();
337 
338  std::vector<std::string> getGroupJointNames(const std::string& group_name) const;
339 
340  std::shared_ptr<const tesseract_kinematics::JointGroup> getJointGroup(const std::string& group_name) const;
341 
342  std::shared_ptr<const tesseract_kinematics::JointGroup>
343  getJointGroup(const std::string& name, const std::vector<std::string>& joint_names) const;
344 
345  std::shared_ptr<const tesseract_kinematics::KinematicGroup> getKinematicGroup(const std::string& group_name,
346  std::string ik_solver_name) const;
347 
348  Eigen::Isometry3d findTCPOffset(const tesseract_common::ManipulatorInfo& manip_info) const;
349 
350  std::unique_ptr<tesseract_collision::DiscreteContactManager> getDiscreteContactManager() const;
351 
352  std::unique_ptr<tesseract_collision::ContinuousContactManager> getContinuousContactManager() const;
353 
355 
357 
358  bool setActiveDiscreteContactManagerHelper(const std::string& name);
359 
360  bool setActiveContinuousContactManagerHelper(const std::string& name);
361 
362  std::unique_ptr<tesseract_collision::DiscreteContactManager>
363  getDiscreteContactManagerHelper(const std::string& name) const;
364 
365  std::unique_ptr<tesseract_collision::ContinuousContactManager>
366  getContinuousContactManagerHelper(const std::string& name) const;
367 
368  bool setActiveDiscreteContactManager(const std::string& name);
369 
370  std::unique_ptr<tesseract_collision::DiscreteContactManager> getDiscreteContactManager(const std::string& name) const;
371 
372  bool setActiveContinuousContactManager(const std::string& name);
373 
374  std::unique_ptr<tesseract_collision::ContinuousContactManager>
375  getContinuousContactManager(const std::string& name) const;
376 
377  bool removeLinkHelper(const std::string& name);
378 
380  bool applyCommandsHelper(const std::vector<std::shared_ptr<const Command>>& commands);
381 
382  // Command Helper function
383  bool applyAddCommand(const std::shared_ptr<const AddLinkCommand>& cmd);
384  bool applyMoveLinkCommand(const std::shared_ptr<const MoveLinkCommand>& cmd);
385  bool applyMoveJointCommand(const std::shared_ptr<const MoveJointCommand>& cmd);
386  bool applyRemoveLinkCommand(const std::shared_ptr<const RemoveLinkCommand>& cmd);
387  bool applyRemoveJointCommand(const std::shared_ptr<const RemoveJointCommand>& cmd);
388  bool applyReplaceJointCommand(const std::shared_ptr<const ReplaceJointCommand>& cmd);
389  bool applyChangeLinkOriginCommand(const std::shared_ptr<const ChangeLinkOriginCommand>& cmd);
390  bool applyChangeJointOriginCommand(const std::shared_ptr<const ChangeJointOriginCommand>& cmd);
391  bool applyChangeLinkCollisionEnabledCommand(const std::shared_ptr<const ChangeLinkCollisionEnabledCommand>& cmd);
392  bool applyChangeLinkVisibilityCommand(const std::shared_ptr<const ChangeLinkVisibilityCommand>& cmd);
393  bool applyModifyAllowedCollisionsCommand(const std::shared_ptr<const ModifyAllowedCollisionsCommand>& cmd);
394  bool applyRemoveAllowedCollisionLinkCommand(const std::shared_ptr<const RemoveAllowedCollisionLinkCommand>& cmd);
395  bool applyAddSceneGraphCommand(std::shared_ptr<const AddSceneGraphCommand> cmd);
396  bool applyChangeJointPositionLimitsCommand(const std::shared_ptr<const ChangeJointPositionLimitsCommand>& cmd);
397  bool applyChangeJointVelocityLimitsCommand(const std::shared_ptr<const ChangeJointVelocityLimitsCommand>& cmd);
398  bool
399  applyChangeJointAccelerationLimitsCommand(const std::shared_ptr<const ChangeJointAccelerationLimitsCommand>& cmd);
400  bool applyAddKinematicsInformationCommand(const std::shared_ptr<const AddKinematicsInformationCommand>& cmd);
401  bool applyChangeCollisionMarginsCommand(const std::shared_ptr<const ChangeCollisionMarginsCommand>& cmd);
402  bool applyAddContactManagersPluginInfoCommand(const std::shared_ptr<const AddContactManagersPluginInfoCommand>& cmd);
404  const std::shared_ptr<const SetActiveContinuousContactManagerCommand>& cmd);
405  bool
406  applySetActiveDiscreteContactManagerCommand(const std::shared_ptr<const SetActiveDiscreteContactManagerCommand>& cmd);
407  bool applyAddTrajectoryLinkCommand(const std::shared_ptr<const AddTrajectoryLinkCommand>& cmd);
408 
409  bool applyAddLinkCommandHelper(const std::shared_ptr<const tesseract_scene_graph::Link>& link,
410  const std::shared_ptr<const tesseract_scene_graph::Joint>& joint,
411  bool replace_allowed);
412 
413  std::unique_ptr<Implementation> clone() const;
414 
417  template <class Archive>
418  void save(Archive& ar, const unsigned int /*version*/) const // NOLINT
419  {
420  ar& BOOST_SERIALIZATION_NVP(resource_locator);
421  ar& BOOST_SERIALIZATION_NVP(commands);
422  ar& BOOST_SERIALIZATION_NVP(init_revision);
423  ar& BOOST_SERIALIZATION_NVP(current_state);
424  // No need to serialize the contact allowed validator because it cannot be modified and is constructed internally
425  // from the scene graph
426  ar& boost::serialization::make_nvp("timestamp",
427  boost::serialization::make_binary_object(&timestamp, sizeof(timestamp)));
428  ar& boost::serialization::make_nvp(
429  "current_state_timestamp",
430  boost::serialization::make_binary_object(&current_state_timestamp, sizeof(current_state_timestamp)));
431  }
432 
433  template <class Archive>
434  void load(Archive& ar, const unsigned int /*version*/) // NOLINT
435  {
436  ar& BOOST_SERIALIZATION_NVP(resource_locator);
437 
439  ar& boost::serialization::make_nvp("commands", commands);
441 
442  ar& BOOST_SERIALIZATION_NVP(init_revision);
443 
445  ar& boost::serialization::make_nvp("current_state", current_state);
447 
448  // No need to serialize the contact allowed validator because it cannot be modified and is constructed internally
449  // from the scene graph
450 
451  ar& boost::serialization::make_nvp("timestamp",
452  boost::serialization::make_binary_object(&timestamp, sizeof(timestamp)));
453  ar& boost::serialization::make_nvp(
454  "current_state_timestamp",
455  boost::serialization::make_binary_object(&current_state_timestamp, sizeof(current_state_timestamp)));
456  }
457 
458  template <class Archive>
459  void serialize(Archive& ar, const unsigned int version) // NOLINT
460  {
461  boost::serialization::split_member(ar, *this, version);
462  }
463 };
464 
466 {
467  // No need to check everything mainly the items serialized
468  bool equal = true;
469  equal &= initialized == rhs.initialized;
470  equal &= revision == rhs.revision;
471  equal &= init_revision == rhs.init_revision;
472  equal &= commands.size() == rhs.commands.size();
473  if (!equal)
474  return equal;
475 
476  for (std::size_t i = 0; i < commands.size(); ++i)
477  {
478  equal &= *(commands[i]) == *(rhs.commands[i]);
479  if (!equal)
480  return equal;
481  }
482 
483  equal &= current_state == rhs.current_state;
484  equal &= timestamp == rhs.timestamp;
486 
487  // No need to check contact_allowed validator because it is constructed internally from the scene graph and cannot be
488  // changed
489 
491  // equal &= find_tcp_cb == rhs.find_tcp_cb;
492 
493  return equal;
494 }
495 
496 std::unique_ptr<Environment::Implementation> Environment::Implementation::clone() const
497 {
498  auto cloned_env = std::make_unique<Implementation>();
499 
500  std::shared_lock<std::shared_mutex> jg_lock(joint_group_cache_mutex);
501  std::shared_lock<std::shared_mutex> kg_lock(kinematic_group_cache_mutex);
502  std::shared_lock<std::shared_mutex> jn_lock(group_joint_names_cache_mutex);
503  std::shared_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
504  std::shared_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
505 
506  if (!initialized)
507  return cloned_env;
508 
509  cloned_env->initialized = initialized;
510  cloned_env->init_revision = init_revision;
511  cloned_env->revision = revision;
512  cloned_env->commands = commands;
513  cloned_env->scene_graph = scene_graph->clone();
514  cloned_env->timestamp = timestamp;
515  cloned_env->current_state = current_state;
516  cloned_env->current_state_timestamp = current_state_timestamp;
517 
518  // There is not dynamic pointer cast for std::unique_ptr
519  auto cloned_solver = state_solver->clone();
520  auto* p = dynamic_cast<tesseract_scene_graph::MutableStateSolver*>(cloned_solver.get());
521  if (p != nullptr)
522  (void)cloned_solver.release();
523 
524  cloned_env->state_solver = std::unique_ptr<tesseract_scene_graph::MutableStateSolver>(p);
525  cloned_env->kinematics_information = kinematics_information;
526  cloned_env->kinematics_factory = kinematics_factory;
527  cloned_env->find_tcp_cb = find_tcp_cb;
528  cloned_env->collision_margin_data = collision_margin_data;
529 
530  // Copy cache
531  cloned_env->joint_group_cache = joint_group_cache;
532  cloned_env->kinematic_group_cache = kinematic_group_cache;
533  cloned_env->group_joint_names_cache = group_joint_names_cache;
534 
535  // NOLINTNEXTLINE
536  cloned_env->contact_allowed_validator = std::make_shared<EnvironmentContactAllowedValidator>(cloned_env->scene_graph);
537 
538  if (discrete_manager)
539  {
540  cloned_env->discrete_manager = discrete_manager->clone();
541  cloned_env->discrete_manager->setContactAllowedValidator(cloned_env->contact_allowed_validator);
542  }
543  if (continuous_manager)
544  {
545  cloned_env->continuous_manager = continuous_manager->clone();
546  cloned_env->continuous_manager->setContactAllowedValidator(cloned_env->contact_allowed_validator);
547  }
548 
549  cloned_env->contact_managers_plugin_info = contact_managers_plugin_info;
550  cloned_env->contact_managers_factory = contact_managers_factory;
551 
552  return cloned_env;
553 }
554 
555 bool Environment::Implementation::initHelper(const std::vector<std::shared_ptr<const Command>>& commands)
556 {
557  if (commands.empty())
558  return false;
559 
560  if (commands.at(0)->getType() != CommandType::ADD_SCENE_GRAPH)
561  {
562  CONSOLE_BRIDGE_logError("When initializing environment from command history the first command must be type "
563  "ADD_SCENE_GRAPH!");
564  return false;
565  }
566 
567  clear();
568 
569  scene_graph = std::make_shared<tesseract_scene_graph::SceneGraph>(
570  std::static_pointer_cast<const AddSceneGraphCommand>(commands.at(0))->getSceneGraph()->getName());
571 
572  contact_allowed_validator = std::make_shared<EnvironmentContactAllowedValidator>(scene_graph);
573 
574  if (!applyCommandsHelper(commands))
575  {
576  CONSOLE_BRIDGE_logError("When initializing environment from command history, it failed to apply a command!");
577  return false;
578  }
579 
580  initialized = true;
581  init_revision = revision;
582 
583  environmentChanged();
584 
585  return initialized;
586 }
587 
588 void Environment::Implementation::setState(const std::unordered_map<std::string, double>& joints,
589  const tesseract_common::TransformMap& floating_joints)
590 {
591  state_solver->setState(joints, floating_joints);
592  currentStateChanged();
593 }
594 
595 void Environment::Implementation::setState(const std::vector<std::string>& joint_names,
596  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
597  const tesseract_common::TransformMap& floating_joints)
598 {
599  state_solver->setState(joint_names, joint_values, floating_joints);
600  currentStateChanged();
601 }
602 
604 {
605  state_solver->setState(floating_joints);
606  currentStateChanged();
607 }
608 
610 {
611  Eigen::VectorXd jv;
612  std::vector<std::string> active_joint_names = state_solver->getActiveJointNames();
613  jv.resize(static_cast<long int>(active_joint_names.size()));
614  for (auto j = 0U; j < active_joint_names.size(); ++j)
615  jv(j) = current_state.joints.at(active_joint_names[j]);
616 
617  return jv;
618 }
619 
620 Eigen::VectorXd Environment::Implementation::getCurrentJointValues(const std::vector<std::string>& joint_names) const
621 {
622  Eigen::VectorXd jv;
623  jv.resize(static_cast<long int>(joint_names.size()));
624  for (auto j = 0U; j < joint_names.size(); ++j)
625  jv(j) = current_state.joints.at(joint_names[j]);
626 
627  return jv;
628 }
629 
631 {
632  return current_state.floating_joints;
633 }
634 
636 Environment::Implementation::getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const
637 {
639  for (const auto& joint_name : joint_names)
640  fjv[joint_name] = current_state.floating_joints.at(joint_name);
641 
642  return fjv;
643 }
644 
645 std::vector<std::string>
646 Environment::Implementation::getStaticLinkNames(const std::vector<std::string>& joint_names) const
647 {
648  std::vector<std::string> active_link_names = scene_graph->getJointChildrenNames(joint_names);
649  std::vector<std::string> full_link_names = state_solver->getLinkNames();
650  std::vector<std::string> static_link_names;
651  static_link_names.reserve(full_link_names.size());
652 
653  std::sort(active_link_names.begin(), active_link_names.end());
654  std::sort(full_link_names.begin(), full_link_names.end());
655 
656  std::set_difference(full_link_names.begin(),
657  full_link_names.end(),
658  active_link_names.begin(),
659  active_link_names.end(),
660  std::inserter(static_link_names, static_link_names.begin()));
661 
662  return static_link_names;
663 }
664 
666 {
667  initialized = false;
668  revision = 0;
669  init_revision = 0;
670  scene_graph = nullptr;
671  state_solver = nullptr;
672  current_state = tesseract_scene_graph::SceneState();
673  commands.clear();
674  contact_allowed_validator = nullptr;
675  collision_margin_data = tesseract_collision::CollisionMarginData();
676  kinematics_information.clear();
677  contact_managers_plugin_info.clear();
678 
679  {
680  std::unique_lock<std::shared_mutex> lock(discrete_manager_mutex);
681  discrete_manager = nullptr;
682  }
683 
684  {
685  std::unique_lock<std::shared_mutex> lock(continuous_manager_mutex);
686  continuous_manager = nullptr;
687  }
688 
689  {
690  std::unique_lock<std::shared_mutex> lock(group_joint_names_cache_mutex);
691  group_joint_names_cache.clear();
692  }
693 
694  {
695  std::unique_lock<std::shared_mutex> lock(joint_group_cache_mutex);
696  joint_group_cache.clear();
697  }
698 
699  {
700  std::unique_lock<std::shared_mutex> lock(kinematic_group_cache_mutex);
701  kinematic_group_cache.clear();
702  }
703 
704  // Must clear cache before deleting plugin factories
705  kinematics_factory = tesseract_kinematics::KinematicsPluginFactory();
706  contact_managers_factory = tesseract_collision::ContactManagersPluginFactory();
707 }
708 
710 {
711  Commands init_command;
712  if (commands.empty() || !initialized)
713  return false;
714 
715  init_command.reserve(static_cast<std::size_t>(init_revision));
716  for (std::size_t i = 0; i < static_cast<std::size_t>(init_revision); ++i)
717  init_command.push_back(commands[i]);
718 
719  return initHelper(init_command);
720 }
721 
723 {
724  timestamp = std::chrono::system_clock::now();
725  current_state_timestamp = timestamp;
726  current_state = state_solver->getState();
727 
728  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
729  if (discrete_manager != nullptr)
730  discrete_manager->setCollisionObjectsTransform(current_state.link_transforms);
731 
732  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
733  if (continuous_manager != nullptr)
734  {
735  std::vector<std::string> active_link_names = state_solver->getActiveLinkNames();
736  for (const auto& tf : current_state.link_transforms)
737  {
738  if (std::find(active_link_names.begin(), active_link_names.end(), tf.first) != active_link_names.end())
739  continuous_manager->setCollisionObjectsTransform(tf.first, tf.second, tf.second);
740  else
741  continuous_manager->setCollisionObjectsTransform(tf.first, tf.second);
742  }
743  }
744 
745  { // Clear JointGroup and KinematicGroup
746  std::unique_lock<std::shared_mutex> jg_lock(joint_group_cache_mutex);
747  std::unique_lock<std::shared_mutex> kg_lock(kinematic_group_cache_mutex);
748  joint_group_cache.clear();
749  kinematic_group_cache.clear();
750  }
751 }
752 
754 {
755  timestamp = std::chrono::system_clock::now();
756  std::vector<std::string> active_link_names = state_solver->getActiveLinkNames();
757 
758  {
759  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
760  if (discrete_manager != nullptr)
761  discrete_manager->setActiveCollisionObjects(active_link_names);
762  }
763 
764  {
765  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
766  if (continuous_manager != nullptr)
767  continuous_manager->setActiveCollisionObjects(active_link_names);
768  }
769 
770  { // Clear JointGroup, KinematicGroup and GroupJointNames cache
771  std::unique_lock<std::shared_mutex> jn_lock(group_joint_names_cache_mutex);
772  group_joint_names_cache.clear();
773  }
774 
775  currentStateChanged();
776 }
777 
779 {
780  if (!event_cb.empty())
781  {
782  SceneStateChangedEvent event(current_state);
783  for (const auto& cb : event_cb)
784  cb.second(event);
785  }
786 }
787 
789 {
790  if (!event_cb.empty())
791  {
792  CommandAppliedEvent event(commands, revision);
793  for (const auto& cb : event_cb)
794  cb.second(event);
795  }
796 }
797 
799 {
800  triggerEnvironmentChangedCallbacks();
801  triggerCurrentStateChangedCallbacks();
802 }
803 
804 std::vector<std::string> Environment::Implementation::getGroupJointNames(const std::string& group_name) const
805 {
806  auto it = std::find(kinematics_information.group_names.begin(), kinematics_information.group_names.end(), group_name);
807 
808  if (it == kinematics_information.group_names.end())
809  throw std::runtime_error("Environment, Joint group '" + group_name + "' does not exist!");
810 
811  std::unique_lock<std::shared_mutex> cache_lock(group_joint_names_cache_mutex);
812  auto cache_it = group_joint_names_cache.find(group_name);
813  if (cache_it != group_joint_names_cache.end())
814  return cache_it->second;
815 
816  auto chain_it = kinematics_information.chain_groups.find(group_name);
817  if (chain_it != kinematics_information.chain_groups.end())
818  {
819  if (chain_it->second.size() > 1)
820  throw std::runtime_error("Environment, Groups with multiple chains is not supported!");
821 
823  scene_graph->getShortestPath(chain_it->second.begin()->first, chain_it->second.begin()->second);
824 
825  group_joint_names_cache[group_name] = path.active_joints;
826  return path.active_joints;
827  }
828 
829  auto joint_it = kinematics_information.joint_groups.find(group_name);
830  if (joint_it != kinematics_information.joint_groups.end())
831  {
832  group_joint_names_cache[group_name] = joint_it->second;
833  return joint_it->second;
834  }
835 
836  auto link_it = kinematics_information.link_groups.find(group_name);
837  if (link_it != kinematics_information.link_groups.end())
838  throw std::runtime_error("Environment, Link groups are currently not supported!");
839 
840  throw std::runtime_error("Environment, failed to get group '" + group_name + "' joint names!");
841 }
842 
843 std::shared_ptr<const tesseract_kinematics::JointGroup>
844 Environment::Implementation::getJointGroup(const std::string& group_name) const
845 {
846  std::unique_lock<std::shared_mutex> cache_lock(joint_group_cache_mutex);
847  auto it = joint_group_cache.find(group_name);
848  if (it != joint_group_cache.end())
849  return it->second;
850 
851  // Store copy in cache and return
852  std::vector<std::string> joint_names = getGroupJointNames(group_name);
853  tesseract_kinematics::JointGroup::ConstPtr jg = getJointGroup(group_name, joint_names);
854  joint_group_cache[group_name] = jg;
855 
856  return jg;
857 }
858 
859 std::shared_ptr<const tesseract_kinematics::JointGroup>
860 Environment::Implementation::getJointGroup(const std::string& name, const std::vector<std::string>& joint_names) const
861 {
862  return std::make_shared<tesseract_kinematics::JointGroup>(name, joint_names, *scene_graph, current_state);
863 }
864 
865 std::shared_ptr<const tesseract_kinematics::KinematicGroup>
866 Environment::Implementation::getKinematicGroup(const std::string& group_name, std::string ik_solver_name) const
867 {
868  std::unique_lock<std::shared_mutex> cache_lock(kinematic_group_cache_mutex);
869  std::pair<std::string, std::string> key = std::make_pair(group_name, ik_solver_name);
870  auto it = kinematic_group_cache.find(key);
871  if (it != kinematic_group_cache.end())
872  return it->second;
873 
874  std::vector<std::string> joint_names = getGroupJointNames(group_name);
875 
876  if (ik_solver_name.empty())
877  ik_solver_name = kinematics_factory.getDefaultInvKinPlugin(group_name);
878 
880  kinematics_factory.createInvKin(group_name, ik_solver_name, *scene_graph, current_state);
881 
882  // TODO add error message
883  if (inv_kin == nullptr)
884  return nullptr;
885 
886  // Store copy in cache and return
887  auto kg = std::make_shared<tesseract_kinematics::KinematicGroup>(
888  group_name, joint_names, std::move(inv_kin), *scene_graph, current_state);
889 
890  kinematic_group_cache[key] = kg;
891 
892 #if !defined(NDEBUG) && TESSERACT_ENABLE_TESTING
894  {
895  CONSOLE_BRIDGE_logError("Check Kinematics failed. This means that inverse kinematics solution for a pose do not "
896  "match forward kinematics solution. Did you change the URDF recently?");
897  }
898 #endif
899 
900  return kg;
901 }
902 
904 {
905  // If it is already an Isometry3d return the offset
906  if (manip_info.tcp_offset.index() != 0)
907  return std::get<1>(manip_info.tcp_offset);
908 
909  // Check if the tcp offset name is a link in the scene, if so throw an exception
910  const std::string& tcp_offset_name = std::get<0>(manip_info.tcp_offset);
911  if (state_solver->hasLinkName(tcp_offset_name))
912  throw std::runtime_error("The tcp offset name '" + tcp_offset_name +
913  "' should not be an existing link in the scene. Assign it as the tcp_frame instead!");
914 
915  // Check Manipulator Manager for TCP
916  if (kinematics_information.hasGroupTCP(manip_info.manipulator, tcp_offset_name))
917  return kinematics_information.group_tcps.at(manip_info.manipulator).at(tcp_offset_name);
918 
919  // Check callbacks for TCP Offset
920  for (const auto& fn : find_tcp_cb)
921  {
922  try
923  {
924  Eigen::Isometry3d tcp = fn(manip_info);
925  return tcp;
926  }
927  catch (...)
928  {
929  CONSOLE_BRIDGE_logDebug("User Defined Find TCP Callback Failed!");
930  }
931  }
932 
933  throw std::runtime_error("Could not find tcp by name " + tcp_offset_name + "'!");
934 }
935 
936 std::unique_ptr<tesseract_collision::DiscreteContactManager>
938 {
939  { // Clone cached manager if exists
940  std::shared_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
941  if (discrete_manager)
942  return discrete_manager->clone();
943  }
944 
945  { // Try to create the default plugin
946  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
947  const std::string& name = contact_managers_plugin_info.discrete_plugin_infos.default_plugin;
948  discrete_manager = getDiscreteContactManagerHelper(name);
949  if (discrete_manager == nullptr)
950  {
951  CONSOLE_BRIDGE_logError("Discrete manager with %s does not exist in factory!", name.c_str());
952  return nullptr;
953  }
954  }
955 
956  return discrete_manager->clone();
957 }
958 
959 std::unique_ptr<tesseract_collision::ContinuousContactManager>
961 {
962  { // Clone cached manager if exists
963  std::shared_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
964  if (continuous_manager)
965  return continuous_manager->clone();
966  }
967 
968  { // Try to create the default plugin
969  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
970  const std::string& name = contact_managers_plugin_info.continuous_plugin_infos.default_plugin;
971  continuous_manager = getContinuousContactManagerHelper(name);
972  if (continuous_manager == nullptr)
973  {
974  CONSOLE_BRIDGE_logError("Continuous manager with %s does not exist in factory!", name.c_str());
975  return nullptr;
976  }
977  }
978 
979  return continuous_manager->clone();
980 }
981 
983 {
984  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
985  discrete_manager = nullptr;
986 }
987 
989 {
990  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
991  continuous_manager = nullptr;
992 }
993 
995 {
996  tesseract_collision::DiscreteContactManager::UPtr manager = getDiscreteContactManagerHelper(name);
997  if (manager == nullptr)
998  {
999  std::string msg = "\n Discrete manager with " + name + " does not exist in factory!\n";
1000  msg += " Available Managers:\n";
1001  for (const auto& m : contact_managers_factory.getDiscreteContactManagerPlugins())
1002  msg += " " + m.first + "\n";
1003 
1004  CONSOLE_BRIDGE_logError(msg.c_str());
1005  return false;
1006  }
1007 
1008  contact_managers_plugin_info.discrete_plugin_infos.default_plugin = name;
1009 
1010  // The calling function should be locking discrete_manager_mutex_
1011  discrete_manager = std::move(manager);
1012 
1013  return true;
1014 }
1015 
1017 {
1018  tesseract_collision::ContinuousContactManager::UPtr manager = getContinuousContactManagerHelper(name);
1019 
1020  if (manager == nullptr)
1021  {
1022  std::string msg = "\n Continuous manager with " + name + " does not exist in factory!\n";
1023  msg += " Available Managers:\n";
1024  for (const auto& m : contact_managers_factory.getContinuousContactManagerPlugins())
1025  msg += " " + m.first + "\n";
1026 
1027  CONSOLE_BRIDGE_logError(msg.c_str());
1028  return false;
1029  }
1030 
1031  contact_managers_plugin_info.continuous_plugin_infos.default_plugin = name;
1032 
1033  // The calling function should be locking continuous_manager_mutex_
1034  continuous_manager = std::move(manager);
1035 
1036  return true;
1037 }
1038 
1039 std::unique_ptr<tesseract_collision::DiscreteContactManager>
1041 {
1043  contact_managers_factory.createDiscreteContactManager(name);
1044  if (manager == nullptr)
1045  return nullptr;
1046 
1047  manager->setContactAllowedValidator(contact_allowed_validator);
1048  if (scene_graph != nullptr)
1049  {
1050  for (const auto& link : scene_graph->getLinks())
1051  {
1052  if (!link->collision.empty())
1053  {
1056  getCollisionObject(shapes, shape_poses, *link);
1057  manager->addCollisionObject(link->getName(), 0, shapes, shape_poses, true);
1058  }
1059  }
1060 
1061  manager->setActiveCollisionObjects(state_solver->getActiveLinkNames());
1062  }
1063 
1064  manager->setCollisionMarginData(collision_margin_data);
1065 
1066  manager->setCollisionObjectsTransform(current_state.link_transforms);
1067 
1068  return manager;
1069 }
1070 
1071 std::unique_ptr<tesseract_collision::ContinuousContactManager>
1073 {
1075  contact_managers_factory.createContinuousContactManager(name);
1076 
1077  if (manager == nullptr)
1078  return nullptr;
1079 
1080  manager->setContactAllowedValidator(contact_allowed_validator);
1081  if (scene_graph != nullptr)
1082  {
1083  for (const auto& link : scene_graph->getLinks())
1084  {
1085  if (!link->collision.empty())
1086  {
1089  getCollisionObject(shapes, shape_poses, *link);
1090  manager->addCollisionObject(link->getName(), 0, shapes, shape_poses, true);
1091  }
1092  }
1093 
1094  manager->setActiveCollisionObjects(state_solver->getActiveLinkNames());
1095  }
1096 
1097  manager->setCollisionMarginData(collision_margin_data);
1098 
1099  std::vector<std::string> active_link_names = state_solver->getActiveLinkNames();
1100  for (const auto& tf : current_state.link_transforms)
1101  {
1102  if (std::find(active_link_names.begin(), active_link_names.end(), tf.first) != active_link_names.end())
1103  manager->setCollisionObjectsTransform(tf.first, tf.second, tf.second);
1104  else
1105  manager->setCollisionObjectsTransform(tf.first, tf.second);
1106  }
1107 
1108  return manager;
1109 }
1110 
1112 {
1113  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1114  return setActiveDiscreteContactManagerHelper(name);
1115 }
1116 
1117 std::unique_ptr<tesseract_collision::DiscreteContactManager>
1119 {
1120  tesseract_collision::DiscreteContactManager::UPtr manager = getDiscreteContactManagerHelper(name);
1121  if (manager == nullptr)
1122  {
1123  CONSOLE_BRIDGE_logError("Discrete manager with %s does not exist in factory!", name.c_str());
1124  return nullptr;
1125  }
1126 
1127  return manager;
1128 }
1129 
1131 {
1132  std::unique_lock<std::shared_mutex> continous_lock(continuous_manager_mutex);
1133  return setActiveContinuousContactManagerHelper(name);
1134 }
1135 
1136 std::unique_ptr<tesseract_collision::ContinuousContactManager>
1138 {
1139  tesseract_collision::ContinuousContactManager::UPtr manager = getContinuousContactManagerHelper(name);
1140  if (manager == nullptr)
1141  {
1142  CONSOLE_BRIDGE_logError("Continuous manager with %s does not exist in factory!", name.c_str());
1143  return nullptr;
1144  }
1145 
1146  return manager;
1147 }
1148 
1150 {
1151  if (scene_graph->getLink(name) == nullptr)
1152  {
1153  CONSOLE_BRIDGE_logWarn("Tried to remove link (%s) that does not exist", name.c_str());
1154  return false;
1155  }
1156  std::vector<tesseract_scene_graph::Joint::ConstPtr> joints = scene_graph->getInboundJoints(name);
1157  assert(joints.size() <= 1);
1158 
1159  // get child link names to remove
1160  std::vector<std::string> child_link_names = scene_graph->getLinkChildrenNames(name);
1161 
1162  scene_graph->removeLink(name, true);
1163 
1164  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1165  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1166  if (discrete_manager != nullptr)
1167  discrete_manager->removeCollisionObject(name);
1168  if (continuous_manager != nullptr)
1169  continuous_manager->removeCollisionObject(name);
1170 
1171  for (const auto& link_name : child_link_names)
1172  {
1173  if (discrete_manager != nullptr)
1174  discrete_manager->removeCollisionObject(link_name);
1175  if (continuous_manager != nullptr)
1176  continuous_manager->removeCollisionObject(link_name);
1177  }
1178 
1179  return true;
1180 }
1181 
1182 bool Environment::Implementation::applyCommandsHelper(const std::vector<std::shared_ptr<const Command>>& commands)
1183 {
1184  bool success = true;
1185  for (const auto& command : commands)
1186  {
1187  if (!command)
1188  {
1189  success = false;
1190  break;
1191  }
1192 
1193  switch (command->getType())
1194  {
1196  {
1197  auto cmd = std::static_pointer_cast<const AddLinkCommand>(command);
1198  success &= applyAddCommand(cmd);
1199  break;
1200  }
1202  {
1203  auto cmd = std::static_pointer_cast<const MoveLinkCommand>(command);
1204  success &= applyMoveLinkCommand(cmd);
1205  break;
1206  }
1208  {
1209  auto cmd = std::static_pointer_cast<const MoveJointCommand>(command);
1210  success &= applyMoveJointCommand(cmd);
1211  break;
1212  }
1214  {
1215  auto cmd = std::static_pointer_cast<const RemoveLinkCommand>(command);
1216  success &= applyRemoveLinkCommand(cmd);
1217  break;
1218  }
1220  {
1221  auto cmd = std::static_pointer_cast<const RemoveJointCommand>(command);
1222  success &= applyRemoveJointCommand(cmd);
1223  break;
1224  }
1226  {
1227  auto cmd = std::static_pointer_cast<const ReplaceJointCommand>(command);
1228  success &= applyReplaceJointCommand(cmd);
1229  break;
1230  }
1232  {
1233  auto cmd = std::static_pointer_cast<const ChangeLinkOriginCommand>(command);
1234  success &= applyChangeLinkOriginCommand(cmd);
1235  break;
1236  }
1238  {
1239  auto cmd = std::static_pointer_cast<const ChangeJointOriginCommand>(command);
1240  success &= applyChangeJointOriginCommand(cmd);
1241  break;
1242  }
1244  {
1245  auto cmd = std::static_pointer_cast<const ChangeLinkCollisionEnabledCommand>(command);
1246  success &= applyChangeLinkCollisionEnabledCommand(cmd);
1247  break;
1248  }
1250  {
1251  auto cmd = std::static_pointer_cast<const ChangeLinkVisibilityCommand>(command);
1252  success &= applyChangeLinkVisibilityCommand(cmd);
1253  break;
1254  }
1256  {
1257  auto cmd = std::static_pointer_cast<const ModifyAllowedCollisionsCommand>(command);
1258  success &= applyModifyAllowedCollisionsCommand(cmd);
1259  break;
1260  }
1262  {
1263  auto cmd = std::static_pointer_cast<const RemoveAllowedCollisionLinkCommand>(command);
1264  success &= applyRemoveAllowedCollisionLinkCommand(cmd);
1265  break;
1266  }
1268  {
1269  auto cmd = std::static_pointer_cast<const AddSceneGraphCommand>(command);
1270  success &= applyAddSceneGraphCommand(cmd);
1271  break;
1272  }
1274  {
1275  auto cmd = std::static_pointer_cast<const ChangeJointPositionLimitsCommand>(command);
1276  success &= applyChangeJointPositionLimitsCommand(cmd);
1277  break;
1278  }
1280  {
1281  auto cmd = std::static_pointer_cast<const ChangeJointVelocityLimitsCommand>(command);
1282  success &= applyChangeJointVelocityLimitsCommand(cmd);
1283  break;
1284  }
1286  {
1287  auto cmd = std::static_pointer_cast<const ChangeJointAccelerationLimitsCommand>(command);
1288  success &= applyChangeJointAccelerationLimitsCommand(cmd);
1289  break;
1290  }
1292  {
1293  auto cmd = std::static_pointer_cast<const AddKinematicsInformationCommand>(command);
1294  success &= applyAddKinematicsInformationCommand(cmd);
1295  break;
1296  }
1298  {
1299  auto cmd = std::static_pointer_cast<const ChangeCollisionMarginsCommand>(command);
1300  success &= applyChangeCollisionMarginsCommand(cmd);
1301  break;
1302  }
1304  {
1305  auto cmd = std::static_pointer_cast<const AddContactManagersPluginInfoCommand>(command);
1306  success &= applyAddContactManagersPluginInfoCommand(cmd);
1307  break;
1308  }
1310  {
1311  auto cmd = std::static_pointer_cast<const SetActiveContinuousContactManagerCommand>(command);
1312  success &= applySetActiveContinuousContactManagerCommand(cmd);
1313  break;
1314  }
1316  {
1317  auto cmd = std::static_pointer_cast<const SetActiveDiscreteContactManagerCommand>(command);
1318  success &= applySetActiveDiscreteContactManagerCommand(cmd);
1319  break;
1320  }
1322  {
1323  auto cmd = std::static_pointer_cast<const AddTrajectoryLinkCommand>(command);
1324  success &= applyAddTrajectoryLinkCommand(cmd);
1325  break;
1326  }
1327  // LCOV_EXCL_START
1328  default:
1329  {
1330  CONSOLE_BRIDGE_logError("Unhandled environment command");
1331  success &= false;
1332  }
1333  // LCOV_EXCL_STOP
1334  }
1335 
1336  if (!success)
1337  break;
1338  }
1339 
1340  // Update the solver revision to match environment
1341  state_solver->setRevision(revision);
1342 
1343  // If this is not true then the initHelper function has called applyCommand so do not call.
1344  if (initialized)
1345  environmentChanged();
1346 
1347  return success;
1348 }
1349 
1353 
1355 {
1356  // The command should not allow this to occur but adding an assert to catch if something changes
1357  assert(!(!cmd->getLink() && !cmd->getJoint())); // NOLINT
1358  assert(!((cmd->getLink() != nullptr) && (cmd->getJoint() != nullptr) &&
1359  (cmd->getJoint()->child_link_name != cmd->getLink()->getName())));
1360 
1361  if (!applyAddLinkCommandHelper(cmd->getLink(), cmd->getJoint(), cmd->replaceAllowed()))
1362  return false;
1363 
1364  ++revision;
1365  commands.push_back(cmd);
1366 
1367  return true;
1368 }
1369 
1371 {
1372  const tesseract_common::JointTrajectory& traj = cmd->getTrajectory();
1373  if (traj.empty())
1374  return false;
1375 
1376  if (cmd->getLinkName().empty())
1377  {
1378  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link with empty link name.");
1379  return false;
1380  }
1381 
1382  if (cmd->getParentLinkName().empty())
1383  {
1384  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link with empty parent link name.");
1385  return false;
1386  }
1387 
1388  const bool parent_link_exists = (scene_graph->getLink(cmd->getParentLinkName()) != nullptr);
1389  if (!parent_link_exists)
1390  {
1391  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link (%s) with parent link (%s) which does not exists.",
1392  cmd->getLinkName().c_str(),
1393  cmd->getParentLinkName().c_str());
1394  return false;
1395  }
1396 
1397  auto state_solver_clone = state_solver->clone();
1398 
1399  auto traj_link = std::make_shared<tesseract_scene_graph::Link>(cmd->getLinkName());
1400  std::vector<std::string> joint_names;
1401  std::vector<std::string> active_link_names;
1402  for (const auto& state : traj)
1403  {
1404  if (state.joint_names.empty())
1405  {
1406  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link (%s) with empty joint names.", cmd->getLinkName().c_str());
1407  return false;
1408  }
1409 
1410  if (state.position.rows() == 0)
1411  {
1412  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link (%s) with empty position.", cmd->getLinkName().c_str());
1413  return false;
1414  }
1415 
1416  if (static_cast<Eigen::Index>(state.joint_names.size()) != state.position.size())
1417  {
1418  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link (%s) where joint names and position are different sizes.",
1419  cmd->getLinkName().c_str());
1420  return false;
1421  }
1422 
1423  tesseract_scene_graph::SceneState scene_state = state_solver_clone->getState(state.joint_names, state.position);
1424  if (joint_names.empty() || !tesseract_common::isIdentical(state.joint_names, joint_names, false))
1425  {
1426  joint_names = state.joint_names;
1427  active_link_names = scene_graph->getJointChildrenNames(joint_names);
1428 
1429  if (std::find(active_link_names.begin(), active_link_names.end(), cmd->getParentLinkName()) !=
1430  active_link_names.end())
1431  {
1432  CONSOLE_BRIDGE_logWarn("Tried to add trajectory link (%s) where parent link is an active link.",
1433  cmd->getLinkName().c_str());
1434  return false;
1435  }
1436  }
1437 
1438  Eigen::Isometry3d parent_link_tf_inv = scene_state.link_transforms[cmd->getParentLinkName()].inverse(); // NOLINT
1439  for (const auto& link_name : active_link_names)
1440  {
1441  Eigen::Isometry3d link_transform = parent_link_tf_inv * scene_state.link_transforms[link_name];
1442  auto link = scene_graph->getLink(link_name);
1443  assert(link != nullptr);
1444 
1445  auto clone = link->clone(link_name + "_clone");
1446 
1447  for (auto& vis_clone : clone.visual)
1448  {
1449  vis_clone->origin = link_transform * vis_clone->origin;
1450  traj_link->visual.push_back(vis_clone);
1451  }
1452 
1453  for (auto& col_clone : clone.collision)
1454  {
1455  col_clone->origin = link_transform * col_clone->origin;
1456  traj_link->collision.push_back(col_clone);
1457  }
1458  }
1459  }
1460 
1461  auto traj_joint = std::make_shared<tesseract_scene_graph::Joint>("joint_" + cmd->getLinkName());
1462  traj_joint->type = tesseract_scene_graph::JointType::FIXED;
1463  traj_joint->parent_link_name = cmd->getParentLinkName();
1464  traj_joint->child_link_name = cmd->getLinkName();
1465  traj_joint->parent_to_joint_origin_transform = Eigen::Isometry3d::Identity();
1466 
1467  if (!applyAddLinkCommandHelper(traj_link, traj_joint, cmd->replaceAllowed()))
1468  return false;
1469 
1470  ++revision;
1471  commands.push_back(cmd);
1472 
1473  return true;
1474 }
1475 
1477  const std::shared_ptr<const tesseract_scene_graph::Link>& link,
1478  const std::shared_ptr<const tesseract_scene_graph::Joint>& joint,
1479  bool replace_allowed)
1480 {
1481  bool link_exists = false;
1482  bool joint_exists = false;
1483  std::string link_name, joint_name;
1484 
1485  if (link != nullptr)
1486  {
1487  link_name = link->getName();
1488  link_exists = (scene_graph->getLink(link_name) != nullptr);
1489  }
1490 
1491  if (joint != nullptr)
1492  {
1493  joint_name = joint->getName();
1494  joint_exists = (scene_graph->getJoint(joint_name) != nullptr);
1495  }
1496 
1497  if (link_exists && !replace_allowed)
1498  {
1499  CONSOLE_BRIDGE_logWarn("Tried to add link (%s) which already exists. Set replace_allowed to enable replacing.",
1500  link_name.c_str());
1501  return false;
1502  }
1503 
1504  if (joint_exists && !replace_allowed)
1505  {
1506  CONSOLE_BRIDGE_logWarn("Tried to replace link (%s) and joint (%s) where the joint exist but the link does not. "
1507  "This is not supported.",
1508  link_name.c_str(),
1509  joint_name.c_str());
1510  return false;
1511  }
1512 
1513  if (!link_exists && joint_exists)
1514  {
1515  CONSOLE_BRIDGE_logWarn("Tried to add link (%s) which does not exists with a joint provided which already exists. "
1516  "This is not supported.",
1517  link_name.c_str());
1518  return false;
1519  }
1520 
1521  if (link_exists && joint && !joint_exists)
1522  {
1523  CONSOLE_BRIDGE_logWarn("Tried to add link (%s) which already exists with a joint provided which does not exist. "
1524  "This is not supported.",
1525  link_name.c_str());
1526  return false;
1527  }
1528 
1529  if (link_exists && !joint)
1530  { // A link is being replaced
1531  if (!scene_graph->addLink(*link, true))
1532  return false;
1533 
1534  // Solver is not affected by replace links
1535  }
1536  else if (link_exists && joint_exists)
1537  { // A link and joint pair is being replaced
1538  tesseract_scene_graph::Link::ConstPtr orig_link = scene_graph->getLink(link_name);
1539  tesseract_scene_graph::Joint::ConstPtr orig_joint = scene_graph->getJoint(joint_name);
1540 
1541  if (orig_joint->child_link_name != orig_link->getName())
1542  {
1543  CONSOLE_BRIDGE_logWarn("Tried to replace link (%s) and joint (%s) which are currently not linked. This is not "
1544  "supported.",
1545  link_name.c_str(),
1546  joint_name.c_str());
1547  return false;
1548  }
1549 
1550  if (!scene_graph->addLink(*link, true))
1551  return false;
1552 
1553  if (!scene_graph->removeJoint(joint_name))
1554  {
1555  // Replace with original link
1556  if (!scene_graph->addLink(*orig_link, true))
1557  throw std::runtime_error("Environment: Failed to replace link and joint and reset to original state.");
1558 
1559  return false;
1560  }
1561 
1562  if (!scene_graph->addJoint(*joint))
1563  {
1564  // Replace with original link
1565  if (!scene_graph->addLink(*orig_link, true))
1566  throw std::runtime_error("Environment: Failed to replace link and joint reset to original state.");
1567 
1568  // Replace with original link
1569  if (!scene_graph->addJoint(*orig_joint))
1570  throw std::runtime_error("Environment: Failed to replace link and joint and reset to original state.");
1571 
1572  return false;
1573  }
1574 
1575  if (!state_solver->replaceJoint(*joint))
1576  throw std::runtime_error("Environment, failed to replace link and joint in state solver.");
1577  }
1578  else if (!link_exists && !joint)
1579  { // Add a new link is being added attached to the world
1580  std::string joint_name = "joint_" + link_name;
1581  tesseract_scene_graph::Joint joint(joint_name);
1583  joint.child_link_name = link_name;
1584  joint.parent_link_name = scene_graph->getRoot();
1585 
1586  if (!scene_graph->addLink(*link, joint))
1587  return false;
1588 
1589  if (!state_solver->addLink(*link, joint))
1590  throw std::runtime_error("Environment, failed to add link and joint in state solver.");
1591  }
1592  else
1593  { // A new link and joint is being added
1594  if (!scene_graph->addLink(*link, *joint))
1595  return false;
1596 
1597  if (!state_solver->addLink(*link, *joint))
1598  throw std::runtime_error("Environment, failed to add link and joint in state solver.");
1599  }
1600 
1601  // If Link existed remove it from collision before adding the replacing links geometry
1602  if (link_exists)
1603  {
1604  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1605  if (discrete_manager != nullptr)
1606  discrete_manager->removeCollisionObject(link_name);
1607 
1608  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1609  if (continuous_manager != nullptr)
1610  continuous_manager->removeCollisionObject(link_name);
1611  }
1612 
1613  // We have moved the original objects, get a pointer to them from scene_graph
1614  if (!link->collision.empty())
1615  {
1618  getCollisionObject(shapes, shape_poses, *link);
1619 
1620  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1621  if (discrete_manager != nullptr)
1622  discrete_manager->addCollisionObject(link_name, 0, shapes, shape_poses, true);
1623 
1624  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1625  if (continuous_manager != nullptr)
1626  continuous_manager->addCollisionObject(link_name, 0, shapes, shape_poses, true);
1627  }
1628 
1629  return true;
1630 }
1631 
1632 bool Environment::Implementation::applyMoveLinkCommand(const std::shared_ptr<const MoveLinkCommand>& cmd)
1633 {
1634  if (!scene_graph->moveLink(*cmd->getJoint()))
1635  return false;
1636 
1637  if (!state_solver->moveLink(*cmd->getJoint()))
1638  throw std::runtime_error("Environment, failed to move link in state solver.");
1639 
1640  ++revision;
1641  commands.push_back(cmd);
1642 
1643  return true;
1644 }
1645 
1646 bool Environment::Implementation::applyMoveJointCommand(const std::shared_ptr<const MoveJointCommand>& cmd)
1647 {
1648  if (!scene_graph->moveJoint(cmd->getJointName(), cmd->getParentLink()))
1649  return false;
1650 
1651  if (!state_solver->moveJoint(cmd->getJointName(), cmd->getParentLink()))
1652  throw std::runtime_error("Environment, failed to move joint in state solver.");
1653 
1654  ++revision;
1655  commands.push_back(cmd);
1656 
1657  return true;
1658 }
1659 
1660 bool Environment::Implementation::applyRemoveLinkCommand(const std::shared_ptr<const RemoveLinkCommand>& cmd)
1661 {
1662  if (!removeLinkHelper(cmd->getLinkName()))
1663  return false;
1664 
1665  if (!state_solver->removeLink(cmd->getLinkName()))
1666  throw std::runtime_error("Environment, failed to remove link in state solver.");
1667 
1668  ++revision;
1669  commands.push_back(cmd);
1670 
1671  return true;
1672 }
1673 
1674 bool Environment::Implementation::applyRemoveJointCommand(const std::shared_ptr<const RemoveJointCommand>& cmd)
1675 {
1676  if (scene_graph->getJoint(cmd->getJointName()) == nullptr)
1677  {
1678  CONSOLE_BRIDGE_logWarn("Tried to remove Joint (%s) that does not exist", cmd->getJointName().c_str());
1679  return false;
1680  }
1681 
1682  std::string target_link_name = scene_graph->getTargetLink(cmd->getJointName())->getName();
1683 
1684  if (!removeLinkHelper(target_link_name))
1685  return false;
1686 
1687  if (!state_solver->removeJoint(cmd->getJointName()))
1688  throw std::runtime_error("Environment, failed to remove joint in state solver.");
1689 
1690  ++revision;
1691  commands.push_back(cmd);
1692 
1693  return true;
1694 }
1695 
1696 bool Environment::Implementation::applyReplaceJointCommand(const std::shared_ptr<const ReplaceJointCommand>& cmd)
1697 {
1698  tesseract_scene_graph::Joint::ConstPtr current_joint = scene_graph->getJoint(cmd->getJoint()->getName());
1699  if (current_joint == nullptr)
1700  {
1701  CONSOLE_BRIDGE_logWarn("Tried to replace Joint (%s) that does not exist", cmd->getJoint()->getName().c_str());
1702  return false;
1703  }
1704 
1705  if (cmd->getJoint()->child_link_name != current_joint->child_link_name)
1706  {
1707  CONSOLE_BRIDGE_logWarn("Tried to replace Joint (%s) where the child links are not the same",
1708  cmd->getJoint()->getName().c_str());
1709  return false;
1710  }
1711 
1712  if (!scene_graph->removeJoint(cmd->getJoint()->getName()))
1713  return false;
1714 
1715  if (!scene_graph->addJoint(*cmd->getJoint()))
1716  {
1717  // Add old joint back
1718  if (!scene_graph->addJoint(*current_joint))
1719  throw std::runtime_error("Environment: Failed to add old joint back when replace failed!");
1720 
1721  return false;
1722  }
1723 
1724  if (!state_solver->replaceJoint(*cmd->getJoint()))
1725  throw std::runtime_error("Environment, failed to replace joint in state solver.");
1726 
1727  ++revision;
1728  commands.push_back(cmd);
1729 
1730  return true;
1731 }
1732 
1733 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1735  const std::shared_ptr<const ChangeLinkOriginCommand>& /*cmd*/)
1736 {
1737  throw std::runtime_error("Unhandled environment command: CHANGE_LINK_ORIGIN");
1738 }
1739 
1741 {
1742  if (!scene_graph->changeJointOrigin(cmd->getJointName(), cmd->getOrigin()))
1743  return false;
1744 
1745  if (!state_solver->changeJointOrigin(cmd->getJointName(), cmd->getOrigin()))
1746  throw std::runtime_error("Environment, failed to change joint origin in state solver.");
1747 
1748  ++revision;
1749  commands.push_back(cmd);
1750 
1751  return true;
1752 }
1753 
1755  const std::shared_ptr<const ChangeLinkCollisionEnabledCommand>& cmd)
1756 {
1757  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1758  if (discrete_manager != nullptr)
1759  {
1760  if (cmd->getEnabled())
1761  discrete_manager->enableCollisionObject(cmd->getLinkName());
1762  else
1763  discrete_manager->disableCollisionObject(cmd->getLinkName());
1764  }
1765 
1766  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1767  if (continuous_manager != nullptr)
1768  {
1769  if (cmd->getEnabled())
1770  continuous_manager->enableCollisionObject(cmd->getLinkName());
1771  else
1772  continuous_manager->disableCollisionObject(cmd->getLinkName());
1773  }
1774 
1775  scene_graph->setLinkCollisionEnabled(cmd->getLinkName(), cmd->getEnabled());
1776 
1777  if (scene_graph->getLinkCollisionEnabled(cmd->getLinkName()) != cmd->getEnabled())
1778  return false;
1779 
1780  ++revision;
1781  commands.push_back(cmd);
1782 
1783  return true;
1784 }
1785 
1787  const std::shared_ptr<const ChangeLinkVisibilityCommand>& cmd)
1788 {
1789  scene_graph->setLinkVisibility(cmd->getLinkName(), cmd->getEnabled());
1790  if (scene_graph->getLinkVisibility(cmd->getLinkName()) != cmd->getEnabled())
1791  return false;
1792 
1793  ++revision;
1794  commands.push_back(cmd);
1795 
1796  return true;
1797 }
1798 
1800  const std::shared_ptr<const ModifyAllowedCollisionsCommand>& cmd)
1801 {
1802  switch (cmd->getModifyType())
1803  {
1805  {
1806  for (const auto& entry : cmd->getAllowedCollisionMatrix().getAllAllowedCollisions())
1807  scene_graph->removeAllowedCollision(entry.first.first, entry.first.second);
1808 
1809  break;
1810  }
1812  {
1813  scene_graph->clearAllowedCollisions();
1814  for (const auto& entry : cmd->getAllowedCollisionMatrix().getAllAllowedCollisions())
1815  scene_graph->addAllowedCollision(entry.first.first, entry.first.second, entry.second);
1816  break;
1817  }
1819  {
1820  for (const auto& entry : cmd->getAllowedCollisionMatrix().getAllAllowedCollisions())
1821  scene_graph->addAllowedCollision(entry.first.first, entry.first.second, entry.second);
1822 
1823  break;
1824  }
1825  }
1826 
1827  ++revision;
1828  commands.push_back(cmd);
1829 
1830  return true;
1831 }
1832 
1834  const std::shared_ptr<const RemoveAllowedCollisionLinkCommand>& cmd)
1835 {
1836  scene_graph->removeAllowedCollision(cmd->getLinkName());
1837 
1838  ++revision;
1839  commands.push_back(cmd);
1840 
1841  return true;
1842 }
1843 
1844 bool Environment::Implementation::applyAddSceneGraphCommand(std::shared_ptr<const AddSceneGraphCommand> cmd)
1845 {
1846  if (scene_graph->isEmpty() && cmd->getJoint())
1847  return false;
1848 
1849  std::vector<tesseract_scene_graph::Link::ConstPtr> pre_links = scene_graph->getLinks();
1850  if (scene_graph->isEmpty())
1851  {
1852  if (!scene_graph->insertSceneGraph(*cmd->getSceneGraph(), cmd->getPrefix()))
1853  return false;
1854 
1855  state_solver = std::make_unique<tesseract_scene_graph::OFKTStateSolver>(*cmd->getSceneGraph(), cmd->getPrefix());
1856  }
1857  else if (!cmd->getJoint())
1858  {
1859  // Connect root of subgraph to graph
1860  tesseract_scene_graph::Joint root_joint(cmd->getPrefix() + cmd->getSceneGraph()->getName() + "_joint");
1862  root_joint.parent_link_name = scene_graph->getRoot();
1863  root_joint.child_link_name = cmd->getPrefix() + cmd->getSceneGraph()->getRoot();
1864  root_joint.parent_to_joint_origin_transform = Eigen::Isometry3d::Identity();
1865 
1866  tesseract_scene_graph::SceneGraph::ConstPtr sg = cmd->getSceneGraph();
1867  std::string prefix = cmd->getPrefix();
1868  cmd = std::make_shared<AddSceneGraphCommand>(*sg, root_joint, prefix);
1869  if (!scene_graph->insertSceneGraph(*cmd->getSceneGraph(), *cmd->getJoint(), cmd->getPrefix()))
1870  return false;
1871 
1872  if (!state_solver->insertSceneGraph(*cmd->getSceneGraph(), *cmd->getJoint(), cmd->getPrefix()))
1873  throw std::runtime_error("Environment, failed to insert scene graph into state solver.");
1874  }
1875  else
1876  {
1877  if (!scene_graph->insertSceneGraph(*cmd->getSceneGraph(), *cmd->getJoint(), cmd->getPrefix()))
1878  return false;
1879 
1880  if (!state_solver->insertSceneGraph(*cmd->getSceneGraph(), *cmd->getJoint(), cmd->getPrefix()))
1881  throw std::runtime_error("Environment, failed to insert scene graph into state solver.");
1882  }
1883 
1884  // Now need to get list of added links to add to the contact manager
1885  std::vector<tesseract_scene_graph::Link::ConstPtr> post_links = scene_graph->getLinks();
1886  assert(post_links.size() > pre_links.size());
1887  std::sort(pre_links.begin(), pre_links.end());
1888  std::sort(post_links.begin(), post_links.end());
1889  std::vector<tesseract_scene_graph::Link::ConstPtr> diff_links;
1890  std::set_difference(post_links.begin(),
1891  post_links.end(),
1892  pre_links.begin(),
1893  pre_links.end(),
1894  std::inserter(diff_links, diff_links.begin()));
1895 
1896  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1897  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1898  for (const auto& link : diff_links)
1899  {
1900  if (!link->collision.empty())
1901  {
1904  getCollisionObject(shapes, shape_poses, *link);
1905 
1906  if (discrete_manager != nullptr)
1907  discrete_manager->addCollisionObject(link->getName(), 0, shapes, shape_poses, true);
1908  if (continuous_manager != nullptr)
1909  continuous_manager->addCollisionObject(link->getName(), 0, shapes, shape_poses, true);
1910  }
1911  }
1912 
1913  ++revision;
1914  commands.push_back(cmd);
1915 
1916  return true;
1917 }
1918 
1920  const std::shared_ptr<const ChangeJointPositionLimitsCommand>& cmd)
1921 {
1922  // First check if all of the joint exist
1923  for (const auto& jp : cmd->getLimits())
1924  {
1925  tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph->getJointLimits(jp.first);
1926  if (jl == nullptr)
1927  return false;
1928  }
1929 
1930  for (const auto& jp : cmd->getLimits())
1931  {
1932  tesseract_scene_graph::JointLimits jl_copy = *scene_graph->getJointLimits(jp.first);
1933  jl_copy.lower = jp.second.first;
1934  jl_copy.upper = jp.second.second;
1935 
1936  if (!scene_graph->changeJointLimits(jp.first, jl_copy))
1937  return false;
1938 
1939  if (!state_solver->changeJointPositionLimits(jp.first, jp.second.first, jp.second.second))
1940  throw std::runtime_error("Environment, failed to change joint position limits in state solver.");
1941  }
1942 
1943  ++revision;
1944  commands.push_back(cmd);
1945 
1946  return true;
1947 }
1948 
1950  const std::shared_ptr<const ChangeJointVelocityLimitsCommand>& cmd)
1951 {
1952  // First check if all of the joint exist
1953  for (const auto& jp : cmd->getLimits())
1954  {
1955  tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph->getJointLimits(jp.first);
1956  if (jl == nullptr)
1957  return false;
1958  }
1959 
1960  for (const auto& jp : cmd->getLimits())
1961  {
1962  tesseract_scene_graph::JointLimits jl_copy = *scene_graph->getJointLimits(jp.first);
1963  jl_copy.velocity = jp.second;
1964 
1965  if (!scene_graph->changeJointLimits(jp.first, jl_copy))
1966  return false;
1967 
1968  if (!state_solver->changeJointVelocityLimits(jp.first, jp.second))
1969  throw std::runtime_error("Environment, failed to change joint velocity limits in state solver.");
1970  }
1971 
1972  ++revision;
1973  commands.push_back(cmd);
1974 
1975  return true;
1976 }
1977 
1979  const std::shared_ptr<const ChangeJointAccelerationLimitsCommand>& cmd)
1980 {
1981  // First check if all of the joint exist
1982  for (const auto& jp : cmd->getLimits())
1983  {
1984  tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph->getJointLimits(jp.first);
1985  if (jl == nullptr)
1986  return false;
1987  }
1988 
1989  for (const auto& jp : cmd->getLimits())
1990  {
1991  tesseract_scene_graph::JointLimits jl_copy = *scene_graph->getJointLimits(jp.first);
1992  jl_copy.acceleration = jp.second;
1993 
1994  if (!scene_graph->changeJointLimits(jp.first, jl_copy))
1995  return false;
1996 
1997  if (!state_solver->changeJointAccelerationLimits(jp.first, jp.second))
1998  throw std::runtime_error("Environment, failed to change joint acceleration limits in state solver.");
1999  }
2000 
2001  ++revision;
2002  commands.push_back(cmd);
2003 
2004  return true;
2005 }
2006 
2008  const std::shared_ptr<const AddKinematicsInformationCommand>& cmd)
2009 {
2010  kinematics_information.insert(cmd->getKinematicsInformation());
2011 
2012  if (!cmd->getKinematicsInformation().kinematics_plugin_info.empty())
2013  {
2014  const auto& info = cmd->getKinematicsInformation().kinematics_plugin_info;
2015  for (const auto& search_path : info.search_paths)
2016  kinematics_factory.addSearchPath(search_path);
2017 
2018  for (const auto& search_library : info.search_libraries)
2019  kinematics_factory.addSearchLibrary(search_library);
2020 
2021  for (const auto& group : info.fwd_plugin_infos)
2022  {
2023  for (const auto& solver : group.second.plugins)
2024  kinematics_factory.addFwdKinPlugin(group.first, solver.first, solver.second);
2025 
2026  if (!group.second.default_plugin.empty())
2027  kinematics_factory.setDefaultFwdKinPlugin(group.first, group.second.default_plugin);
2028  }
2029 
2030  for (const auto& group : info.inv_plugin_infos)
2031  {
2032  for (const auto& solver : group.second.plugins)
2033  kinematics_factory.addInvKinPlugin(group.first, solver.first, solver.second);
2034 
2035  if (!group.second.default_plugin.empty())
2036  kinematics_factory.setDefaultInvKinPlugin(group.first, group.second.default_plugin);
2037  }
2038  }
2039 
2040  ++revision;
2041  commands.push_back(cmd);
2042 
2043  return true;
2044 }
2045 
2047  const std::shared_ptr<const AddContactManagersPluginInfoCommand>& cmd)
2048 {
2049  const auto& info = cmd->getContactManagersPluginInfo();
2050 
2051  if (!info.empty())
2052  {
2053  contact_managers_plugin_info.insert(info);
2054 
2055  for (const auto& search_path : info.search_paths)
2056  contact_managers_factory.addSearchPath(search_path);
2057 
2058  for (const auto& search_library : info.search_libraries)
2059  contact_managers_factory.addSearchLibrary(search_library);
2060 
2061  for (const auto& cm : info.discrete_plugin_infos.plugins)
2062  contact_managers_factory.addDiscreteContactManagerPlugin(cm.first, cm.second);
2063 
2064  if (!info.discrete_plugin_infos.default_plugin.empty())
2065  contact_managers_factory.setDefaultDiscreteContactManagerPlugin(info.discrete_plugin_infos.default_plugin);
2066 
2067  for (const auto& cm : info.continuous_plugin_infos.plugins)
2068  contact_managers_factory.addContinuousContactManagerPlugin(cm.first, cm.second);
2069 
2070  if (!info.continuous_plugin_infos.default_plugin.empty())
2071  contact_managers_factory.setDefaultContinuousContactManagerPlugin(info.continuous_plugin_infos.default_plugin);
2072  }
2073 
2074  if (contact_managers_factory.hasDiscreteContactManagerPlugins())
2075  {
2076  std::string discrete_default = contact_managers_factory.getDefaultDiscreteContactManagerPlugin();
2077  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
2078  if (discrete_manager == nullptr || discrete_manager->getName() != discrete_default)
2079  setActiveDiscreteContactManagerHelper(discrete_default);
2080  }
2081  else
2082  {
2083  CONSOLE_BRIDGE_logDebug("Environment, No discrete contact manager plugins were provided");
2084  }
2085 
2086  if (contact_managers_factory.hasContinuousContactManagerPlugins())
2087  {
2088  std::string continuous_default = contact_managers_factory.getDefaultContinuousContactManagerPlugin();
2089  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
2090  if (continuous_manager == nullptr || continuous_manager->getName() != continuous_default)
2091  setActiveContinuousContactManagerHelper(continuous_default);
2092  }
2093  else
2094  {
2095  CONSOLE_BRIDGE_logDebug("Environment, No continuous contact manager plugins were provided");
2096  }
2097 
2098  ++revision;
2099  commands.push_back(cmd);
2100 
2101  return true;
2102 }
2103 
2105  const std::shared_ptr<const SetActiveContinuousContactManagerCommand>& cmd)
2106 {
2107  setActiveContinuousContactManager(cmd->getName());
2108 
2109  ++revision;
2110  commands.push_back(cmd);
2111 
2112  return true;
2113 }
2114 
2116  const std::shared_ptr<const SetActiveDiscreteContactManagerCommand>& cmd)
2117 {
2118  setActiveDiscreteContactManager(cmd->getName());
2119 
2120  ++revision;
2121  commands.push_back(cmd);
2122 
2123  return true;
2124 }
2125 
2127  const std::shared_ptr<const ChangeCollisionMarginsCommand>& cmd)
2128 {
2129  std::optional<double> default_margin = cmd->getDefaultCollisionMargin();
2130  const tesseract_common::CollisionMarginPairData& pair_margins = cmd->getCollisionMarginPairData();
2131 
2132  if (default_margin.has_value())
2133  collision_margin_data.setDefaultCollisionMargin(default_margin.value());
2134 
2135  if (!pair_margins.empty())
2136  collision_margin_data.apply(pair_margins, cmd->getCollisionMarginPairOverrideType());
2137 
2138  std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
2139  if (continuous_manager != nullptr)
2140  continuous_manager->setCollisionMarginData(collision_margin_data);
2141 
2142  std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
2143  if (discrete_manager != nullptr)
2144  discrete_manager->setCollisionMarginData(collision_margin_data);
2145 
2146  ++revision;
2147  commands.push_back(cmd);
2148 
2149  return true;
2150 }
2151 
2152 Environment::Environment() : impl_(std::make_unique<Implementation>()) {}
2153 Environment::Environment(std::unique_ptr<Implementation> impl) : impl_(std::move(impl)) {}
2154 Environment::~Environment() = default;
2155 
2156 bool Environment::init(const std::vector<std::shared_ptr<const Command>>& commands)
2157 {
2158  bool success{ false };
2159  {
2160  std::unique_lock<std::shared_mutex> lock(mutex_);
2161  success = impl_->initHelper(commands);
2162  }
2163 
2164  // Call the event callbacks
2165  std::shared_lock<std::shared_mutex> lock(mutex_);
2166  impl_->triggerCallbacks();
2167 
2168  return success;
2169 }
2170 
2172  const std::shared_ptr<const tesseract_srdf::SRDFModel>& srdf_model)
2173 {
2174  Commands commands = getInitCommands(scene_graph, srdf_model);
2175  return init(commands);
2176 }
2177 
2178 bool Environment::init(const std::string& urdf_string,
2179  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2180 {
2181  {
2182  std::unique_lock<std::shared_mutex> lock(mutex_);
2183  impl_->resource_locator = locator;
2184  }
2185 
2186  // Parse urdf string into Scene Graph
2188  try
2189  {
2190  scene_graph = tesseract_urdf::parseURDFString(urdf_string, *locator);
2191  }
2192  catch (const std::exception& e)
2193  {
2194  CONSOLE_BRIDGE_logError("Failed to parse URDF.");
2196  return false;
2197  }
2198 
2199  Commands commands = getInitCommands(*scene_graph);
2200  return init(commands);
2201 }
2202 
2203 bool Environment::init(const std::string& urdf_string,
2204  const std::string& srdf_string,
2205  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2206 {
2207  {
2208  std::unique_lock<std::shared_mutex> lock(mutex_);
2209  impl_->resource_locator = locator;
2210  }
2211 
2212  // Parse urdf string into Scene Graph
2214  try
2215  {
2216  scene_graph = tesseract_urdf::parseURDFString(urdf_string, *locator);
2217  }
2218  catch (const std::exception& e)
2219  {
2220  CONSOLE_BRIDGE_logError("Failed to parse URDF.");
2222  return false;
2223  }
2224 
2225  // Parse srdf string into SRDF Model
2226  auto srdf = std::make_shared<tesseract_srdf::SRDFModel>();
2227  try
2228  {
2229  srdf->initString(*scene_graph, srdf_string, *locator);
2230  }
2231  catch (const std::exception& e)
2232  {
2233  CONSOLE_BRIDGE_logError("Failed to parse SRDF.");
2235  return false;
2236  }
2237 
2238  Commands commands = getInitCommands(*scene_graph, srdf);
2239  return init(commands);
2240 }
2241 
2242 bool Environment::init(const std::filesystem::path& urdf_path,
2243  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2244 {
2245  {
2246  std::unique_lock<std::shared_mutex> lock(mutex_);
2247  impl_->resource_locator = locator;
2248  }
2249 
2250  // Parse urdf file into Scene Graph
2252  try
2253  {
2254  scene_graph = tesseract_urdf::parseURDFFile(urdf_path.string(), *locator);
2255  }
2256  catch (const std::exception& e)
2257  {
2258  CONSOLE_BRIDGE_logError("Failed to parse URDF.");
2260  return false;
2261  }
2262 
2263  Commands commands = getInitCommands(*scene_graph);
2264  return init(commands);
2265 }
2266 
2267 bool Environment::init(const std::filesystem::path& urdf_path,
2268  const std::filesystem::path& srdf_path,
2269  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2270 {
2271  {
2272  std::unique_lock<std::shared_mutex> lock(mutex_);
2273  impl_->resource_locator = locator;
2274  }
2275 
2276  // Parse urdf file into Scene Graph
2278  try
2279  {
2280  scene_graph = tesseract_urdf::parseURDFFile(urdf_path.string(), *locator);
2281  }
2282  catch (const std::exception& e)
2283  {
2284  CONSOLE_BRIDGE_logError("Failed to parse URDF.");
2286  return false;
2287  }
2288 
2289  // Parse srdf file into SRDF Model
2290  auto srdf = std::make_shared<tesseract_srdf::SRDFModel>();
2291  try
2292  {
2293  srdf->initFile(*scene_graph, srdf_path.string(), *locator);
2294  }
2295  catch (const std::exception& e)
2296  {
2297  CONSOLE_BRIDGE_logError("Failed to parse SRDF.");
2299  return false;
2300  }
2301 
2302  Commands commands = getInitCommands(*scene_graph, srdf);
2303  return init(commands); // NOLINT
2304 }
2305 
2307 {
2308  bool success{ false };
2309  {
2310  std::unique_lock<std::shared_mutex> lock(mutex_);
2311  success = impl_->reset();
2312  }
2313 
2314  // Call the event callbacks
2315  std::shared_lock<std::shared_mutex> lock(mutex_);
2316  impl_->triggerCallbacks();
2317 
2318  return success;
2319 }
2320 
2322 {
2323  std::unique_lock<std::shared_mutex> lock(mutex_);
2324  impl_->clear();
2325 }
2326 
2328 {
2329  std::shared_lock<std::shared_mutex> lock(mutex_);
2330  return std::as_const<Implementation>(*impl_).initialized;
2331 }
2332 
2334 {
2335  std::shared_lock<std::shared_mutex> lock(mutex_);
2336  return std::as_const<Implementation>(*impl_).revision;
2337 }
2338 
2340 {
2341  std::shared_lock<std::shared_mutex> lock(mutex_);
2342  return std::as_const<Implementation>(*impl_).init_revision;
2343 }
2344 
2345 std::vector<std::shared_ptr<const Command>> Environment::getCommandHistory() const
2346 {
2347  std::shared_lock<std::shared_mutex> lock(mutex_);
2348  return std::as_const<Implementation>(*impl_).commands;
2349 }
2350 
2351 bool Environment::applyCommands(const std::vector<std::shared_ptr<const Command>>& commands)
2352 {
2353  bool success{ false };
2354  {
2355  std::unique_lock<std::shared_mutex> lock(mutex_);
2356  success = impl_->applyCommandsHelper(commands);
2357  }
2358  std::shared_lock<std::shared_mutex> lock(mutex_);
2359  impl_->triggerCallbacks();
2360 
2361  return success;
2362 }
2363 
2364 bool Environment::applyCommand(std::shared_ptr<const Command> command) { return applyCommands({ std::move(command) }); }
2365 
2366 std::shared_ptr<const tesseract_scene_graph::SceneGraph> Environment::getSceneGraph() const
2367 {
2368  return std::as_const<Implementation>(*impl_).scene_graph;
2369 }
2370 
2371 std::vector<std::string> Environment::getGroupJointNames(const std::string& group_name) const
2372 {
2373  std::shared_lock<std::shared_mutex> lock(mutex_);
2374  return std::as_const<Implementation>(*impl_).getGroupJointNames(group_name);
2375 }
2376 
2377 std::shared_ptr<const tesseract_kinematics::JointGroup> Environment::getJointGroup(const std::string& group_name) const
2378 {
2379  std::shared_lock<std::shared_mutex> lock(mutex_);
2380  return std::as_const<Implementation>(*impl_).getJointGroup(group_name);
2381 }
2382 
2383 std::shared_ptr<const tesseract_kinematics::JointGroup>
2384 Environment::getJointGroup(const std::string& name, const std::vector<std::string>& joint_names) const
2385 {
2386  std::shared_lock<std::shared_mutex> lock(mutex_);
2387  return std::as_const<Implementation>(*impl_).getJointGroup(name, joint_names);
2388 }
2389 
2390 std::shared_ptr<const tesseract_kinematics::KinematicGroup>
2391 Environment::getKinematicGroup(const std::string& group_name, const std::string& ik_solver_name) const
2392 {
2393  std::shared_lock<std::shared_mutex> lock(mutex_);
2394  return std::as_const<Implementation>(*impl_).getKinematicGroup(group_name, ik_solver_name);
2395 }
2396 
2397 // NOLINTNEXTLINE
2398 Eigen::Isometry3d Environment::findTCPOffset(const tesseract_common::ManipulatorInfo& manip_info) const
2399 {
2400  std::shared_lock<std::shared_mutex> lock(mutex_);
2401  return std::as_const<Implementation>(*impl_).findTCPOffset(manip_info);
2402 }
2403 
2405 {
2406  std::unique_lock<std::shared_mutex> lock(mutex_);
2407  impl_->find_tcp_cb.push_back(fn);
2408 }
2409 
2410 std::vector<FindTCPOffsetCallbackFn> Environment::getFindTCPOffsetCallbacks() const
2411 {
2412  std::shared_lock<std::shared_mutex> lock(mutex_);
2413  return std::as_const<Implementation>(*impl_).find_tcp_cb;
2414 }
2415 
2416 void Environment::addEventCallback(std::size_t hash, const EventCallbackFn& fn)
2417 {
2418  std::unique_lock<std::shared_mutex> lock(mutex_);
2419  impl_->event_cb[hash] = fn;
2420 }
2421 
2422 void Environment::removeEventCallback(std::size_t hash)
2423 {
2424  std::unique_lock<std::shared_mutex> lock(mutex_);
2425  impl_->event_cb.erase(hash);
2426 }
2427 
2429 {
2430  std::unique_lock<std::shared_mutex> lock(mutex_);
2431  impl_->event_cb.clear();
2432 }
2433 
2434 std::map<std::size_t, EventCallbackFn> Environment::getEventCallbacks() const
2435 {
2436  std::shared_lock<std::shared_mutex> lock(mutex_);
2437  return std::as_const<Implementation>(*impl_).event_cb;
2438 }
2439 
2440 void Environment::setResourceLocator(std::shared_ptr<const tesseract_common::ResourceLocator> locator)
2441 {
2442  std::unique_lock<std::shared_mutex> lock(mutex_);
2443  impl_->resource_locator = std::move(locator);
2444 }
2445 
2446 std::shared_ptr<const tesseract_common::ResourceLocator> Environment::getResourceLocator() const
2447 {
2448  std::shared_lock<std::shared_mutex> lock(mutex_);
2449  return std::as_const<Implementation>(*impl_).resource_locator;
2450 }
2451 
2452 void Environment::setName(const std::string& name)
2453 {
2454  std::unique_lock<std::shared_mutex> lock(mutex_);
2455  impl_->scene_graph->setName(name);
2456 }
2457 
2458 const std::string& Environment::getName() const
2459 {
2460  std::shared_lock<std::shared_mutex> lock(mutex_);
2461  return std::as_const<Implementation>(*impl_).scene_graph->getName();
2462 }
2463 
2464 void Environment::setState(const std::unordered_map<std::string, double>& joints,
2465  const tesseract_common::TransformMap& floating_joints)
2466 {
2467  {
2468  std::unique_lock<std::shared_mutex> lock(mutex_);
2469  impl_->setState(joints, floating_joints);
2470  }
2471 
2472  std::shared_lock<std::shared_mutex> lock(mutex_);
2473  impl_->triggerCurrentStateChangedCallbacks();
2474 }
2475 
2476 void Environment::setState(const std::vector<std::string>& joint_names,
2477  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
2478  const tesseract_common::TransformMap& floating_joints)
2479 {
2480  {
2481  std::unique_lock<std::shared_mutex> lock(mutex_);
2482  impl_->setState(joint_names, joint_values, floating_joints);
2483  }
2484 
2485  std::shared_lock<std::shared_mutex> lock(mutex_);
2486  impl_->triggerCurrentStateChangedCallbacks();
2487 }
2488 
2490 {
2491  {
2492  std::unique_lock<std::shared_mutex> lock(mutex_);
2493  impl_->setState(floating_joints);
2494  }
2495 
2496  std::shared_lock<std::shared_mutex> lock(mutex_);
2497  impl_->triggerCurrentStateChangedCallbacks();
2498 }
2499 
2500 tesseract_scene_graph::SceneState Environment::getState(const std::unordered_map<std::string, double>& joints,
2501  const tesseract_common::TransformMap& floating_joints) const
2502 {
2503  std::shared_lock<std::shared_mutex> lock(mutex_);
2504  return std::as_const<Implementation>(*impl_).state_solver->getState(joints, floating_joints);
2505 }
2506 
2507 tesseract_scene_graph::SceneState Environment::getState(const std::vector<std::string>& joint_names,
2508  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
2509  const tesseract_common::TransformMap& floating_joints) const
2510 {
2511  std::shared_lock<std::shared_mutex> lock(mutex_);
2512  return std::as_const<Implementation>(*impl_).state_solver->getState(joint_names, joint_values, floating_joints);
2513 }
2514 
2516 {
2517  std::shared_lock<std::shared_mutex> lock(mutex_);
2518  return std::as_const<Implementation>(*impl_).state_solver->getState(floating_joints);
2519 }
2520 
2522 {
2523  std::shared_lock<std::shared_mutex> lock(mutex_);
2524  return std::as_const<Implementation>(*impl_).current_state;
2525 }
2526 
2527 std::chrono::system_clock::time_point Environment::getTimestamp() const
2528 {
2529  std::shared_lock<std::shared_mutex> lock(mutex_);
2530  return std::as_const<Implementation>(*impl_).timestamp;
2531 }
2532 
2533 std::chrono::system_clock::time_point Environment::getCurrentStateTimestamp() const
2534 {
2535  std::shared_lock<std::shared_mutex> lock(mutex_);
2536  return std::as_const<Implementation>(*impl_).current_state_timestamp;
2537 }
2538 
2539 std::shared_ptr<const tesseract_scene_graph::Link> Environment::getLink(const std::string& name) const
2540 {
2541  std::shared_lock<std::shared_mutex> lock(mutex_);
2542  tesseract_scene_graph::Link::ConstPtr link = std::as_const<Implementation>(*impl_).scene_graph->getLink(name);
2543  return link;
2544 }
2545 
2546 std::shared_ptr<const tesseract_scene_graph::JointLimits>
2547 Environment::getJointLimits(const std::string& joint_name) const
2548 {
2549  std::shared_lock<std::shared_mutex> lock(mutex_);
2550  return std::as_const<Implementation>(*impl_).scene_graph->getJointLimits(joint_name);
2551 }
2552 
2553 bool Environment::getLinkCollisionEnabled(const std::string& name) const
2554 {
2555  std::shared_lock<std::shared_mutex> lock(mutex_);
2556  return std::as_const<Implementation>(*impl_).scene_graph->getLinkCollisionEnabled(name);
2557 }
2558 
2559 bool Environment::getLinkVisibility(const std::string& name) const
2560 {
2561  std::shared_lock<std::shared_mutex> lock(mutex_);
2562  return std::as_const<Implementation>(*impl_).scene_graph->getLinkVisibility(name);
2563 }
2564 
2565 std::shared_ptr<const tesseract_common::AllowedCollisionMatrix> Environment::getAllowedCollisionMatrix() const
2566 {
2567  std::shared_lock<std::shared_mutex> lock(mutex_);
2568  return std::as_const<Implementation>(*impl_).scene_graph->getAllowedCollisionMatrix();
2569 }
2570 
2571 std::vector<std::string> Environment::getJointNames() const
2572 {
2573  std::shared_lock<std::shared_mutex> lock(mutex_);
2574  return std::as_const<Implementation>(*impl_).state_solver->getJointNames();
2575 }
2576 
2577 std::vector<std::string> Environment::getActiveJointNames() const
2578 {
2579  std::shared_lock<std::shared_mutex> lock(mutex_);
2580  return std::as_const<Implementation>(*impl_).state_solver->getActiveJointNames();
2581 }
2582 
2583 std::shared_ptr<const tesseract_scene_graph::Joint> Environment::getJoint(const std::string& name) const
2584 {
2585  std::shared_lock<std::shared_mutex> lock(mutex_);
2586  return std::as_const<Implementation>(*impl_).scene_graph->getJoint(name);
2587 }
2588 
2589 Eigen::VectorXd Environment::getCurrentJointValues() const
2590 {
2591  std::shared_lock<std::shared_mutex> lock(mutex_);
2592  return std::as_const<Implementation>(*impl_).getCurrentJointValues();
2593 }
2594 
2595 Eigen::VectorXd Environment::getCurrentJointValues(const std::vector<std::string>& joint_names) const
2596 {
2597  std::shared_lock<std::shared_mutex> lock(mutex_);
2598  return std::as_const<Implementation>(*impl_).getCurrentJointValues(joint_names);
2599 }
2600 
2602 {
2603  std::shared_lock<std::shared_mutex> lock(mutex_);
2604  return std::as_const<Implementation>(*impl_).getCurrentFloatingJointValues();
2605 }
2606 
2608 Environment::getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const
2609 {
2610  std::shared_lock<std::shared_mutex> lock(mutex_);
2611  return std::as_const<Implementation>(*impl_).getCurrentFloatingJointValues(joint_names);
2612 }
2613 
2614 std::string Environment::getRootLinkName() const
2615 {
2616  std::shared_lock<std::shared_mutex> lock(mutex_);
2617  return std::as_const<Implementation>(*impl_).scene_graph->getRoot();
2618 }
2619 
2620 std::vector<std::string> Environment::getLinkNames() const
2621 {
2622  std::shared_lock<std::shared_mutex> lock(mutex_);
2623  return std::as_const<Implementation>(*impl_).state_solver->getLinkNames();
2624 }
2625 
2626 std::vector<std::string> Environment::getActiveLinkNames() const
2627 {
2628  std::shared_lock<std::shared_mutex> lock(mutex_);
2629  return std::as_const<Implementation>(*impl_).state_solver->getActiveLinkNames();
2630 }
2631 
2632 std::vector<std::string> Environment::getActiveLinkNames(const std::vector<std::string>& joint_names) const
2633 {
2634  std::shared_lock<std::shared_mutex> lock(mutex_);
2635  return std::as_const<Implementation>(*impl_).scene_graph->getJointChildrenNames(joint_names);
2636 }
2637 
2638 std::vector<std::string> Environment::getStaticLinkNames() const
2639 {
2640  std::shared_lock<std::shared_mutex> lock(mutex_);
2641  return std::as_const<Implementation>(*impl_).state_solver->getStaticLinkNames();
2642 }
2643 
2644 std::vector<std::string> Environment::getStaticLinkNames(const std::vector<std::string>& joint_names) const
2645 {
2646  std::shared_lock<std::shared_mutex> lock(mutex_);
2647  return std::as_const<Implementation>(*impl_).getStaticLinkNames(joint_names);
2648 }
2649 
2651 {
2652  std::shared_lock<std::shared_mutex> lock(mutex_);
2653  return std::as_const<Implementation>(*impl_).state_solver->getLinkTransforms();
2654 }
2655 
2656 Eigen::Isometry3d Environment::getLinkTransform(const std::string& link_name) const
2657 {
2658  std::shared_lock<std::shared_mutex> lock(mutex_);
2659  return std::as_const<Implementation>(*impl_).state_solver->getLinkTransform(link_name);
2660 }
2661 
2662 Eigen::Isometry3d Environment::getRelativeLinkTransform(const std::string& from_link_name,
2663  const std::string& to_link_name) const
2664 {
2665  std::shared_lock<std::shared_mutex> lock(mutex_);
2666  return std::as_const<Implementation>(*impl_).state_solver->getRelativeLinkTransform(from_link_name, to_link_name);
2667 }
2668 
2669 std::unique_ptr<tesseract_scene_graph::StateSolver> Environment::getStateSolver() const
2670 {
2671  std::shared_lock<std::shared_mutex> lock(mutex_);
2672  return std::as_const<Implementation>(*impl_).state_solver->clone();
2673 }
2674 
2676 {
2677  std::shared_lock<std::shared_mutex> lock(mutex_);
2678  return std::as_const<Implementation>(*impl_).kinematics_information;
2679 }
2680 
2681 std::set<std::string> Environment::getGroupNames() const
2682 {
2683  std::shared_lock<std::shared_mutex> lock(mutex_);
2684  return std::as_const<Implementation>(*impl_).kinematics_information.group_names;
2685 }
2686 
2688 {
2689  std::shared_lock<std::shared_mutex> lock(mutex_);
2690  return std::as_const<Implementation>(*impl_).contact_managers_plugin_info;
2691 }
2692 
2694 {
2695  std::unique_lock<std::shared_mutex> lock(mutex_);
2696  return impl_->setActiveDiscreteContactManager(name);
2697 }
2698 
2699 std::unique_ptr<tesseract_collision::DiscreteContactManager>
2700 Environment::getDiscreteContactManager(const std::string& name) const
2701 {
2702  std::shared_lock<std::shared_mutex> lock(mutex_);
2703  return std::as_const<Implementation>(*impl_).getDiscreteContactManager(name);
2704 }
2705 
2707 {
2708  std::unique_lock<std::shared_mutex> lock(mutex_);
2709  return impl_->setActiveContinuousContactManager(name);
2710 }
2711 
2712 std::unique_ptr<tesseract_collision::ContinuousContactManager>
2713 Environment::getContinuousContactManager(const std::string& name) const
2714 {
2715  std::shared_lock<std::shared_mutex> lock(mutex_);
2716  return std::as_const<Implementation>(*impl_).getContinuousContactManager(name);
2717 }
2718 
2719 std::unique_ptr<tesseract_collision::DiscreteContactManager> Environment::getDiscreteContactManager() const
2720 {
2721  std::shared_lock<std::shared_mutex> lock(mutex_);
2722  return std::as_const<Implementation>(*impl_).getDiscreteContactManager();
2723 }
2724 
2726 {
2727  std::shared_lock<std::shared_mutex> lock(mutex_);
2728  std::as_const<Implementation>(*impl_).clearCachedDiscreteContactManager();
2729 }
2730 
2731 std::unique_ptr<tesseract_collision::ContinuousContactManager> Environment::getContinuousContactManager() const
2732 {
2733  std::shared_lock<std::shared_mutex> lock(mutex_);
2734  return std::as_const<Implementation>(*impl_).getContinuousContactManager();
2735 }
2736 
2738 {
2739  std::shared_lock<std::shared_mutex> lock(mutex_);
2740  std::as_const<Implementation>(*impl_).clearCachedContinuousContactManager();
2741 }
2742 
2744 {
2745  std::shared_lock<std::shared_mutex> lock(mutex_);
2746  return std::as_const<Implementation>(*impl_).collision_margin_data;
2747 }
2748 
2749 std::shared_lock<std::shared_mutex> Environment::lockRead() const
2750 {
2751  return std::shared_lock<std::shared_mutex>(mutex_);
2752 }
2753 
2754 bool Environment::operator==(const Environment& rhs) const
2755 {
2756  std::shared_lock<std::shared_mutex> lock(mutex_);
2757  return std::as_const<Implementation>(*impl_) == std::as_const<Implementation>(*rhs.impl_);
2758 }
2759 
2760 bool Environment::operator!=(const Environment& rhs) const { return !operator==(rhs); }
2761 
2763 {
2764  std::shared_lock<std::shared_mutex> lock(mutex_);
2765  return std::make_unique<Environment>(std::as_const<Implementation>(*impl_).clone());
2766 }
2767 
2768 template <class Archive>
2769 void Environment::save(Archive& ar, const unsigned int /*version*/) const
2770 {
2771  std::shared_lock<std::shared_mutex> lock(mutex_);
2772  ar& BOOST_SERIALIZATION_NVP(impl_);
2773 }
2774 
2775 template <class Archive>
2776 void Environment::load(Archive& ar, const unsigned int /*version*/) // NOLINT
2777 {
2778  std::unique_lock<std::shared_mutex> lock(mutex_);
2779  ar& BOOST_SERIALIZATION_NVP(impl_);
2780 }
2781 
2782 template <class Archive>
2783 void Environment::serialize(Archive& ar, const unsigned int version)
2784 {
2785  boost::serialization::split_member(ar, *this, version);
2786 }
2787 
2788 } // namespace tesseract_environment
2789 
2793 
2795 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_environment::Environment)
2796 
2798 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_environment::EnvironmentPtrAnyPoly)
2799 
2801 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_environment::EnvironmentConstPtrAnyPoly)
tesseract_common::VectorIsometry3d
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
tesseract_environment::EnvironmentContactAllowedValidator
Definition: environment.cpp:79
tesseract_environment::Environment::getSceneGraph
std::shared_ptr< const tesseract_scene_graph::SceneGraph > getSceneGraph() const
Get the Scene Graph.
Definition: environment.cpp:2366
tesseract_collision::ContactManagersPluginFactory::createDiscreteContactManager
std::unique_ptr< DiscreteContactManager > createDiscreteContactManager(const std::string &name) const
tesseract_environment::Environment::getResourceLocator
std::shared_ptr< const tesseract_common::ResourceLocator > getResourceLocator() const
Get the resource locator assigned.
Definition: environment.cpp:2446
tesseract_common::JointTrajectory::empty
bool empty() const
tesseract_environment::Environment::operator!=
bool operator!=(const Environment &rhs) const
Definition: environment.cpp:2760
tesseract_collision::ContactManagersPluginFactory::hasContinuousContactManagerPlugins
bool hasContinuousContactManagerPlugins() const
graph.h
tesseract_scene_graph::SceneState::floating_joints
tesseract_common::TransformMap floating_joints
tesseract_environment::Environment::Implementation::operator==
bool operator==(const Implementation &rhs) const
Definition: environment.cpp:465
tesseract_common::ContactAllowedValidator
mutable_state_solver.h
tesseract_collision::ContinuousContactManager::UPtr
std::unique_ptr< ContinuousContactManager > UPtr
tesseract_environment
Definition: command.h:45
tesseract_environment::Environment::Implementation::kinematic_group_cache
std::map< std::pair< std::string, std::string >, std::shared_ptr< const tesseract_kinematics::KinematicGroup > > kinematic_group_cache
A cache of kinematic groups to provide faster access.
Definition: environment.cpp:293
tesseract_environment::CommandType::MODIFY_ALLOWED_COLLISIONS
@ MODIFY_ALLOWED_COLLISIONS
tesseract_environment::Environment::Implementation::find_tcp_cb
std::vector< FindTCPOffsetCallbackFn > find_tcp_cb
A vector of user defined callbacks for locating tool center point.
Definition: environment.cpp:216
tesseract_srdf::KinematicsInformation::group_tcps
GroupTCPs group_tcps
tesseract_environment::Environment::Implementation::reset
bool reset()
Definition: environment.cpp:709
tesseract_environment::ModifyAllowedCollisionsType::REPLACE
@ REPLACE
tesseract_environment::Environment::Implementation::setActiveDiscreteContactManager
bool setActiveDiscreteContactManager(const std::string &name)
Definition: environment.cpp:1111
tesseract_environment::Environment::getContinuousContactManager
std::unique_ptr< tesseract_collision::ContinuousContactManager > getContinuousContactManager() const
Get a copy of the environments active continuous contact manager.
Definition: environment.cpp:2731
tesseract_environment::Environment::getJoint
std::shared_ptr< const tesseract_scene_graph::Joint > getJoint(const std::string &name) const
Get joint by name.
Definition: environment.cpp:2583
tesseract_environment::Environment::setActiveDiscreteContactManager
bool setActiveDiscreteContactManager(const std::string &name)
Set the active discrete contact manager.
Definition: environment.cpp:2693
tesseract_environment::Environment::Implementation::group_joint_names_cache
std::unordered_map< std::string, std::vector< std::string > > group_joint_names_cache
A cache of group joint names to provide faster access.
Definition: environment.cpp:276
tesseract_scene_graph::SceneGraph::clone
SceneGraph::UPtr clone() const
tesseract_environment::Environment::Implementation::current_state
tesseract_scene_graph::SceneState current_state
Current state of the environment.
Definition: environment.cpp:193
tesseract_environment::CommandType::ADD_SCENE_GRAPH
@ ADD_SCENE_GRAPH
tesseract_environment::Environment::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: environment.cpp:2783
tesseract_environment::Environment::Implementation::applyChangeJointPositionLimitsCommand
bool applyChangeJointPositionLimitsCommand(const std::shared_ptr< const ChangeJointPositionLimitsCommand > &cmd)
Definition: environment.cpp:1919
tesseract_environment::CommandType::CHANGE_JOINT_VELOCITY_LIMITS
@ CHANGE_JOINT_VELOCITY_LIMITS
tesseract_common::isIdentical
bool isIdentical(const std::vector< T > &vec1, const std::vector< T > &vec2, bool ordered=true, const std::function< bool(const T &, const T &)> &equal_pred=[](const T &v1, const T &v2) { return v1==v2;}, const std::function< bool(const T &, const T &)> &comp=[](const T &v1, const T &v2) { return v1< v2;})
tesseract_environment::Environment::Implementation::scene_graph
std::shared_ptr< tesseract_scene_graph::SceneGraph > scene_graph
Tesseract Scene Graph.
Definition: environment.cpp:190
tesseract_environment::Environment::Implementation::kinematics_information
tesseract_srdf::KinematicsInformation kinematics_information
The kinematics information.
Definition: environment.cpp:237
tesseract_environment::CommandType::CHANGE_JOINT_ACCELERATION_LIMITS
@ CHANGE_JOINT_ACCELERATION_LIMITS
tesseract_environment::Environment::clearEventCallbacks
void clearEventCallbacks()
clear all event callbacks
Definition: environment.cpp:2428
tesseract_common::ContactManagersPluginInfo::clear
void clear()
tesseract_environment::CommandType::CHANGE_JOINT_ORIGIN
@ CHANGE_JOINT_ORIGIN
tesseract_environment::Environment::getCollisionMarginData
tesseract_common::CollisionMarginData getCollisionMarginData() const
Get the environment collision margin data.
Definition: environment.cpp:2743
tesseract_common::CollisionMarginPairOverrideType::REPLACE
@ REPLACE
tesseract_environment::Environment::Implementation::getContinuousContactManagerHelper
std::unique_ptr< tesseract_collision::ContinuousContactManager > getContinuousContactManagerHelper(const std::string &name) const
Definition: environment.cpp:1072
tesseract_environment::CommandType::REMOVE_ALLOWED_COLLISION_LINK
@ REMOVE_ALLOWED_COLLISION_LINK
tesseract_environment::Environment::getTimestamp
std::chrono::system_clock::time_point getTimestamp() const
Last update time. Updated when any change to the environment occurs.
Definition: environment.cpp:2527
manipulator_info.h
utils.h
tesseract_environment::Environment::Implementation::clearCachedContinuousContactManager
void clearCachedContinuousContactManager() const
Definition: environment.cpp:988
tesseract_environment::Environment::Implementation::applyRemoveJointCommand
bool applyRemoveJointCommand(const std::shared_ptr< const RemoveJointCommand > &cmd)
Definition: environment.cpp:1674
tesseract_environment::Environment::Implementation::applyRemoveLinkCommand
bool applyRemoveLinkCommand(const std::shared_ptr< const RemoveLinkCommand > &cmd)
Definition: environment.cpp:1660
tesseract_environment::Environment::Implementation::triggerCurrentStateChangedCallbacks
void triggerCurrentStateChangedCallbacks()
Passes a current state changed event to the callbacks.
Definition: environment.cpp:778
tesseract_scene_graph::ShortestPath::active_joints
std::vector< std::string > active_joints
tesseract_environment::Environment::setResourceLocator
void setResourceLocator(std::shared_ptr< const tesseract_common::ResourceLocator > locator)
Set resource locator for environment.
Definition: environment.cpp:2440
tesseract_environment::Environment::Implementation::getCurrentJointValues
Eigen::VectorXd getCurrentJointValues() const
Definition: environment.cpp:609
tesseract_kinematics::KinematicsPluginFactory::addInvKinPlugin
void addInvKinPlugin(const std::string &group_name, const std::string &solver_name, tesseract_common::PluginInfo plugin_info)
tesseract_environment::Environment::Implementation::applySetActiveDiscreteContactManagerCommand
bool applySetActiveDiscreteContactManagerCommand(const std::shared_ptr< const SetActiveDiscreteContactManagerCommand > &cmd)
Definition: environment.cpp:2115
tesseract_environment::Environment::applyCommand
bool applyCommand(std::shared_ptr< const Command > command)
Apply command to the environment.
Definition: environment.cpp:2364
tesseract_environment::Environment::load
void load(Archive &ar, const unsigned int version)
Definition: environment.cpp:2776
tesseract_environment::Environment::Implementation::current_state_timestamp
std::chrono::system_clock::time_point current_state_timestamp
Current state timestamp.
Definition: environment.cpp:199
tesseract_environment::Environment::Environment
Environment()
Default constructor.
Definition: environment.cpp:2152
tesseract_environment::Environment::clear
void clear()
clear content and uninitialized
Definition: environment.cpp:2321
tesseract_environment::Environment::getStaticLinkNames
std::vector< std::string > getStaticLinkNames() const
Get a vector of static link names in the environment.
Definition: environment.cpp:2638
tesseract_scene_graph::JointLimits::ConstPtr
std::shared_ptr< const JointLimits > ConstPtr
resource_locator.h
tesseract_environment::Environment::getLinkTransform
Eigen::Isometry3d getLinkTransform(const std::string &link_name) const
Get the transform corresponding to the link.
Definition: environment.cpp:2656
tesseract_environment::Environment::Implementation::getCurrentFloatingJointValues
tesseract_common::TransformMap getCurrentFloatingJointValues() const
Definition: environment.cpp:630
tesseract_environment::Environment::mutex_
std::shared_mutex mutex_
The environment can be accessed from multiple threads, need use mutex throughout.
Definition: environment.h:570
tesseract_environment::Environment::Implementation::discrete_manager
std::unique_ptr< tesseract_collision::DiscreteContactManager > discrete_manager
The discrete contact manager object.
Definition: environment.cpp:261
tesseract_collision::ContactManagersPluginFactory::addSearchLibrary
void addSearchLibrary(const std::string &library_name)
tesseract_common::TransformMap
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
tesseract_environment::CommandType::CHANGE_COLLISION_MARGINS
@ CHANGE_COLLISION_MARGINS
tesseract_common::ManipulatorInfo
tesseract_environment::EnvironmentContactAllowedValidator::scene_graph_
std::shared_ptr< const tesseract_scene_graph::SceneGraph > scene_graph_
Definition: environment.cpp:94
tesseract_environment::Environment::Implementation::continuous_manager_mutex
std::shared_mutex continuous_manager_mutex
Definition: environment.cpp:269
tesseract_environment::AddLinkCommand::ConstPtr
std::shared_ptr< const AddLinkCommand > ConstPtr
Definition: add_link_command.h:49
tesseract_environment::Environment::Implementation::timestamp
std::chrono::system_clock::time_point timestamp
Environment timestamp.
Definition: environment.cpp:196
tesseract_common::CollisionMarginPairData::empty
bool empty() const
tesseract_environment::Environment::clearCachedContinuousContactManager
void clearCachedContinuousContactManager() const
Set the cached internal copy of the environments active continuous contact manager not nullptr.
Definition: environment.cpp:2737
tesseract_environment::Environment::Implementation::setActiveContinuousContactManagerHelper
bool setActiveContinuousContactManagerHelper(const std::string &name)
Definition: environment.cpp:1016
tesseract_kinematics::checkKinematics
bool checkKinematics(const KinematicGroup &manip, double tol=1e-3)
tesseract_environment::Environment::Implementation::applyModifyAllowedCollisionsCommand
bool applyModifyAllowedCollisionsCommand(const std::shared_ptr< const ModifyAllowedCollisionsCommand > &cmd)
Definition: environment.cpp:1799
common.h
tesseract_environment::Environment::Implementation::applyChangeJointVelocityLimitsCommand
bool applyChangeJointVelocityLimitsCommand(const std::shared_ptr< const ChangeJointVelocityLimitsCommand > &cmd)
Definition: environment.cpp:1949
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE
#define TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(Type)
tesseract_environment::Environment::Implementation::triggerEnvironmentChangedCallbacks
void triggerEnvironmentChangedCallbacks()
Passes a environment changed event to the callbacks.
Definition: environment.cpp:788
tesseract_environment::Environment::Implementation::clone
std::unique_ptr< Implementation > clone() const
Definition: environment.cpp:496
tesseract_collision::ContactManagersPluginFactory::createContinuousContactManager
std::unique_ptr< ContinuousContactManager > createContinuousContactManager(const std::string &name) const
tesseract_environment::Environment::getCurrentStateTimestamp
std::chrono::system_clock::time_point getCurrentStateTimestamp() const
Last update time to current state. Updated only when current state is updated.
Definition: environment.cpp:2533
collision_margin_data.h
tesseract_environment::Environment::Implementation
Definition: environment.cpp:164
joint.h
tesseract_scene_graph::Joint::parent_to_joint_origin_transform
Eigen::Isometry3d parent_to_joint_origin_transform
tesseract_environment::Environment::Implementation::joint_group_cache
std::unordered_map< std::string, std::shared_ptr< const tesseract_kinematics::JointGroup > > joint_group_cache
A cache of joint groups to provide faster access.
Definition: environment.cpp:284
tesseract_environment::AddTrajectoryLinkCommand::ConstPtr
std::shared_ptr< const AddTrajectoryLinkCommand > ConstPtr
Definition: add_trajectory_link_command.h:49
tesseract_environment::CommandType::MOVE_JOINT
@ MOVE_JOINT
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_common::AnyWrapper
tesseract_environment::CommandType::ADD_KINEMATICS_INFORMATION
@ ADD_KINEMATICS_INFORMATION
ofkt_state_solver.h
tesseract_collision::ContactManagersPluginFactory::getDefaultDiscreteContactManagerPlugin
std::string getDefaultDiscreteContactManagerPlugin() const
tesseract_environment::Environment::Implementation::getJointGroup
std::shared_ptr< const tesseract_kinematics::JointGroup > getJointGroup(const std::string &group_name) const
Definition: environment.cpp:844
contact_managers_plugin_factory.h
tesseract_environment::Environment::Implementation::applyReplaceJointCommand
bool applyReplaceJointCommand(const std::shared_ptr< const ReplaceJointCommand > &cmd)
Definition: environment.cpp:1696
tesseract_environment::Environment::getName
const std::string & getName() const
Get the name of the environment.
Definition: environment.cpp:2458
tesseract_environment::Environment::getCommandHistory
std::vector< std::shared_ptr< const Command > > getCommandHistory() const
Get Environment command history post initialization.
Definition: environment.cpp:2345
tesseract_environment::CommandType::MOVE_LINK
@ MOVE_LINK
tesseract_scene_graph::SceneGraph
tesseract_environment::Environment::Implementation::resource_locator
std::shared_ptr< const tesseract_common::ResourceLocator > resource_locator
Used when initialized by URDF_STRING, URDF_STRING_SRDF_STRING, URDF_PATH, and URDF_PATH_SRDF_PATH.
Definition: environment.cpp:225
tesseract_scene_graph::Joint::ConstPtr
std::shared_ptr< const Joint > ConstPtr
tesseract_common::Serialization
tesseract_environment::Environment::Implementation::getKinematicGroup
std::shared_ptr< const tesseract_kinematics::KinematicGroup > getKinematicGroup(const std::string &group_name, std::string ik_solver_name) const
Definition: environment.cpp:866
tesseract_environment::EnvironmentContactAllowedValidator::serialize
void serialize(Archive &ar, const unsigned int)
Definition: environment.cpp:100
tesseract_common::ContactManagersPluginInfo::discrete_plugin_infos
tesseract_common::PluginInfoContainer discrete_plugin_infos
tesseract_common::CollisionMarginData
tesseract_environment::Environment::getLinkTransforms
tesseract_common::VectorIsometry3d getLinkTransforms() const
Get all of the links transforms.
Definition: environment.cpp:2650
tesseract_environment::Environment::getRevision
int getRevision() const
Get the current revision number.
Definition: environment.cpp:2333
tesseract_environment::Environment::Implementation::group_joint_names_cache_mutex
std::shared_mutex group_joint_names_cache_mutex
Definition: environment.cpp:277
kinematics_plugin_factory.h
tesseract_environment::Environment::getStateSolver
std::unique_ptr< tesseract_scene_graph::StateSolver > getStateSolver() const
Returns a clone of the environments state solver.
Definition: environment.cpp:2669
tesseract_environment::Environment::Implementation::initialized
bool initialized
Identifies if the object has been initialized.
Definition: environment.cpp:172
tesseract_environment::Environment::Implementation::setActiveDiscreteContactManagerHelper
bool setActiveDiscreteContactManagerHelper(const std::string &name)
Definition: environment.cpp:994
tesseract_collision::ContactManagersPluginFactory::addSearchPath
void addSearchPath(const std::string &path)
tesseract_kinematics::InverseKinematics::UPtr
std::unique_ptr< InverseKinematics > UPtr
tesseract_environment::Environment::getState
tesseract_scene_graph::SceneState getState() const
Get the current state of the environment.
Definition: environment.cpp:2521
tesseract_environment::Environment::Implementation::applyChangeJointAccelerationLimitsCommand
bool applyChangeJointAccelerationLimitsCommand(const std::shared_ptr< const ChangeJointAccelerationLimitsCommand > &cmd)
Definition: environment.cpp:1978
urdf_parser.h
events.h
Tesseract Events.
tesseract_environment::EnvironmentContactAllowedValidator::access
friend class boost::serialization::access
Definition: environment.cpp:97
tesseract_common::ContactManagersPluginInfo::continuous_plugin_infos
tesseract_common::PluginInfoContainer continuous_plugin_infos
tesseract_environment::Environment::getCurrentJointValues
Eigen::VectorXd getCurrentJointValues() const
Get the current state of the environment.
Definition: environment.cpp:2589
tesseract_scene_graph::SceneGraph::ConstPtr
std::shared_ptr< const SceneGraph > ConstPtr
tesseract_scene_graph::SceneState
tesseract_kinematics::KinematicsPluginFactory::getDefaultInvKinPlugin
std::string getDefaultInvKinPlugin(const std::string &group_name) const
command.h
This contains classes for recording operations applied to the environment for tracking changes....
tesseract_common::ManipulatorInfo::tcp_offset
std::variant< std::string, Eigen::Isometry3d > tcp_offset
tesseract_environment::ModifyAllowedCollisionsType::REMOVE
@ REMOVE
tesseract_environment::CommandType::ADD_LINK
@ ADD_LINK
tesseract_environment::ModifyAllowedCollisionsType::ADD
@ ADD
discrete_contact_manager.h
tesseract_environment::Environment::Implementation::getDiscreteContactManagerHelper
std::unique_ptr< tesseract_collision::DiscreteContactManager > getDiscreteContactManagerHelper(const std::string &name) const
Definition: environment.cpp:1040
tesseract_environment::Environment::clone
Environment::UPtr clone() const
Clone the environment.
Definition: environment.cpp:2762
utils.h
Tesseract Environment Utility Functions.
tesseract_environment::Environment::Implementation::state_solver
std::unique_ptr< tesseract_scene_graph::MutableStateSolver > state_solver
Tesseract State Solver.
Definition: environment.cpp:205
tesseract_scene_graph::MutableStateSolver
tesseract_scene_graph::JointLimits::upper
double upper
tesseract_environment::Environment::Implementation::environmentChanged
void environmentChanged()
Definition: environment.cpp:753
tesseract_environment::Environment::getGroupNames
std::set< std::string > getGroupNames() const
Get the available group names.
Definition: environment.cpp:2681
kinematics_information.h
tesseract_environment::Environment::Implementation::kinematic_group_cache_mutex
std::shared_mutex kinematic_group_cache_mutex
Definition: environment.cpp:294
tesseract_srdf::KinematicsInformation::link_groups
LinkGroups link_groups
tesseract_environment::Environment::impl_
std::unique_ptr< Implementation > impl_
Definition: environment.h:573
tesseract_environment::getCollisionObject
void getCollisionObject(std::vector< std::shared_ptr< const tesseract_geometry::Geometry >> &shapes, tesseract_common::VectorIsometry3d &shape_poses, const tesseract_scene_graph::Link &link)
Definition: environment.cpp:107
name
std::string name
tesseract_urdf::parseURDFFile
std::unique_ptr< tesseract_scene_graph::SceneGraph > parseURDFFile(const std::string &path, const tesseract_common::ResourceLocator &locator)
tesseract_environment::Environment::Implementation::contact_managers_factory
tesseract_collision::ContactManagersPluginFactory contact_managers_factory
The contact managers factory.
Definition: environment.cpp:255
tesseract_environment::Environment::Implementation::revision
int revision
This increments when the scene graph is modified.
Definition: environment.cpp:178
tesseract_environment::Environment::Implementation::event_cb
std::map< std::size_t, EventCallbackFn > event_cb
A map of user defined event callback functions.
Definition: environment.cpp:222
tesseract_environment::Environment::addEventCallback
void addEventCallback(std::size_t hash, const EventCallbackFn &fn)
Add an event callback function.
Definition: environment.cpp:2416
tesseract_environment::Environment::getKinematicsInformation
tesseract_srdf::KinematicsInformation getKinematicsInformation() const
Get the kinematics information.
Definition: environment.cpp:2675
tesseract_environment::Environment::Implementation::findTCPOffset
Eigen::Isometry3d findTCPOffset(const tesseract_common::ManipulatorInfo &manip_info) const
Definition: environment.cpp:903
tesseract_environment::Environment::Implementation::joint_group_cache_mutex
std::shared_mutex joint_group_cache_mutex
Definition: environment.cpp:285
tesseract_collision::ContactManagersPluginFactory::setDefaultDiscreteContactManagerPlugin
void setDefaultDiscreteContactManagerPlugin(const std::string &name)
tesseract_scene_graph::Joint::child_link_name
std::string child_link_name
tesseract_environment::EnvironmentContactAllowedValidator::EnvironmentContactAllowedValidator
EnvironmentContactAllowedValidator()=default
tesseract_environment::Environment::Implementation::kinematics_factory
tesseract_kinematics::KinematicsPluginFactory kinematics_factory
The kinematics factory.
Definition: environment.cpp:243
tesseract_environment::CommandType::CHANGE_JOINT_POSITION_LIMITS
@ CHANGE_JOINT_POSITION_LIMITS
tesseract_environment::CommandType::REMOVE_JOINT
@ REMOVE_JOINT
tesseract_srdf::KinematicsInformation::group_names
EIGEN_MAKE_ALIGNED_OPERATOR_NEW GroupNames group_names
tesseract_environment::Environment::getRootLinkName
std::string getRootLinkName() const
Get the root link name.
Definition: environment.cpp:2614
tesseract_srdf::KinematicsInformation::insert
void insert(const KinematicsInformation &other)
tesseract_environment::Environment::Implementation::clearCachedDiscreteContactManager
void clearCachedDiscreteContactManager() const
Definition: environment.cpp:982
tesseract_environment::Environment::~Environment
virtual ~Environment()
tesseract_environment::Environment::Implementation::discrete_manager_mutex
std::shared_mutex discrete_manager_mutex
Definition: environment.cpp:262
serialization.h
tesseract_environment::Environment::getDiscreteContactManager
std::unique_ptr< tesseract_collision::DiscreteContactManager > getDiscreteContactManager() const
Get a copy of the environments active discrete contact manager.
Definition: environment.cpp:2719
tesseract_common::JointTrajectory
tesseract_environment::Environment::Implementation::clear
void clear()
Definition: environment.cpp:665
tesseract_common::ContactManagersPluginInfo
tesseract_environment::CommandAppliedEvent
The command applied event.
Definition: events.h:64
tesseract_environment::Environment::Implementation::continuous_manager
std::unique_ptr< tesseract_collision::ContinuousContactManager > continuous_manager
The continuous contact manager object.
Definition: environment.cpp:268
tesseract_environment::Environment::UPtr
std::unique_ptr< Environment > UPtr
Definition: environment.h:80
tesseract_environment::Environment::Implementation::applyRemoveAllowedCollisionLinkCommand
bool applyRemoveAllowedCollisionLinkCommand(const std::shared_ptr< const RemoveAllowedCollisionLinkCommand > &cmd)
Definition: environment.cpp:1833
tesseract_collision::ContactManagersPluginFactory::getContinuousContactManagerPlugins
tesseract_common::PluginInfoMap getContinuousContactManagerPlugins() const
tesseract_kinematics::KinematicsPluginFactory::createInvKin
std::unique_ptr< InverseKinematics > createInvKin(const std::string &group_name, const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state) const
tesseract_environment::CommandType::REPLACE_JOINT
@ REPLACE_JOINT
tesseract_environment::Environment::Implementation::applyMoveLinkCommand
bool applyMoveLinkCommand(const std::shared_ptr< const MoveLinkCommand > &cmd)
Definition: environment.cpp:1632
tesseract_environment::Environment::getLink
std::shared_ptr< const tesseract_scene_graph::Link > getLink(const std::string &name) const
Get a link in the environment.
Definition: environment.cpp:2539
tesseract_environment::Environment::Implementation::applyChangeJointOriginCommand
bool applyChangeJointOriginCommand(const std::shared_ptr< const ChangeJointOriginCommand > &cmd)
Definition: environment.cpp:1740
tesseract_scene_graph::SceneState::joints
std::unordered_map< std::string, double > joints
tesseract_environment::Environment::Implementation::applyAddKinematicsInformationCommand
bool applyAddKinematicsInformationCommand(const std::shared_ptr< const AddKinematicsInformationCommand > &cmd)
Definition: environment.cpp:2007
tesseract_common::printNestedException
void printNestedException(const std::exception &e, int level=0)
kinematic_group.h
tesseract_environment::Environment::addFindTCPOffsetCallback
void addFindTCPOffsetCallback(const FindTCPOffsetCallbackFn &fn)
This allows for user defined callbacks for looking up TCP information.
Definition: environment.cpp:2404
tesseract_kinematics::KinematicsPluginFactory::addSearchLibrary
void addSearchLibrary(const std::string &library_name)
tesseract_environment::CommandType::SET_ACTIVE_CONTINUOUS_CONTACT_MANAGER
@ SET_ACTIVE_CONTINUOUS_CONTACT_MANAGER
tesseract_environment::Environment::getLinkVisibility
bool getLinkVisibility(const std::string &name) const
Get a given links visibility setting.
Definition: environment.cpp:2559
tesseract_environment::Environment::reset
bool reset()
reset to initialized state
Definition: environment.cpp:2306
tesseract_environment::CommandType::CHANGE_LINK_ORIGIN
@ CHANGE_LINK_ORIGIN
tesseract_environment::Environment::Implementation::applyAddSceneGraphCommand
bool applyAddSceneGraphCommand(std::shared_ptr< const AddSceneGraphCommand > cmd)
Definition: environment.cpp:1844
tesseract_srdf::KinematicsInformation
tesseract_collision::CollisionShapesConst
std::vector< CollisionShapeConstPtr > CollisionShapesConst
tesseract_common::PluginInfoContainer::default_plugin
std::string default_plugin
tesseract_environment::CommandType::SET_ACTIVE_DISCRETE_CONTACT_MANAGER
@ SET_ACTIVE_DISCRETE_CONTACT_MANAGER
tesseract_environment::Environment::Implementation::initHelper
bool initHelper(const std::vector< std::shared_ptr< const Command >> &commands)
Definition: environment.cpp:555
tesseract_environment::Environment::Implementation::~Implementation
~Implementation()=default
tesseract_scene_graph::JointLimits::acceleration
double acceleration
tesseract_common::CollisionMarginData::apply
void apply(const CollisionMarginPairData &pair_margin_data, CollisionMarginPairOverrideType override_type)
tesseract_environment::Environment::Implementation::applyChangeLinkVisibilityCommand
bool applyChangeLinkVisibilityCommand(const std::shared_ptr< const ChangeLinkVisibilityCommand > &cmd)
Definition: environment.cpp:1786
tesseract_environment::Environment::lockRead
std::shared_lock< std::shared_mutex > lockRead() const
Lock the environment when wanting to make multiple reads.
Definition: environment.cpp:2749
tesseract_environment::Environment
Definition: environment.h:71
tesseract_environment::Environment::Implementation::applyAddCommand
bool applyAddCommand(const std::shared_ptr< const AddLinkCommand > &cmd)
Definition: environment.cpp:1354
tesseract_kinematics::KinematicsPluginFactory::addSearchPath
void addSearchPath(const std::string &path)
tesseract_environment::Environment::getLinkNames
std::vector< std::string > getLinkNames() const
Get a vector of link names in the environment.
Definition: environment.cpp:2620
tesseract_environment::Environment::Implementation::load
void load(Archive &ar, const unsigned int)
Definition: environment.cpp:434
TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_environment::Environment::Implementation::applyMoveJointCommand
bool applyMoveJointCommand(const std::shared_ptr< const MoveJointCommand > &cmd)
Definition: environment.cpp:1646
tesseract_collision::ContactManagersPluginFactory::hasDiscreteContactManagerPlugins
bool hasDiscreteContactManagerPlugins() const
tesseract_scene_graph::ShortestPath
tesseract_scene_graph::JointLimits
tesseract_environment::CommandType::CHANGE_LINK_COLLISION_ENABLED
@ CHANGE_LINK_COLLISION_ENABLED
tesseract_environment::Environment::Implementation::collision_margin_data
tesseract_common::CollisionMarginData collision_margin_data
The collision margin data.
Definition: environment.cpp:231
tesseract_environment::Environment::Implementation::setState
void setState(const std::unordered_map< std::string, double > &joints, const tesseract_common::TransformMap &floating_joints={})
Definition: environment.cpp:588
tesseract_environment::Environment::operator==
bool operator==(const Environment &rhs) const
These operators are to facilitate checking serialization but may have value elsewhere.
Definition: environment.cpp:2754
tesseract_environment::SceneStateChangedEvent
The scene state changed event.
Definition: events.h:77
tesseract_environment::getInitCommands
std::vector< std::shared_ptr< const Command > > getInitCommands(const tesseract_scene_graph::SceneGraph &scene_graph, const std::shared_ptr< const tesseract_srdf::SRDFModel > &srdf_model=nullptr)
Definition: environment.cpp:119
tesseract_environment::Environment::Implementation::applyChangeCollisionMarginsCommand
bool applyChangeCollisionMarginsCommand(const std::shared_ptr< const ChangeCollisionMarginsCommand > &cmd)
Definition: environment.cpp:2126
continuous_contact_manager.h
validate.h
tesseract_environment::CommandType::CHANGE_LINK_VISIBILITY
@ CHANGE_LINK_VISIBILITY
tesseract_environment::Environment::Implementation::contact_managers_plugin_info
tesseract_common::ContactManagersPluginInfo contact_managers_plugin_info
The contact manager information.
Definition: environment.cpp:249
tesseract_scene_graph::Joint
tesseract_environment::Environment::Implementation::applyAddTrajectoryLinkCommand
bool applyAddTrajectoryLinkCommand(const std::shared_ptr< const AddTrajectoryLinkCommand > &cmd)
Definition: environment.cpp:1370
tesseract_common::CollisionMarginPairData
tesseract_environment::Environment::getJointLimits
std::shared_ptr< const tesseract_scene_graph::JointLimits > getJointLimits(const std::string &joint_name) const
Gets the limits associated with a joint.
Definition: environment.cpp:2547
tesseract_environment::EnvironmentContactAllowedValidator::operator()
bool operator()(const std::string &link_name1, const std::string &link_name2) const override
Definition: environment.cpp:88
tesseract_environment::Environment::getGroupJointNames
std::vector< std::string > getGroupJointNames(const std::string &group_name) const
Get a groups joint names.
Definition: environment.cpp:2371
srdf_model.h
tesseract_environment::Environment::Implementation::currentStateChanged
void currentStateChanged()
Definition: environment.cpp:722
tesseract_srdf::KinematicsInformation::joint_groups
JointGroups joint_groups
tesseract_collision::ContactManagersPluginFactory::addContinuousContactManagerPlugin
void addContinuousContactManagerPlugin(const std::string &name, tesseract_common::PluginInfo plugin_info)
tesseract_environment::EventCallbackFn
std::function< void(const Event &event)> EventCallbackFn
Definition: environment.h:69
tesseract_environment::Environment::getKinematicGroup
std::shared_ptr< const tesseract_kinematics::KinematicGroup > getKinematicGroup(const std::string &group_name, const std::string &ik_solver_name="") const
Get a kinematic group given group name and solver name.
Definition: environment.cpp:2391
tesseract_collision::ContactManagersPluginFactory
tesseract_environment::FindTCPOffsetCallbackFn
std::function< Eigen::Isometry3d(const tesseract_common::ManipulatorInfo &)> FindTCPOffsetCallbackFn
Function signature for adding additional callbacks for looking up TCP information.
Definition: environment.h:67
tesseract_environment::Environment::Implementation::init_revision
int init_revision
This is the revision number after initialization used when reset is called.
Definition: environment.cpp:181
tesseract_environment::Environment::getJointGroup
std::shared_ptr< const tesseract_kinematics::JointGroup > getJointGroup(const std::string &group_name) const
Get a joint group by name.
Definition: environment.cpp:2377
tesseract_environment::ChangeJointOriginCommand::ConstPtr
std::shared_ptr< const ChangeJointOriginCommand > ConstPtr
Definition: change_joint_origin_command.h:54
tesseract_environment::Environment::Implementation::getGroupJointNames
std::vector< std::string > getGroupJointNames(const std::string &group_name) const
Definition: environment.cpp:804
tesseract_environment::Environment::Implementation::applyChangeLinkOriginCommand
bool applyChangeLinkOriginCommand(const std::shared_ptr< const ChangeLinkOriginCommand > &cmd)
Definition: environment.cpp:1734
tesseract_common::ContactAllowedValidator::ConstPtr
std::shared_ptr< const ContactAllowedValidator > ConstPtr
tesseract_environment::Environment::Implementation::applyCommandsHelper
bool applyCommandsHelper(const std::vector< std::shared_ptr< const Command >> &commands)
Apply Command Helper which does not lock.
Definition: environment.cpp:1182
scene_state.h
tesseract_environment::Environment::Implementation::triggerCallbacks
void triggerCallbacks()
Trigger both Current State and Environment changed callback.
Definition: environment.cpp:798
tesseract_environment::Environment::Implementation::save
void save(Archive &ar, const unsigned int) const
Definition: environment.cpp:418
tesseract_common::ContactManagersPluginInfo::insert
void insert(const ContactManagersPluginInfo &other)
tesseract_srdf::KinematicsInformation::clear
void clear()
tesseract_environment::Environment::getFindTCPOffsetCallbacks
std::vector< FindTCPOffsetCallbackFn > getFindTCPOffsetCallbacks() const
This get the current find tcp callbacks stored in the environment.
Definition: environment.cpp:2410
tesseract_srdf::KinematicsInformation::hasGroupTCP
bool hasGroupTCP(const std::string &group_name, const std::string &tcp_name) const
tesseract_kinematics::KinematicsPluginFactory::setDefaultInvKinPlugin
void setDefaultInvKinPlugin(const std::string &group_name, const std::string &solver_name)
tesseract_environment::Environment::getInitRevision
int getInitRevision() const
Get the initialization revision number.
Definition: environment.cpp:2339
tesseract_kinematics::JointGroup::ConstPtr
std::shared_ptr< const JointGroup > ConstPtr
environment.h
tesseract_environment::Environment::Implementation::contact_allowed_validator
tesseract_common::ContactAllowedValidator::ConstPtr contact_allowed_validator
The validator used to determine if two objects are allowed in collision.
Definition: environment.cpp:210
tesseract_common::ManipulatorInfo::manipulator
std::string manipulator
tesseract_common::CollisionMarginData::setDefaultCollisionMargin
void setDefaultCollisionMargin(double default_collision_margin)
tesseract_environment::CommandType::REMOVE_LINK
@ REMOVE_LINK
tesseract_collision::ContactManagersPluginFactory::getDiscreteContactManagerPlugins
tesseract_common::PluginInfoMap getDiscreteContactManagerPlugins() const
tesseract_collision::ContactManagersPluginFactory::addDiscreteContactManagerPlugin
void addDiscreteContactManagerPlugin(const std::string &name, tesseract_common::PluginInfo plugin_info)
tesseract_scene_graph::Joint::type
JointType type
tesseract_environment::EnvironmentContactAllowedValidator::EnvironmentContactAllowedValidator
EnvironmentContactAllowedValidator(std::shared_ptr< const tesseract_scene_graph::SceneGraph > scene_graph)
Definition: environment.cpp:83
tesseract_environment::Environment::save
void save(Archive &ar, const unsigned int version) const
Definition: environment.cpp:2769
tesseract_environment::Environment::getCurrentFloatingJointValues
tesseract_common::TransformMap getCurrentFloatingJointValues() const
Get the current floating joint values.
Definition: environment.cpp:2601
tesseract_environment::Environment::getLinkCollisionEnabled
bool getLinkCollisionEnabled(const std::string &name) const
Get whether a link should be considered during collision checking.
Definition: environment.cpp:2553
tesseract_environment::CommandType::ADD_TRAJECTORY_LINK
@ ADD_TRAJECTORY_LINK
tesseract_environment::Environment::getRelativeLinkTransform
Eigen::Isometry3d getRelativeLinkTransform(const std::string &from_link_name, const std::string &to_link_name) const
Get transform between two links using the current state.
Definition: environment.cpp:2662
tesseract_srdf::processSRDFAllowedCollisions
void processSRDFAllowedCollisions(tesseract_scene_graph::SceneGraph &scene_graph, const SRDFModel &srdf_model)
commands.h
This contains classes for recording operations applied to the environment for tracking changes....
tesseract_scene_graph::JointLimits::velocity
double velocity
tesseract_environment::Environment::Implementation::getDiscreteContactManager
std::unique_ptr< tesseract_collision::DiscreteContactManager > getDiscreteContactManager() const
Definition: environment.cpp:937
tesseract_environment::Environment::Implementation::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: environment.cpp:459
tesseract_collision::DiscreteContactManager::UPtr
std::unique_ptr< DiscreteContactManager > UPtr
tesseract_environment::Environment::isInitialized
bool isInitialized() const
check if the environment is initialized
Definition: environment.cpp:2327
tesseract_environment::Environment::getEventCallbacks
std::map< std::size_t, EventCallbackFn > getEventCallbacks() const
Get the current event callbacks stored in the environment.
Definition: environment.cpp:2434
joint_group.h
tesseract_scene_graph::SceneState::link_transforms
tesseract_common::TransformMap link_transforms
tesseract_environment::Environment::Implementation::removeLinkHelper
bool removeLinkHelper(const std::string &name)
Definition: environment.cpp:1149
tesseract_collision::ContactManagersPluginFactory::getDefaultContinuousContactManagerPlugin
std::string getDefaultContinuousContactManagerPlugin() const
types.h
tesseract_environment::Environment::Implementation::getStaticLinkNames
std::vector< std::string > getStaticLinkNames(const std::vector< std::string > &joint_names) const
Definition: environment.cpp:646
tesseract_environment::CommandType::ADD_CONTACT_MANAGERS_PLUGIN_INFO
@ ADD_CONTACT_MANAGERS_PLUGIN_INFO
inverse_kinematics.h
tesseract_scene_graph::SceneGraph::Ptr
std::shared_ptr< SceneGraph > Ptr
tesseract_environment::Environment::getActiveLinkNames
std::vector< std::string > getActiveLinkNames() const
Get a vector of active link names in the environment.
Definition: environment.cpp:2626
tesseract_environment::Environment::getAllowedCollisionMatrix
std::shared_ptr< const tesseract_common::AllowedCollisionMatrix > getAllowedCollisionMatrix() const
Get the allowed collision matrix.
Definition: environment.cpp:2565
tesseract_kinematics::KinematicsPluginFactory
tesseract_scene_graph::JointLimits::lower
double lower
tesseract_environment::Environment::setState
void setState(const std::unordered_map< std::string, double > &joints, const tesseract_common::TransformMap &floating_joints={})
Set the current state of the environment.
Definition: environment.cpp:2464
tesseract_environment::Environment::getContactManagersPluginInfo
tesseract_common::ContactManagersPluginInfo getContactManagersPluginInfo() const
Get the contact managers plugin information.
Definition: environment.cpp:2687
tesseract_kinematics::KinematicsPluginFactory::addFwdKinPlugin
void addFwdKinPlugin(const std::string &group_name, const std::string &solver_name, tesseract_common::PluginInfo plugin_info)
tesseract_urdf::parseURDFString
std::unique_ptr< tesseract_scene_graph::SceneGraph > parseURDFString(const std::string &urdf_xml_string, const tesseract_common::ResourceLocator &locator)
tesseract_environment::Environment::Implementation::applySetActiveContinuousContactManagerCommand
bool applySetActiveContinuousContactManagerCommand(const std::shared_ptr< const SetActiveContinuousContactManagerCommand > &cmd)
Definition: environment.cpp:2104
tesseract_environment::Environment::Implementation::applyAddContactManagersPluginInfoCommand
bool applyAddContactManagersPluginInfoCommand(const std::shared_ptr< const AddContactManagersPluginInfoCommand > &cmd)
Definition: environment.cpp:2046
tesseract_srdf::KinematicsInformation::chain_groups
ChainGroups chain_groups
tesseract_environment::Environment::Implementation::getContinuousContactManager
std::unique_ptr< tesseract_collision::ContinuousContactManager > getContinuousContactManager() const
Definition: environment.cpp:960
tesseract_kinematics::KinematicsPluginFactory::setDefaultFwdKinPlugin
void setDefaultFwdKinPlugin(const std::string &group_name, const std::string &solver_name)
tesseract_environment::Environment::removeEventCallback
void removeEventCallback(std::size_t hash)
Remove event callbacks.
Definition: environment.cpp:2422
tesseract_environment::Environment::getJointNames
std::vector< std::string > getJointNames() const
Get a vector of joint names in the environment.
Definition: environment.cpp:2571
tesseract_environment::Environment::Implementation::commands
std::vector< std::shared_ptr< const Command > > commands
The history of commands applied to the environment after initialization.
Definition: environment.cpp:184
tesseract_environment::Environment::clearCachedDiscreteContactManager
void clearCachedDiscreteContactManager() const
Set the cached internal copy of the environments active discrete contact manager not nullptr.
Definition: environment.cpp:2725
tesseract_environment::Environment::applyCommands
bool applyCommands(const std::vector< std::shared_ptr< const Command >> &commands)
Applies the commands to the environment.
Definition: environment.cpp:2351
tesseract_scene_graph::Joint::parent_link_name
std::string parent_link_name
tesseract_collision::ContactManagersPluginFactory::setDefaultContinuousContactManagerPlugin
void setDefaultContinuousContactManagerPlugin(const std::string &name)
tesseract_environment::Environment::Implementation::applyAddLinkCommandHelper
bool applyAddLinkCommandHelper(const std::shared_ptr< const tesseract_scene_graph::Link > &link, const std::shared_ptr< const tesseract_scene_graph::Joint > &joint, bool replace_allowed)
Definition: environment.cpp:1476
tesseract_environment::Environment::init
bool init(const std::vector< std::shared_ptr< const Command >> &commands)
Initialize the Environment.
Definition: environment.cpp:2156
tesseract_environment::Commands
std::vector< std::shared_ptr< const Command > > Commands
Definition: command.h:110
tesseract_environment::Environment::getActiveJointNames
std::vector< std::string > getActiveJointNames() const
Get a vector of active joint names in the environment.
Definition: environment.cpp:2577
tesseract_environment::Environment::Implementation::access
friend class boost::serialization::access
Definition: environment.cpp:415
tesseract_scene_graph::JointType::FIXED
@ FIXED
tesseract_environment::Environment::findTCPOffset
Eigen::Isometry3d findTCPOffset(const tesseract_common::ManipulatorInfo &manip_info) const
Find tool center point provided in the manipulator info.
Definition: environment.cpp:2398
tesseract_environment::Environment::setActiveContinuousContactManager
bool setActiveContinuousContactManager(const std::string &name)
Set the active continuous contact manager.
Definition: environment.cpp:2706
tesseract_environment::Environment::Implementation::setActiveContinuousContactManager
bool setActiveContinuousContactManager(const std::string &name)
Definition: environment.cpp:1130
tesseract_collision::CollisionMarginData
tesseract_common::CollisionMarginData CollisionMarginData
tesseract_environment::Environment::setName
void setName(const std::string &name)
Give the environment a name.
Definition: environment.cpp:2452
tesseract_environment::Environment::Implementation::applyChangeLinkCollisionEnabledCommand
bool applyChangeLinkCollisionEnabledCommand(const std::shared_ptr< const ChangeLinkCollisionEnabledCommand > &cmd)
Definition: environment.cpp:1754


tesseract_environment
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:21