26#ifndef TESSERACT_ENVIRONMENT_ENVIRONMENT_H
27#define TESSERACT_ENVIRONMENT_ENVIRONMENT_H
32#include <shared_mutex>
34#include <console_bridge/console.h>
68 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
71 using Ptr = std::shared_ptr<Environment>;
72 using ConstPtr = std::shared_ptr<const Environment>;
73 using UPtr = std::unique_ptr<Environment>;
74 using ConstUPtr = std::unique_ptr<const Environment>;
114 const tesseract_common::fs::path&
srdf_path,
191 const std::vector<std::string>&
joint_names)
const;
201 std::string ik_solver_name =
"")
const;
276 const std::string&
getName()
const;
285 void setState(
const std::unordered_map<std::string, double>&
joints);
286 void setState(
const std::vector<std::string>&
joint_names,
const Eigen::Ref<const Eigen::VectorXd>& joint_values);
298 const Eigen::Ref<const Eigen::VectorXd>& joint_values)
const;
304 std::chrono::system_clock::time_point
getTimestamp()
const;
437 Eigen::Isometry3d
getRelativeLinkTransform(
const std::string& from_link_name,
const std::string& to_link_name)
const;
513 std::shared_lock<std::shared_mutex>
lockRead()
const;
570 std::chrono::system_clock::time_point
timestamp_{ std::chrono::system_clock::now() };
647 mutable std::unordered_map<std::string, tesseract_kinematics::JointGroup::UPtr>
joint_group_cache_{};
725 template <
class Archive>
726 void save(Archive& ar,
const unsigned int version)
const;
728 template <
class Archive>
729 void load(Archive& ar,
const unsigned int version);
731 template <
class Archive>
732 void serialize(Archive& ar,
const unsigned int version);
std::shared_ptr< const AllowedCollisionMatrix > ConstPtr
Definition: allowed_collision_matrix.h:30
Stores information about how the margins allowed between collision objects.
Definition: collision_margin_data.h:74
std::shared_ptr< const ResourceLocator > ConstPtr
Definition: resource_locator.h:46
std::shared_ptr< const AddLinkCommand > ConstPtr
Definition: add_link_command.h:45
std::shared_ptr< const AddSceneGraphCommand > ConstPtr
Definition: add_scene_graph_command.h:44
std::shared_ptr< const ChangeCollisionMarginsCommand > ConstPtr
Definition: change_collision_margins_command.h:49
std::shared_ptr< const ChangeJointAccelerationLimitsCommand > ConstPtr
Definition: change_joint_acceleration_limits_command.h:46
std::shared_ptr< const ChangeJointOriginCommand > ConstPtr
Definition: change_joint_origin_command.h:48
std::shared_ptr< const ChangeJointPositionLimitsCommand > ConstPtr
Definition: change_joint_position_limits_command.h:46
std::shared_ptr< const ChangeJointVelocityLimitsCommand > ConstPtr
Definition: change_joint_velocity_limits_command.h:46
std::shared_ptr< const ChangeLinkCollisionEnabledCommand > ConstPtr
Definition: change_link_collision_enabled_command.h:43
std::shared_ptr< const ChangeLinkOriginCommand > ConstPtr
Definition: change_link_origin_command.h:48
std::shared_ptr< const ChangeLinkVisibilityCommand > ConstPtr
Definition: change_link_visibility_command.h:43
std::shared_ptr< const Command > ConstPtr
Definition: command.h:79
Definition: environment.h:65
tesseract_common::ContactManagersPluginInfo getContactManagersPluginInfo() const
Get the contact managers plugin information.
Definition: environment.cpp:763
bool operator==(const Environment &rhs) const
These operators are to facilitate checking serialization but may have value elsewhere.
Definition: environment.cpp:881
void serialize(Archive &ar, const unsigned int version)
Definition: environment.cpp:2089
int revision_
This increments when the scene graph is modified.
Definition: environment.h:534
std::shared_mutex joint_group_cache_mutex_
Definition: environment.h:648
std::unordered_map< std::string, tesseract_kinematics::JointGroup::UPtr > joint_group_cache_
A cache of joint groups to provide faster access.
Definition: environment.h:647
tesseract_scene_graph::SceneState getState() const
Get the current state of the environment.
Definition: environment.cpp:586
tesseract_collision::ContactManagersPluginFactory contact_managers_factory_
The contact managers factory.
Definition: environment.h:612
std::vector< std::string > getActiveJointNames() const
Get a vector of active joint names in the environment.
Definition: environment.cpp:641
bool getLinkVisibility(const std::string &name) const
Get a given links visibility setting.
Definition: environment.cpp:623
std::vector< std::string > getStaticLinkNames() const
Get a vector of static link names in the environment.
Definition: environment.cpp:700
Eigen::VectorXd getCurrentJointValues() const
Get the current state of the environment.
Definition: environment.cpp:653
bool applyCommandsHelper(const Commands &commands)
Apply Command Helper which does not lock.
Definition: environment.cpp:1219
Environment()=default
Default constructor.
bool applyCommand(Command::ConstPtr command)
Apply command to the environment.
Definition: environment.cpp:329
std::unique_ptr< Environment > UPtr
Definition: environment.h:73
Environment & operator=(Environment &&)=delete
void currentStateChanged()
Definition: environment.cpp:1041
bool applyRemoveJointCommand(const RemoveJointCommand::ConstPtr &cmd)
Definition: environment.cpp:1591
tesseract_scene_graph::SceneState current_state_
Current state of the environment.
Definition: environment.h:567
bool applyMoveLinkCommand(const MoveLinkCommand::ConstPtr &cmd)
Definition: environment.cpp:1549
bool applyRemoveLinkCommand(const RemoveLinkCommand::ConstPtr &cmd)
Definition: environment.cpp:1577
bool applyAddCommand(AddLinkCommand::ConstPtr cmd)
Definition: environment.cpp:1385
std::shared_lock< std::shared_mutex > lockRead() const
Lock the environment when wanting to make multiple reads.
Definition: environment.cpp:876
bool applyChangeJointOriginCommand(const ChangeJointOriginCommand::ConstPtr &cmd)
Definition: environment.cpp:1655
std::vector< FindTCPOffsetCallbackFn > getFindTCPOffsetCallbacks() const
This get the current find tcp callbacks stored in the environment.
Definition: environment.cpp:494
tesseract_scene_graph::JointLimits::ConstPtr getJointLimits(const std::string &joint_name) const
Gets the limits associated with a joint.
Definition: environment.cpp:611
virtual ~Environment()=default
bool applyChangeJointPositionLimitsCommand(const ChangeJointPositionLimitsCommand::ConstPtr &cmd)
Definition: environment.cpp:1830
std::vector< std::string > getJointNames() const
Get a vector of joint names in the environment.
Definition: environment.cpp:635
bool applyMoveJointCommand(const MoveJointCommand::ConstPtr &cmd)
Definition: environment.cpp:1563
bool applyAddSceneGraphCommand(AddSceneGraphCommand::ConstPtr cmd)
Definition: environment.cpp:1755
bool applyRemoveAllowedCollisionLinkCommand(const RemoveAllowedCollisionLinkCommand::ConstPtr &cmd)
Definition: environment.cpp:1745
bool setActiveDiscreteContactManagerHelper(const std::string &name)
Definition: environment.cpp:913
void clearCachedDiscreteContactManager() const
Set the cached internal copy of the environments active discrete contact manager not nullptr.
Definition: environment.cpp:819
bool removeLinkHelper(const std::string &name)
Definition: environment.cpp:1117
tesseract_kinematics::KinematicsPluginFactory kinematics_factory_
The kinematics factory.
Definition: environment.h:564
void addFindTCPOffsetCallback(const FindTCPOffsetCallbackFn &fn)
This allows for user defined callbacks for looking up TCP information.
Definition: environment.cpp:488
std::vector< std::string > getActiveLinkNames() const
Get a vector of active link names in the environment.
Definition: environment.cpp:688
bool setActiveContinuousContactManager(const std::string &name)
Set the active continuous contact manager.
Definition: environment.cpp:789
void removeEventCallback(std::size_t hash)
Remove event callbacks.
Definition: environment.cpp:506
static Commands getInitCommands(const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_srdf::SRDFModel::ConstPtr &srdf_model=nullptr)
Definition: environment.cpp:256
tesseract_scene_graph::Link::ConstPtr getLink(const std::string &name) const
Get a link in the environment.
Definition: environment.cpp:604
Commands getCommandHistory() const
Get Environment command history post initialization.
Definition: environment.cpp:309
Environment(const Environment &)=delete
bool operator!=(const Environment &rhs) const
Definition: environment.cpp:911
tesseract_collision::ContinuousContactManager::UPtr continuous_manager_
The continuous contact manager object.
Definition: environment.h:631
std::vector< std::string > getGroupJointNames(const std::string &group_name) const
Get a groups joint names.
Definition: environment.cpp:333
std::chrono::system_clock::time_point getTimestamp() const
Last update time. Updated when any change to the environment occurs.
Definition: environment.cpp:592
bool applyChangeCollisionMarginsCommand(const ChangeCollisionMarginsCommand::ConstPtr &cmd)
Definition: environment.cpp:2032
std::map< std::size_t, EventCallbackFn > event_cb_
A map of user defined event callback functions.
Definition: environment.h:597
std::shared_mutex mutex_
The environment can be accessed from multiple threads, need use mutex throughout.
Definition: environment.h:660
tesseract_collision::CollisionMarginData collision_margin_data_
The collision margin data.
Definition: environment.h:618
int getRevision() const
Get the current revision number.
Definition: environment.cpp:303
tesseract_collision::DiscreteContactManager::UPtr getDiscreteContactManager() const
Get a copy of the environments active discrete contact manager.
Definition: environment.cpp:796
bool init(const Commands &commands)
Initialize the Environment.
Definition: environment.cpp:80
std::string getRootLinkName() const
Get the root link name.
Definition: environment.cpp:676
tesseract_srdf::GroupNames getGroupNames() const
Get the available group names.
Definition: environment.cpp:757
tesseract_collision::IsContactAllowedFn is_contact_allowed_fn_
The function used to determine if two objects are allowed in collision.
Definition: environment.h:585
std::vector< std::string > getLinkNames() const
Get a vector of link names in the environment.
Definition: environment.cpp:682
tesseract_scene_graph::StateSolver::UPtr getStateSolver() const
Returns a clone of the environments state solver.
Definition: environment.cpp:745
tesseract_scene_graph::SceneGraph::Ptr scene_graph_
Tesseract Scene Graph.
Definition: environment.h:546
static void getCollisionObject(tesseract_collision::CollisionShapesConst &shapes, tesseract_common::VectorIsometry3d &shape_poses, const tesseract_scene_graph::Link &link)
Definition: environment.cpp:1030
tesseract_srdf::KinematicsInformation getKinematicsInformation() const
Get the kinematics information.
Definition: environment.cpp:751
bool initHelper(const Commands &commands)
Definition: environment.cpp:44
std::shared_ptr< Environment > Ptr
Definition: environment.h:71
void setName(const std::string &name)
Give the environment a name.
Definition: environment.cpp:536
tesseract_scene_graph::SceneGraph::ConstPtr scene_graph_const_
Tesseract Scene Graph Const.
Definition: environment.h:552
bool applyChangeLinkOriginCommand(const ChangeLinkOriginCommand::ConstPtr &cmd)
Definition: environment.cpp:1650
tesseract_scene_graph::SceneGraph::ConstPtr getSceneGraph() const
Get the Scene Graph.
Definition: environment.cpp:331
tesseract_common::ResourceLocator::ConstPtr resource_locator_
Used when initialized by URDF_STRING, URDF_STRING_SRDF_STRING, URDF_PATH, and URDF_PATH_SRDF_PATH.
Definition: environment.h:600
std::shared_mutex kinematic_group_cache_mutex_
Definition: environment.h:657
void triggerEnvironmentChangedCallbacks()
Passes a environment changed event to the callbacks.
Definition: environment.cpp:1107
tesseract_common::ResourceLocator::ConstPtr getResourceLocator() const
Get the resource locator assigned.
Definition: environment.cpp:530
Eigen::Isometry3d findTCPOffset(const tesseract_common::ManipulatorInfo &manip_info) const
Find tool center point provided in the manipulator info.
Definition: environment.cpp:453
Commands commands_
The history of commands applied to the environment after initialization.
Definition: environment.h:540
void load(Archive &ar, const unsigned int version)
Definition: environment.cpp:2067
bool applySetActiveContinuousContactManagerCommand(const SetActiveContinuousContactManagerCommand::ConstPtr &cmd)
Definition: environment.cpp:2010
tesseract_kinematics::JointGroup::UPtr getJointGroup(const std::string &group_name) const
Get a joint group by name.
Definition: environment.cpp:378
bool applyChangeLinkVisibilityCommand(const ChangeLinkVisibilityCommand::ConstPtr &cmd)
Definition: environment.cpp:1700
void clearCachedContinuousContactManager() const
Set the cached internal copy of the environments active continuous contact manager not nullptr.
Definition: environment.cpp:849
bool reset()
reset to initialized state
Definition: environment.cpp:218
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:738
bool applyCommands(const Commands &commands)
Applies the commands to the environment.
Definition: environment.cpp:315
std::shared_ptr< const Environment > ConstPtr
Definition: environment.h:72
bool applyChangeJointVelocityLimitsCommand(const ChangeJointVelocityLimitsCommand::ConstPtr &cmd)
Definition: environment.cpp:1859
Environment::UPtr clone() const
Clone the environment.
Definition: environment.cpp:1150
bool applyReplaceJointCommand(const ReplaceJointCommand::ConstPtr &cmd)
Definition: environment.cpp:1613
std::unique_ptr< const Environment > ConstUPtr
Definition: environment.h:74
std::chrono::system_clock::time_point timestamp_
Environment timestamp.
Definition: environment.h:570
bool applySetActiveDiscreteContactManagerCommand(const SetActiveDiscreteContactManagerCommand::ConstPtr &cmd)
Definition: environment.cpp:2021
std::map< std::size_t, EventCallbackFn > getEventCallbacks() const
Get the current event callbacks stored in the environment.
Definition: environment.cpp:518
tesseract_collision::DiscreteContactManager::UPtr discrete_manager_
The discrete contact manager object.
Definition: environment.h:624
tesseract_common::ContactManagersPluginInfo contact_managers_plugin_info_
The contact manager information.
Definition: environment.h:606
bool getLinkCollisionEnabled(const std::string &name) const
Get whether a link should be considered during collision checking.
Definition: environment.cpp:617
std::shared_mutex continuous_manager_mutex_
Definition: environment.h:632
std::map< std::pair< std::string, std::string >, tesseract_kinematics::KinematicGroup::UPtr > kinematic_group_cache_
A cache of kinematic groups to provide faster access.
Definition: environment.h:656
void save(Archive &ar, const unsigned int version) const
Definition: environment.cpp:2051
Eigen::Isometry3d getLinkTransform(const std::string &link_name) const
Get the transform corresponding to the link.
Definition: environment.cpp:732
bool applyAddContactManagersPluginInfoCommand(const AddContactManagersPluginInfoCommand::ConstPtr &cmd)
Definition: environment.cpp:1953
bool setActiveContinuousContactManagerHelper(const std::string &name)
Definition: environment.cpp:935
void addEventCallback(std::size_t hash, const EventCallbackFn &fn)
Add an event callback function.
Definition: environment.cpp:500
bool applyChangeJointAccelerationLimitsCommand(const ChangeJointAccelerationLimitsCommand::ConstPtr &cmd)
Definition: environment.cpp:1887
void setResourceLocator(tesseract_common::ResourceLocator::ConstPtr locator)
Set resource locator for environment.
Definition: environment.cpp:524
Environment & operator=(const Environment &)=delete
friend class boost::serialization::access
Definition: environment.h:724
std::chrono::system_clock::time_point getCurrentStateTimestamp() const
Last update time to current state. Updated only when current state is updated.
Definition: environment.cpp:598
tesseract_scene_graph::MutableStateSolver::UPtr state_solver_
Tesseract State Solver.
Definition: environment.h:579
void triggerCurrentStateChangedCallbacks()
Passes a current state changed event to the callbacks.
Definition: environment.cpp:1097
tesseract_common::AllowedCollisionMatrix::ConstPtr getAllowedCollisionMatrix() const
Get the allowed collision matrix.
Definition: environment.cpp:629
void setState(const std::unordered_map< std::string, double > &joints)
Set the current state of the environment.
Definition: environment.cpp:548
tesseract_common::CollisionMarginData getCollisionMarginData() const
Get the environment collision margin data.
Definition: environment.cpp:870
tesseract_scene_graph::Joint::ConstPtr getJoint(const std::string &name) const
Get joint by name.
Definition: environment.cpp:647
tesseract_common::VectorIsometry3d getLinkTransforms() const
Get all of the links transforms.
Definition: environment.cpp:726
bool applyChangeLinkCollisionEnabledCommand(const ChangeLinkCollisionEnabledCommand::ConstPtr &cmd)
Definition: environment.cpp:1669
std::chrono::system_clock::time_point current_state_timestamp_
Current state timestamp.
Definition: environment.h:573
int init_revision_
This is the revision number after initialization used when reset is called.
Definition: environment.h:537
bool initialized_
Identifies if the object has been initialized.
Definition: environment.h:528
const std::string & getName() const
Get the name of the environment.
Definition: environment.cpp:542
Environment(Environment &&)=delete
tesseract_collision::ContinuousContactManager::UPtr getContinuousContactManagerHelper(const std::string &name) const
Definition: environment.cpp:991
void clearEventCallbacks()
clear all event callbacks
Definition: environment.cpp:512
tesseract_kinematics::KinematicGroup::UPtr getKinematicGroup(const std::string &group_name, std::string ik_solver_name="") const
Get a kinematic group given group name and solver name.
Definition: environment.cpp:406
bool applyAddKinematicsInformationCommand(const AddKinematicsInformationCommand::ConstPtr &cmd)
Definition: environment.cpp:1915
tesseract_collision::DiscreteContactManager::UPtr getDiscreteContactManagerHelper(const std::string &name) const
Definition: environment.cpp:959
bool applyModifyAllowedCollisionsCommand(const ModifyAllowedCollisionsCommand::ConstPtr &cmd)
Definition: environment.cpp:1712
bool isInitialized() const
check if the environment is initialized
Definition: environment.cpp:297
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.h:639
std::vector< FindTCPOffsetCallbackFn > find_tcp_cb_
A vector of user defined callbacks for locating tool center point.
Definition: environment.h:591
bool setActiveDiscreteContactManager(const std::string &name)
Set the active discrete contact manager.
Definition: environment.cpp:769
std::shared_mutex group_joint_names_cache_mutex_
Definition: environment.h:640
void clear()
clear content and uninitialized
Definition: environment.cpp:243
tesseract_collision::ContinuousContactManager::UPtr getContinuousContactManager() const
Get a copy of the environments active continuous contact manager.
Definition: environment.cpp:826
tesseract_srdf::KinematicsInformation kinematics_information_
The kinematics information.
Definition: environment.h:558
void environmentChanged()
Definition: environment.cpp:1072
std::shared_mutex discrete_manager_mutex_
Definition: environment.h:625
std::shared_ptr< const ModifyAllowedCollisionsCommand > ConstPtr
Definition: modify_allowed_collisions_command.h:52
std::shared_ptr< const MoveJointCommand > ConstPtr
Definition: move_joint_command.h:43
std::shared_ptr< const MoveLinkCommand > ConstPtr
Definition: move_link_command.h:44
std::shared_ptr< const RemoveAllowedCollisionLinkCommand > ConstPtr
Definition: remove_allowed_collision_link_command.h:43
std::shared_ptr< const RemoveJointCommand > ConstPtr
Definition: remove_joint_command.h:43
std::shared_ptr< const RemoveLinkCommand > ConstPtr
Definition: remove_link_command.h:43
std::shared_ptr< const ReplaceJointCommand > ConstPtr
Definition: replace_joint_command.h:43
std::unique_ptr< JointGroup > UPtr
Definition: joint_group.h:51
std::unique_ptr< KinematicGroup > UPtr
Definition: kinematic_group.h:86
Definition: kinematics_plugin_factory.h:114
std::shared_ptr< const JointLimits > ConstPtr
Definition: joint.h:82
std::shared_ptr< const Joint > ConstPtr
Definition: joint.h:286
std::shared_ptr< const Link > ConstPtr
Definition: link.h:191
std::unique_ptr< MutableStateSolver > UPtr
Definition: mutable_state_solver.h:41
std::shared_ptr< SceneGraph > Ptr
Definition: graph.h:130
std::shared_ptr< const SceneGraph > ConstPtr
Definition: graph.h:131
std::unique_ptr< StateSolver > UPtr
Definition: state_solver.h:50
std::shared_ptr< const SRDFModel > ConstPtr
Definition: srdf_model.h:60
This contains classes for recording operations applied to the environment for tracking changes....
A basic scene graph using boost.
auto scene_graph
Definition: ikfast_kinematics_7dof_unit.cpp:51
A joint group with forward kinematics, Jacobian, limits methods.
A kinematic group with forward and inverse kinematics methods.
Kinematics Plugin Factory.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Tesseract Scene Graph Mutable State Solver Interface .
Definition: create_convex_hull.cpp:36
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
std::function< bool(const std::string &, const std::string &)> IsContactAllowedFn
Should return true if contact allowed, otherwise false.
Definition: types.h:59
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
Definition: types.h:62
std::function< Eigen::Isometry3d(const tesseract_common::ManipulatorInfo &)> FindTCPOffsetCallbackFn
Function signature for adding additional callbacks for looking up TCP information.
Definition: environment.h:62
std::function< void(const Event &event)> EventCallbackFn
Definition: events.h:77
std::vector< Command::ConstPtr > Commands
Definition: command.h:101
std::set< std::string > GroupNames
Definition: kinematics_information.h:56
Locate and retrieve resource data.
ResourceLocator::Ptr locator
Definition: resource_locator_unit.cpp:57
This holds a state of the scene.
Contains information about a robot manipulator.
Definition: manipulator_info.h:43
This holds a state of the scene.
Definition: scene_state.h:54
Common Tesseract Utility Functions.
joint_state joint_names
Definition: tesseract_common_serialization_unit.cpp:75
manip_info
Definition: tesseract_common_unit.cpp:269
std::string srdf_string
Definition: tesseract_environment_unit.cpp:447
std::string urdf_string
Definition: tesseract_environment_unit.cpp:432
auto cmd
Definition: tesseract_environment_unit.cpp:424
tesseract_common::fs::path urdf_path("/usr/tmp/doesnotexist.urdf")
tesseract_common::fs::path srdf_path(std::string(TESSERACT_SUPPORT_DIR)+"/urdf/lbr_iiwa_14_r820.srdf")
joint_1 mimic joint_name
Definition: tesseract_scene_graph_joint_unit.cpp:163
m name
Definition: tesseract_scene_graph_link_unit.cpp:77
object joints["j_1"]
Definition: tesseract_scene_graph_serialization_unit.cpp:224
tesseract_srdf::SRDFModel srdf_model
Definition: tesseract_srdf_unit.cpp:852
A urdf parser for tesseract.