environment.h
Go to the documentation of this file.
1 
26 #ifndef TESSERACT_ENVIRONMENT_ENVIRONMENT_H
27 #define TESSERACT_ENVIRONMENT_ENVIRONMENT_H
28 
31 #include <functional>
32 #include <vector>
33 #include <string>
34 #include <chrono>
35 #include <set>
36 #include <memory>
37 #include <shared_mutex>
38 #include <Eigen/Geometry>
40 
41 #include <tesseract_common/fwd.h>
42 #include <tesseract_geometry/fwd.h>
45 #include <tesseract_srdf/fwd.h>
49 
50 #include <filesystem>
54 
55 namespace boost::serialization
56 {
57 class access;
58 }
59 
60 namespace tesseract_environment
61 {
67 using FindTCPOffsetCallbackFn = std::function<Eigen::Isometry3d(const tesseract_common::ManipulatorInfo&)>;
68 
69 using EventCallbackFn = std::function<void(const Event& event)>;
70 
72 {
73 public:
74  // LCOV_EXCL_START
75  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
76  // LCOV_EXCL_STOP
77 
78  using Ptr = std::shared_ptr<Environment>;
79  using ConstPtr = std::shared_ptr<const Environment>;
80  using UPtr = std::unique_ptr<Environment>;
81  using ConstUPtr = std::unique_ptr<const Environment>;
82 
84  Environment();
85  virtual ~Environment();
86  Environment(const Environment&) = delete;
87  Environment& operator=(const Environment&) = delete;
88  Environment(Environment&&) = delete;
89  Environment& operator=(Environment&&) = delete;
90 
99  bool init(const std::vector<std::shared_ptr<const Command>>& commands);
100 
109  bool init(const tesseract_scene_graph::SceneGraph& scene_graph,
110  const std::shared_ptr<const tesseract_srdf::SRDFModel>& srdf_model = nullptr);
111 
112  bool init(const std::string& urdf_string, const std::shared_ptr<const tesseract_common::ResourceLocator>& locator);
113 
114  bool init(const std::string& urdf_string,
115  const std::string& srdf_string,
116  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator);
117 
118  bool init(const std::filesystem::path& urdf_path,
119  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator);
120 
121  bool init(const std::filesystem::path& urdf_path,
122  const std::filesystem::path& srdf_path,
123  const std::shared_ptr<const tesseract_common::ResourceLocator>& locator);
124 
129  Environment::UPtr clone() const;
130 
136  bool reset();
137 
139  void clear();
140 
142  bool isInitialized() const;
143 
148  int getRevision() const;
149 
154  int getInitRevision() const;
155 
160  std::vector<std::shared_ptr<const Command>> getCommandHistory() const;
161 
168  bool applyCommands(const std::vector<std::shared_ptr<const Command>>& commands);
169 
176  bool applyCommand(std::shared_ptr<const Command> command);
177 
182  std::shared_ptr<const tesseract_scene_graph::SceneGraph> getSceneGraph() const;
183 
189  std::vector<std::string> getGroupJointNames(const std::string& group_name) const;
190 
196  std::shared_ptr<const tesseract_kinematics::JointGroup> getJointGroup(const std::string& group_name) const;
197 
204  std::shared_ptr<const tesseract_kinematics::JointGroup>
205  getJointGroup(const std::string& name, const std::vector<std::string>& joint_names) const;
206 
214  std::shared_ptr<const tesseract_kinematics::KinematicGroup>
215  getKinematicGroup(const std::string& group_name, const std::string& ik_solver_name = "") const;
216 
230  Eigen::Isometry3d findTCPOffset(const tesseract_common::ManipulatorInfo& manip_info) const;
231 
237 
242  std::vector<FindTCPOffsetCallbackFn> getFindTCPOffsetCallbacks() const;
243 
253  void addEventCallback(std::size_t hash, const EventCallbackFn& fn);
254 
259  void removeEventCallback(std::size_t hash);
260 
262  void clearEventCallbacks();
263 
268  std::map<std::size_t, EventCallbackFn> getEventCallbacks() const;
269 
274  void setResourceLocator(std::shared_ptr<const tesseract_common::ResourceLocator> locator);
275 
281  std::shared_ptr<const tesseract_common::ResourceLocator> getResourceLocator() const;
282 
284  void setName(const std::string& name);
285 
290  const std::string& getName() const;
291 
299  void setState(const std::unordered_map<std::string, double>& joints,
300  const tesseract_common::TransformMap& floating_joints = {});
301  void setState(const std::vector<std::string>& joint_names,
302  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
303  const tesseract_common::TransformMap& floating_joints = {});
304 
309  void setState(const tesseract_common::TransformMap& floating_joints);
310 
319  tesseract_scene_graph::SceneState getState(const std::unordered_map<std::string, double>& joints,
320  const tesseract_common::TransformMap& floating_joints = {}) const;
321  tesseract_scene_graph::SceneState getState(const std::vector<std::string>& joint_names,
322  const Eigen::Ref<const Eigen::VectorXd>& joint_values,
323  const tesseract_common::TransformMap& floating_joints = {}) const;
324 
331 
334 
336  std::chrono::system_clock::time_point getTimestamp() const;
337 
339  std::chrono::system_clock::time_point getCurrentStateTimestamp() const;
340 
346  std::shared_ptr<const tesseract_scene_graph::Link> getLink(const std::string& name) const;
347 
353  std::shared_ptr<const tesseract_scene_graph::Joint> getJoint(const std::string& name) const;
354 
360  std::shared_ptr<const tesseract_scene_graph::JointLimits> getJointLimits(const std::string& joint_name) const;
361 
366  bool getLinkCollisionEnabled(const std::string& name) const;
367 
372  bool getLinkVisibility(const std::string& name) const;
373 
378  std::shared_ptr<const tesseract_common::AllowedCollisionMatrix> getAllowedCollisionMatrix() const;
379 
384  std::vector<std::string> getJointNames() const;
385 
390  std::vector<std::string> getActiveJointNames() const;
391 
399  Eigen::VectorXd getCurrentJointValues() const;
400 
408  Eigen::VectorXd getCurrentJointValues(const std::vector<std::string>& joint_names) const;
409 
415 
420  tesseract_common::TransformMap getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const;
421 
426  std::string getRootLinkName() const;
427 
432  std::vector<std::string> getLinkNames() const;
433 
438  std::vector<std::string> getActiveLinkNames() const;
439 
445  std::vector<std::string> getActiveLinkNames(const std::vector<std::string>& joint_names) const;
446 
451  std::vector<std::string> getStaticLinkNames() const;
452 
458  std::vector<std::string> getStaticLinkNames(const std::vector<std::string>& joint_names) const;
459 
468 
473  Eigen::Isometry3d getLinkTransform(const std::string& link_name) const;
474 
481  Eigen::Isometry3d getRelativeLinkTransform(const std::string& from_link_name, const std::string& to_link_name) const;
482 
491  std::unique_ptr<tesseract_scene_graph::StateSolver> getStateSolver() const;
492 
498 
503  std::set<std::string> getGroupNames() const;
504 
510 
516  bool setActiveDiscreteContactManager(const std::string& name);
517 
519  std::unique_ptr<tesseract_collision::DiscreteContactManager> getDiscreteContactManager() const;
520 
526 
528  std::unique_ptr<tesseract_collision::DiscreteContactManager> getDiscreteContactManager(const std::string& name) const;
529 
535  bool setActiveContinuousContactManager(const std::string& name);
536 
538  std::unique_ptr<tesseract_collision::ContinuousContactManager> getContinuousContactManager() const;
539 
545 
547  std::unique_ptr<tesseract_collision::ContinuousContactManager>
548  getContinuousContactManager(const std::string& name) const;
549 
552 
558  std::shared_lock<std::shared_mutex> lockRead() const;
559 
565  bool operator==(const Environment& rhs) const;
566  bool operator!=(const Environment& rhs) const;
567 
568 private:
570  mutable std::shared_mutex mutex_;
571 
574  std::unique_ptr<Implementation> impl_;
575 
578  template <class Archive>
579  void save(Archive& ar, const unsigned int version) const; // NOLINT
580 
581  template <class Archive>
582  void load(Archive& ar, const unsigned int version); // NOLINT
583 
584  template <class Archive>
585  void serialize(Archive& ar, const unsigned int version); // NOLINT
586 
587 public:
589  explicit Environment(std::unique_ptr<Implementation> impl);
590 };
591 
595 } // namespace tesseract_environment
596 BOOST_CLASS_EXPORT_KEY(tesseract_environment::Environment)
597 BOOST_CLASS_EXPORT_KEY(tesseract_environment::EnvironmentPtrAnyPoly)
599 #endif // TESSERACT_ENVIRONMENT_ENVIRONMENT_H
tesseract_common::VectorIsometry3d
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
tesseract_environment::Environment::getSceneGraph
std::shared_ptr< const tesseract_scene_graph::SceneGraph > getSceneGraph() const
Get the Scene Graph.
Definition: environment.cpp:2366
tesseract_environment::Environment::getResourceLocator
std::shared_ptr< const tesseract_common::ResourceLocator > getResourceLocator() const
Get the resource locator assigned.
Definition: environment.cpp:2446
tesseract_environment::Environment::operator!=
bool operator!=(const Environment &rhs) const
Definition: environment.cpp:2760
any_poly.h
tesseract_environment
Definition: command.h:45
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::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: environment.cpp:2783
contact_allowed_validator.h
tesseract_environment::Environment::clearEventCallbacks
void clearEventCallbacks()
clear all event callbacks
Definition: environment.cpp:2428
tesseract_environment::Environment::getCollisionMarginData
tesseract_common::CollisionMarginData getCollisionMarginData() const
Get the environment collision margin data.
Definition: environment.cpp:2743
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
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::Ptr
std::shared_ptr< Environment > Ptr
Definition: environment.h:78
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::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_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::mutex_
std::shared_mutex mutex_
The environment can be accessed from multiple threads, need use mutex throughout.
Definition: environment.h:570
tesseract_common::TransformMap
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
tesseract_common::ManipulatorInfo
tesseract_environment::Environment::ConstUPtr
std::unique_ptr< const Environment > ConstUPtr
Definition: environment.h:81
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::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
tesseract_environment::Environment::access
friend class boost::serialization::access
Definition: environment.h:576
fwd.h
Tesseract Environment Forward Declarations.
tesseract_environment::Environment::Implementation
Definition: environment.cpp:164
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_common::AnyWrapper
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_scene_graph::SceneGraph
tesseract_common::Serialization
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::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::getState
tesseract_scene_graph::SceneState getState() const
Get the current state of the environment.
Definition: environment.cpp:2521
tesseract_environment::Environment::getCurrentJointValues
Eigen::VectorXd getCurrentJointValues() const
Get the current state of the environment.
Definition: environment.cpp:2589
tesseract_scene_graph::SceneState
tesseract_environment::Environment::clone
Environment::UPtr clone() const
Clone the environment.
Definition: environment.cpp:2762
tesseract_environment::Environment::getGroupNames
std::set< std::string > getGroupNames() const
Get the available group names.
Definition: environment.cpp:2681
tesseract_environment::Environment::impl_
std::unique_ptr< Implementation > impl_
Definition: environment.h:573
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::getRootLinkName
std::string getRootLinkName() const
Get the root link name.
Definition: environment.cpp:2614
tesseract_environment::Environment::~Environment
virtual ~Environment()
tesseract_environment::Environment::ConstPtr
std::shared_ptr< const Environment > ConstPtr
Definition: environment.h:79
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::ContactManagersPluginInfo
tesseract_environment::Environment::UPtr
std::unique_ptr< Environment > UPtr
Definition: environment.h:80
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::addFindTCPOffsetCallback
void addFindTCPOffsetCallback(const FindTCPOffsetCallbackFn &fn)
This allows for user defined callbacks for looking up TCP information.
Definition: environment.cpp:2404
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_srdf::KinematicsInformation
boost::serialization
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::getLinkNames
std::vector< std::string > getLinkNames() const
Get a vector of link names in the environment.
Definition: environment.cpp:2620
TESSERACT_COMMON_IGNORE_WARNINGS_POP
fwd.h
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::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::Environment::getGroupJointNames
std::vector< std::string > getGroupJointNames(const std::string &group_name) const
Get a groups joint names.
Definition: environment.cpp:2371
eigen_types.h
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_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::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::Event
The event base class.
Definition: events.h:48
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_environment::Environment::getInitRevision
int getInitRevision() const
Get the initialization revision number.
Definition: environment.cpp:2339
tesseract_environment::Environment::operator=
Environment & operator=(const Environment &)=delete
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::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_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
macros.h
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_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_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::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_environment::Environment::init
bool init(const std::vector< std::shared_ptr< const Command >> &commands)
Initialize the Environment.
Definition: environment.cpp:2156
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::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::setName
void setName(const std::string &name)
Give the environment a name.
Definition: environment.cpp:2452


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