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>
73 #include <console_bridge/console.h>
88 bool operator()(
const std::string& link_name1,
const std::string& link_name2)
const override
90 return scene_graph_->isCollisionAllowed(link_name1, link_name2);
94 std::shared_ptr<const tesseract_scene_graph::SceneGraph>
scene_graph_;
99 template <
class Archive>
102 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(ContactAllowedValidator);
113 shapes.push_back(c->geometry);
114 shape_poses.push_back(c->origin);
118 std::vector<std::shared_ptr<const Command>>
120 const std::shared_ptr<const tesseract_srdf::SRDFModel>& srdf_model =
nullptr)
125 if (local_sg ==
nullptr)
127 CONSOLE_BRIDGE_logError(
"Null pointer to Scene Graph");
131 if (!local_sg->getLink(local_sg->getRoot()))
133 CONSOLE_BRIDGE_logError(
"The scene graph has an invalid root.");
137 if (srdf_model !=
nullptr)
140 commands.push_back(std::make_shared<AddSceneGraphCommand>(*local_sg));
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));
148 for (
const auto& cal : srdf_model->calibration_info.joints)
149 commands.push_back(std::make_shared<ChangeJointOriginCommand>(cal.first, cal.second));
152 if (srdf_model->collision_margin_data)
154 commands.push_back(std::make_shared<ChangeCollisionMarginsCommand>(
155 srdf_model->collision_margin_data->getDefaultCollisionMargin(),
156 srdf_model->collision_margin_data->getCollisionMarginPairData(),
184 std::vector<std::shared_ptr<const Command>>
commands{};
190 std::shared_ptr<tesseract_scene_graph::SceneGraph>
scene_graph{
nullptr };
196 std::chrono::system_clock::time_point
timestamp{ std::chrono::system_clock::now() };
205 std::unique_ptr<tesseract_scene_graph::MutableStateSolver>
state_solver{
nullptr };
261 mutable std::unique_ptr<tesseract_collision::DiscreteContactManager>
discrete_manager{
nullptr };
268 mutable std::unique_ptr<tesseract_collision::ContinuousContactManager>
continuous_manager{
nullptr };
284 mutable std::unordered_map<std::string, std::shared_ptr<const tesseract_kinematics::JointGroup>>
joint_group_cache{};
292 mutable std::map<std::pair<std::string, std::string>, std::shared_ptr<const tesseract_kinematics::KinematicGroup>>
300 void setState(
const std::unordered_map<std::string, double>& joints,
303 void setState(
const std::vector<std::string>& joint_names,
304 const Eigen::Ref<const Eigen::VectorXd>& joint_values,
317 std::vector<std::string>
getStaticLinkNames(
const std::vector<std::string>& joint_names)
const;
340 std::shared_ptr<const tesseract_kinematics::JointGroup>
getJointGroup(
const std::string& group_name)
const;
342 std::shared_ptr<const tesseract_kinematics::JointGroup>
343 getJointGroup(
const std::string& name,
const std::vector<std::string>& joint_names)
const;
345 std::shared_ptr<const tesseract_kinematics::KinematicGroup>
getKinematicGroup(
const std::string& group_name,
346 std::string ik_solver_name)
const;
362 std::unique_ptr<tesseract_collision::DiscreteContactManager>
365 std::unique_ptr<tesseract_collision::ContinuousContactManager>
374 std::unique_ptr<tesseract_collision::ContinuousContactManager>
383 bool applyAddCommand(
const std::shared_ptr<const AddLinkCommand>& cmd);
404 const std::shared_ptr<const SetActiveContinuousContactManagerCommand>& cmd);
410 const std::shared_ptr<const tesseract_scene_graph::Joint>& joint,
411 bool replace_allowed);
413 std::unique_ptr<Implementation>
clone()
const;
417 template <
class Archive>
418 void save(Archive& ar,
const unsigned int )
const
421 ar& BOOST_SERIALIZATION_NVP(
commands);
426 ar& boost::serialization::make_nvp(
"timestamp",
428 ar& boost::serialization::make_nvp(
429 "current_state_timestamp",
433 template <
class Archive>
434 void load(Archive& ar,
const unsigned int )
439 ar& boost::serialization::make_nvp(
"commands",
commands);
445 ar& boost::serialization::make_nvp(
"current_state",
current_state);
451 ar& boost::serialization::make_nvp(
"timestamp",
453 ar& boost::serialization::make_nvp(
454 "current_state_timestamp",
458 template <
class Archive>
461 boost::serialization::split_member(ar, *
this, version);
476 for (std::size_t i = 0; i <
commands.size(); ++i)
498 auto cloned_env = std::make_unique<Implementation>();
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);
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;
519 auto cloned_solver = state_solver->clone();
522 (void)cloned_solver.release();
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;
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;
536 cloned_env->contact_allowed_validator = std::make_shared<EnvironmentContactAllowedValidator>(cloned_env->scene_graph);
538 if (discrete_manager)
540 cloned_env->discrete_manager = discrete_manager->clone();
541 cloned_env->discrete_manager->setContactAllowedValidator(cloned_env->contact_allowed_validator);
543 if (continuous_manager)
545 cloned_env->continuous_manager = continuous_manager->clone();
546 cloned_env->continuous_manager->setContactAllowedValidator(cloned_env->contact_allowed_validator);
549 cloned_env->contact_managers_plugin_info = contact_managers_plugin_info;
550 cloned_env->contact_managers_factory = contact_managers_factory;
557 if (commands.empty())
562 CONSOLE_BRIDGE_logError(
"When initializing environment from command history the first command must be type "
569 scene_graph = std::make_shared<tesseract_scene_graph::SceneGraph>(
570 std::static_pointer_cast<const AddSceneGraphCommand>(commands.at(0))->getSceneGraph()->getName());
572 contact_allowed_validator = std::make_shared<EnvironmentContactAllowedValidator>(scene_graph);
574 if (!applyCommandsHelper(commands))
576 CONSOLE_BRIDGE_logError(
"When initializing environment from command history, it failed to apply a command!");
581 init_revision = revision;
583 environmentChanged();
591 state_solver->setState(joints, floating_joints);
592 currentStateChanged();
596 const Eigen::Ref<const Eigen::VectorXd>& joint_values,
599 state_solver->setState(joint_names, joint_values, floating_joints);
600 currentStateChanged();
605 state_solver->setState(floating_joints);
606 currentStateChanged();
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]);
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]);
639 for (
const auto& joint_name : joint_names)
645 std::vector<std::string>
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());
653 std::sort(active_link_names.begin(), active_link_names.end());
654 std::sort(full_link_names.begin(), full_link_names.end());
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()));
662 return static_link_names;
670 scene_graph =
nullptr;
671 state_solver =
nullptr;
674 contact_allowed_validator =
nullptr;
676 kinematics_information.
clear();
677 contact_managers_plugin_info.
clear();
680 std::unique_lock<std::shared_mutex> lock(discrete_manager_mutex);
681 discrete_manager =
nullptr;
685 std::unique_lock<std::shared_mutex> lock(continuous_manager_mutex);
686 continuous_manager =
nullptr;
690 std::unique_lock<std::shared_mutex> lock(group_joint_names_cache_mutex);
691 group_joint_names_cache.clear();
695 std::unique_lock<std::shared_mutex> lock(joint_group_cache_mutex);
696 joint_group_cache.clear();
700 std::unique_lock<std::shared_mutex> lock(kinematic_group_cache_mutex);
701 kinematic_group_cache.clear();
712 if (commands.empty() || !initialized)
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]);
719 return initHelper(init_command);
724 timestamp = std::chrono::system_clock::now();
725 current_state_timestamp = timestamp;
726 current_state = state_solver->getState();
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);
732 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
733 if (continuous_manager !=
nullptr)
735 std::vector<std::string> active_link_names = state_solver->getActiveLinkNames();
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);
741 continuous_manager->setCollisionObjectsTransform(tf.first, tf.second);
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();
755 timestamp = std::chrono::system_clock::now();
756 std::vector<std::string> active_link_names = state_solver->getActiveLinkNames();
759 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
760 if (discrete_manager !=
nullptr)
761 discrete_manager->setActiveCollisionObjects(active_link_names);
765 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
766 if (continuous_manager !=
nullptr)
767 continuous_manager->setActiveCollisionObjects(active_link_names);
771 std::unique_lock<std::shared_mutex> jn_lock(group_joint_names_cache_mutex);
772 group_joint_names_cache.clear();
775 currentStateChanged();
780 if (!event_cb.empty())
783 for (
const auto& cb : event_cb)
790 if (!event_cb.empty())
793 for (
const auto& cb : event_cb)
800 triggerEnvironmentChangedCallbacks();
801 triggerCurrentStateChangedCallbacks();
806 auto it = std::find(kinematics_information.
group_names.begin(), kinematics_information.
group_names.end(), group_name);
808 if (it == kinematics_information.
group_names.end())
809 throw std::runtime_error(
"Environment, Joint group '" + group_name +
"' does not exist!");
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;
816 auto chain_it = kinematics_information.
chain_groups.find(group_name);
817 if (chain_it != kinematics_information.
chain_groups.end())
819 if (chain_it->second.size() > 1)
820 throw std::runtime_error(
"Environment, Groups with multiple chains is not supported!");
823 scene_graph->getShortestPath(chain_it->second.begin()->first, chain_it->second.begin()->second);
829 auto joint_it = kinematics_information.
joint_groups.find(group_name);
830 if (joint_it != kinematics_information.
joint_groups.end())
832 group_joint_names_cache[group_name] = joint_it->second;
833 return joint_it->second;
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!");
840 throw std::runtime_error(
"Environment, failed to get group '" + group_name +
"' joint names!");
843 std::shared_ptr<const tesseract_kinematics::JointGroup>
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())
854 joint_group_cache[group_name] = jg;
859 std::shared_ptr<const tesseract_kinematics::JointGroup>
862 return std::make_shared<tesseract_kinematics::JointGroup>(
name, joint_names, *scene_graph, current_state);
865 std::shared_ptr<const tesseract_kinematics::KinematicGroup>
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())
876 if (ik_solver_name.empty())
880 kinematics_factory.
createInvKin(group_name, ik_solver_name, *scene_graph, current_state);
883 if (inv_kin ==
nullptr)
887 auto kg = std::make_shared<tesseract_kinematics::KinematicGroup>(
888 group_name, joint_names, std::move(inv_kin), *scene_graph, current_state);
890 kinematic_group_cache[key] = kg;
892 #if !defined(NDEBUG) && TESSERACT_ENABLE_TESTING
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?");
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!");
920 for (
const auto& fn : find_tcp_cb)
924 Eigen::Isometry3d tcp = fn(manip_info);
929 CONSOLE_BRIDGE_logDebug(
"User Defined Find TCP Callback Failed!");
933 throw std::runtime_error(
"Could not find tcp by name " + tcp_offset_name +
"'!");
936 std::unique_ptr<tesseract_collision::DiscreteContactManager>
940 std::shared_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
941 if (discrete_manager)
942 return discrete_manager->clone();
946 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
948 discrete_manager = getDiscreteContactManagerHelper(
name);
949 if (discrete_manager ==
nullptr)
951 CONSOLE_BRIDGE_logError(
"Discrete manager with %s does not exist in factory!",
name.c_str());
956 return discrete_manager->clone();
959 std::unique_ptr<tesseract_collision::ContinuousContactManager>
963 std::shared_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
964 if (continuous_manager)
965 return continuous_manager->clone();
969 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
971 continuous_manager = getContinuousContactManagerHelper(
name);
972 if (continuous_manager ==
nullptr)
974 CONSOLE_BRIDGE_logError(
"Continuous manager with %s does not exist in factory!",
name.c_str());
979 return continuous_manager->clone();
984 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
985 discrete_manager =
nullptr;
990 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
991 continuous_manager =
nullptr;
997 if (manager ==
nullptr)
999 std::string msg =
"\n Discrete manager with " +
name +
" does not exist in factory!\n";
1000 msg +=
" Available Managers:\n";
1002 msg +=
" " + m.first +
"\n";
1004 CONSOLE_BRIDGE_logError(msg.c_str());
1011 discrete_manager = std::move(manager);
1020 if (manager ==
nullptr)
1022 std::string msg =
"\n Continuous manager with " +
name +
" does not exist in factory!\n";
1023 msg +=
" Available Managers:\n";
1025 msg +=
" " + m.first +
"\n";
1027 CONSOLE_BRIDGE_logError(msg.c_str());
1034 continuous_manager = std::move(manager);
1039 std::unique_ptr<tesseract_collision::DiscreteContactManager>
1044 if (manager ==
nullptr)
1047 manager->setContactAllowedValidator(contact_allowed_validator);
1048 if (scene_graph !=
nullptr)
1050 for (
const auto& link : scene_graph->getLinks())
1052 if (!link->collision.empty())
1057 manager->addCollisionObject(link->getName(), 0, shapes, shape_poses,
true);
1061 manager->setActiveCollisionObjects(state_solver->getActiveLinkNames());
1064 manager->setCollisionMarginData(collision_margin_data);
1071 std::unique_ptr<tesseract_collision::ContinuousContactManager>
1077 if (manager ==
nullptr)
1080 manager->setContactAllowedValidator(contact_allowed_validator);
1081 if (scene_graph !=
nullptr)
1083 for (
const auto& link : scene_graph->getLinks())
1085 if (!link->collision.empty())
1090 manager->addCollisionObject(link->getName(), 0, shapes, shape_poses,
true);
1094 manager->setActiveCollisionObjects(state_solver->getActiveLinkNames());
1097 manager->setCollisionMarginData(collision_margin_data);
1099 std::vector<std::string> active_link_names = state_solver->getActiveLinkNames();
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);
1105 manager->setCollisionObjectsTransform(tf.first, tf.second);
1113 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1114 return setActiveDiscreteContactManagerHelper(
name);
1117 std::unique_ptr<tesseract_collision::DiscreteContactManager>
1121 if (manager ==
nullptr)
1123 CONSOLE_BRIDGE_logError(
"Discrete manager with %s does not exist in factory!",
name.c_str());
1132 std::unique_lock<std::shared_mutex> continous_lock(continuous_manager_mutex);
1133 return setActiveContinuousContactManagerHelper(
name);
1136 std::unique_ptr<tesseract_collision::ContinuousContactManager>
1140 if (manager ==
nullptr)
1142 CONSOLE_BRIDGE_logError(
"Continuous manager with %s does not exist in factory!",
name.c_str());
1151 if (scene_graph->getLink(
name) ==
nullptr)
1153 CONSOLE_BRIDGE_logWarn(
"Tried to remove link (%s) that does not exist",
name.c_str());
1156 std::vector<tesseract_scene_graph::Joint::ConstPtr> joints = scene_graph->getInboundJoints(
name);
1157 assert(joints.size() <= 1);
1160 std::vector<std::string> child_link_names = scene_graph->getLinkChildrenNames(
name);
1162 scene_graph->removeLink(
name,
true);
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);
1171 for (
const auto& link_name : child_link_names)
1173 if (discrete_manager !=
nullptr)
1174 discrete_manager->removeCollisionObject(link_name);
1175 if (continuous_manager !=
nullptr)
1176 continuous_manager->removeCollisionObject(link_name);
1184 bool success =
true;
1185 for (
const auto& command : commands)
1193 switch (command->getType())
1197 auto cmd = std::static_pointer_cast<const AddLinkCommand>(command);
1198 success &= applyAddCommand(cmd);
1203 auto cmd = std::static_pointer_cast<const MoveLinkCommand>(command);
1204 success &= applyMoveLinkCommand(cmd);
1209 auto cmd = std::static_pointer_cast<const MoveJointCommand>(command);
1210 success &= applyMoveJointCommand(cmd);
1215 auto cmd = std::static_pointer_cast<const RemoveLinkCommand>(command);
1216 success &= applyRemoveLinkCommand(cmd);
1221 auto cmd = std::static_pointer_cast<const RemoveJointCommand>(command);
1222 success &= applyRemoveJointCommand(cmd);
1227 auto cmd = std::static_pointer_cast<const ReplaceJointCommand>(command);
1228 success &= applyReplaceJointCommand(cmd);
1233 auto cmd = std::static_pointer_cast<const ChangeLinkOriginCommand>(command);
1234 success &= applyChangeLinkOriginCommand(cmd);
1239 auto cmd = std::static_pointer_cast<const ChangeJointOriginCommand>(command);
1240 success &= applyChangeJointOriginCommand(cmd);
1245 auto cmd = std::static_pointer_cast<const ChangeLinkCollisionEnabledCommand>(command);
1246 success &= applyChangeLinkCollisionEnabledCommand(cmd);
1251 auto cmd = std::static_pointer_cast<const ChangeLinkVisibilityCommand>(command);
1252 success &= applyChangeLinkVisibilityCommand(cmd);
1257 auto cmd = std::static_pointer_cast<const ModifyAllowedCollisionsCommand>(command);
1258 success &= applyModifyAllowedCollisionsCommand(cmd);
1263 auto cmd = std::static_pointer_cast<const RemoveAllowedCollisionLinkCommand>(command);
1264 success &= applyRemoveAllowedCollisionLinkCommand(cmd);
1269 auto cmd = std::static_pointer_cast<const AddSceneGraphCommand>(command);
1270 success &= applyAddSceneGraphCommand(cmd);
1275 auto cmd = std::static_pointer_cast<const ChangeJointPositionLimitsCommand>(command);
1276 success &= applyChangeJointPositionLimitsCommand(cmd);
1281 auto cmd = std::static_pointer_cast<const ChangeJointVelocityLimitsCommand>(command);
1282 success &= applyChangeJointVelocityLimitsCommand(cmd);
1287 auto cmd = std::static_pointer_cast<const ChangeJointAccelerationLimitsCommand>(command);
1288 success &= applyChangeJointAccelerationLimitsCommand(cmd);
1293 auto cmd = std::static_pointer_cast<const AddKinematicsInformationCommand>(command);
1294 success &= applyAddKinematicsInformationCommand(cmd);
1299 auto cmd = std::static_pointer_cast<const ChangeCollisionMarginsCommand>(command);
1300 success &= applyChangeCollisionMarginsCommand(cmd);
1305 auto cmd = std::static_pointer_cast<const AddContactManagersPluginInfoCommand>(command);
1306 success &= applyAddContactManagersPluginInfoCommand(cmd);
1311 auto cmd = std::static_pointer_cast<const SetActiveContinuousContactManagerCommand>(command);
1312 success &= applySetActiveContinuousContactManagerCommand(cmd);
1317 auto cmd = std::static_pointer_cast<const SetActiveDiscreteContactManagerCommand>(command);
1318 success &= applySetActiveDiscreteContactManagerCommand(cmd);
1323 auto cmd = std::static_pointer_cast<const AddTrajectoryLinkCommand>(command);
1324 success &= applyAddTrajectoryLinkCommand(cmd);
1330 CONSOLE_BRIDGE_logError(
"Unhandled environment command");
1341 state_solver->setRevision(revision);
1345 environmentChanged();
1357 assert(!(!cmd->getLink() && !cmd->getJoint()));
1358 assert(!((cmd->getLink() !=
nullptr) && (cmd->getJoint() !=
nullptr) &&
1359 (cmd->getJoint()->child_link_name != cmd->getLink()->getName())));
1361 if (!applyAddLinkCommandHelper(cmd->getLink(), cmd->getJoint(), cmd->replaceAllowed()))
1365 commands.push_back(cmd);
1376 if (cmd->getLinkName().empty())
1378 CONSOLE_BRIDGE_logWarn(
"Tried to add trajectory link with empty link name.");
1382 if (cmd->getParentLinkName().empty())
1384 CONSOLE_BRIDGE_logWarn(
"Tried to add trajectory link with empty parent link name.");
1388 const bool parent_link_exists = (scene_graph->getLink(cmd->getParentLinkName()) !=
nullptr);
1389 if (!parent_link_exists)
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());
1397 auto state_solver_clone = state_solver->clone();
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)
1404 if (state.joint_names.empty())
1406 CONSOLE_BRIDGE_logWarn(
"Tried to add trajectory link (%s) with empty joint names.", cmd->getLinkName().c_str());
1410 if (state.position.rows() == 0)
1412 CONSOLE_BRIDGE_logWarn(
"Tried to add trajectory link (%s) with empty position.", cmd->getLinkName().c_str());
1416 if (
static_cast<Eigen::Index
>(state.joint_names.size()) != state.position.size())
1418 CONSOLE_BRIDGE_logWarn(
"Tried to add trajectory link (%s) where joint names and position are different sizes.",
1419 cmd->getLinkName().c_str());
1426 joint_names = state.joint_names;
1427 active_link_names = scene_graph->getJointChildrenNames(joint_names);
1429 if (std::find(active_link_names.begin(), active_link_names.end(), cmd->getParentLinkName()) !=
1430 active_link_names.end())
1432 CONSOLE_BRIDGE_logWarn(
"Tried to add trajectory link (%s) where parent link is an active link.",
1433 cmd->getLinkName().c_str());
1438 Eigen::Isometry3d parent_link_tf_inv = scene_state.
link_transforms[cmd->getParentLinkName()].inverse();
1439 for (
const auto& link_name : active_link_names)
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);
1445 auto clone = link->clone(link_name +
"_clone");
1447 for (
auto& vis_clone :
clone.visual)
1449 vis_clone->origin = link_transform * vis_clone->origin;
1450 traj_link->visual.push_back(vis_clone);
1453 for (
auto& col_clone :
clone.collision)
1455 col_clone->origin = link_transform * col_clone->origin;
1456 traj_link->collision.push_back(col_clone);
1461 auto traj_joint = std::make_shared<tesseract_scene_graph::Joint>(
"joint_" + cmd->getLinkName());
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();
1467 if (!applyAddLinkCommandHelper(traj_link, traj_joint, cmd->replaceAllowed()))
1471 commands.push_back(cmd);
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)
1481 bool link_exists =
false;
1482 bool joint_exists =
false;
1483 std::string link_name, joint_name;
1485 if (link !=
nullptr)
1487 link_name = link->getName();
1488 link_exists = (scene_graph->getLink(link_name) !=
nullptr);
1491 if (joint !=
nullptr)
1493 joint_name = joint->getName();
1494 joint_exists = (scene_graph->getJoint(joint_name) !=
nullptr);
1497 if (link_exists && !replace_allowed)
1499 CONSOLE_BRIDGE_logWarn(
"Tried to add link (%s) which already exists. Set replace_allowed to enable replacing.",
1504 if (joint_exists && !replace_allowed)
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.",
1509 joint_name.c_str());
1513 if (!link_exists && joint_exists)
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.",
1521 if (link_exists && joint && !joint_exists)
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.",
1529 if (link_exists && !joint)
1531 if (!scene_graph->addLink(*link,
true))
1536 else if (link_exists && joint_exists)
1541 if (orig_joint->child_link_name != orig_link->getName())
1543 CONSOLE_BRIDGE_logWarn(
"Tried to replace link (%s) and joint (%s) which are currently not linked. This is not "
1546 joint_name.c_str());
1550 if (!scene_graph->addLink(*link,
true))
1553 if (!scene_graph->removeJoint(joint_name))
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.");
1562 if (!scene_graph->addJoint(*joint))
1565 if (!scene_graph->addLink(*orig_link,
true))
1566 throw std::runtime_error(
"Environment: Failed to replace link and joint reset to original state.");
1569 if (!scene_graph->addJoint(*orig_joint))
1570 throw std::runtime_error(
"Environment: Failed to replace link and joint and reset to original state.");
1575 if (!state_solver->replaceJoint(*joint))
1576 throw std::runtime_error(
"Environment, failed to replace link and joint in state solver.");
1578 else if (!link_exists && !joint)
1580 std::string joint_name =
"joint_" + link_name;
1586 if (!scene_graph->addLink(*link, joint))
1589 if (!state_solver->addLink(*link, joint))
1590 throw std::runtime_error(
"Environment, failed to add link and joint in state solver.");
1594 if (!scene_graph->addLink(*link, *joint))
1597 if (!state_solver->addLink(*link, *joint))
1598 throw std::runtime_error(
"Environment, failed to add link and joint in state solver.");
1604 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1605 if (discrete_manager !=
nullptr)
1606 discrete_manager->removeCollisionObject(link_name);
1608 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1609 if (continuous_manager !=
nullptr)
1610 continuous_manager->removeCollisionObject(link_name);
1614 if (!link->collision.empty())
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);
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);
1634 if (!scene_graph->moveLink(*cmd->getJoint()))
1637 if (!state_solver->moveLink(*cmd->getJoint()))
1638 throw std::runtime_error(
"Environment, failed to move link in state solver.");
1641 commands.push_back(cmd);
1648 if (!scene_graph->moveJoint(cmd->getJointName(), cmd->getParentLink()))
1651 if (!state_solver->moveJoint(cmd->getJointName(), cmd->getParentLink()))
1652 throw std::runtime_error(
"Environment, failed to move joint in state solver.");
1655 commands.push_back(cmd);
1662 if (!removeLinkHelper(cmd->getLinkName()))
1665 if (!state_solver->removeLink(cmd->getLinkName()))
1666 throw std::runtime_error(
"Environment, failed to remove link in state solver.");
1669 commands.push_back(cmd);
1676 if (scene_graph->getJoint(cmd->getJointName()) ==
nullptr)
1678 CONSOLE_BRIDGE_logWarn(
"Tried to remove Joint (%s) that does not exist", cmd->getJointName().c_str());
1682 std::string target_link_name = scene_graph->getTargetLink(cmd->getJointName())->getName();
1684 if (!removeLinkHelper(target_link_name))
1687 if (!state_solver->removeJoint(cmd->getJointName()))
1688 throw std::runtime_error(
"Environment, failed to remove joint in state solver.");
1691 commands.push_back(cmd);
1699 if (current_joint ==
nullptr)
1701 CONSOLE_BRIDGE_logWarn(
"Tried to replace Joint (%s) that does not exist", cmd->getJoint()->getName().c_str());
1705 if (cmd->getJoint()->child_link_name != current_joint->child_link_name)
1707 CONSOLE_BRIDGE_logWarn(
"Tried to replace Joint (%s) where the child links are not the same",
1708 cmd->getJoint()->getName().c_str());
1712 if (!scene_graph->removeJoint(cmd->getJoint()->getName()))
1715 if (!scene_graph->addJoint(*cmd->getJoint()))
1718 if (!scene_graph->addJoint(*current_joint))
1719 throw std::runtime_error(
"Environment: Failed to add old joint back when replace failed!");
1724 if (!state_solver->replaceJoint(*cmd->getJoint()))
1725 throw std::runtime_error(
"Environment, failed to replace joint in state solver.");
1728 commands.push_back(cmd);
1735 const std::shared_ptr<const ChangeLinkOriginCommand>& )
1737 throw std::runtime_error(
"Unhandled environment command: CHANGE_LINK_ORIGIN");
1742 if (!scene_graph->changeJointOrigin(cmd->getJointName(), cmd->getOrigin()))
1745 if (!state_solver->changeJointOrigin(cmd->getJointName(), cmd->getOrigin()))
1746 throw std::runtime_error(
"Environment, failed to change joint origin in state solver.");
1749 commands.push_back(cmd);
1755 const std::shared_ptr<const ChangeLinkCollisionEnabledCommand>& cmd)
1757 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
1758 if (discrete_manager !=
nullptr)
1760 if (cmd->getEnabled())
1761 discrete_manager->enableCollisionObject(cmd->getLinkName());
1763 discrete_manager->disableCollisionObject(cmd->getLinkName());
1766 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
1767 if (continuous_manager !=
nullptr)
1769 if (cmd->getEnabled())
1770 continuous_manager->enableCollisionObject(cmd->getLinkName());
1772 continuous_manager->disableCollisionObject(cmd->getLinkName());
1775 scene_graph->setLinkCollisionEnabled(cmd->getLinkName(), cmd->getEnabled());
1777 if (scene_graph->getLinkCollisionEnabled(cmd->getLinkName()) != cmd->getEnabled())
1781 commands.push_back(cmd);
1787 const std::shared_ptr<const ChangeLinkVisibilityCommand>& cmd)
1789 scene_graph->setLinkVisibility(cmd->getLinkName(), cmd->getEnabled());
1790 if (scene_graph->getLinkVisibility(cmd->getLinkName()) != cmd->getEnabled())
1794 commands.push_back(cmd);
1800 const std::shared_ptr<const ModifyAllowedCollisionsCommand>& cmd)
1802 switch (cmd->getModifyType())
1806 for (
const auto& entry : cmd->getAllowedCollisionMatrix().getAllAllowedCollisions())
1807 scene_graph->removeAllowedCollision(entry.first.first, entry.first.second);
1813 scene_graph->clearAllowedCollisions();
1814 for (
const auto& entry : cmd->getAllowedCollisionMatrix().getAllAllowedCollisions())
1815 scene_graph->addAllowedCollision(entry.first.first, entry.first.second, entry.second);
1820 for (
const auto& entry : cmd->getAllowedCollisionMatrix().getAllAllowedCollisions())
1821 scene_graph->addAllowedCollision(entry.first.first, entry.first.second, entry.second);
1828 commands.push_back(cmd);
1834 const std::shared_ptr<const RemoveAllowedCollisionLinkCommand>& cmd)
1836 scene_graph->removeAllowedCollision(cmd->getLinkName());
1839 commands.push_back(cmd);
1846 if (scene_graph->isEmpty() && cmd->getJoint())
1849 std::vector<tesseract_scene_graph::Link::ConstPtr> pre_links = scene_graph->getLinks();
1850 if (scene_graph->isEmpty())
1852 if (!scene_graph->insertSceneGraph(*cmd->getSceneGraph(), cmd->getPrefix()))
1855 state_solver = std::make_unique<tesseract_scene_graph::OFKTStateSolver>(*cmd->getSceneGraph(), cmd->getPrefix());
1857 else if (!cmd->getJoint())
1863 root_joint.
child_link_name = cmd->getPrefix() + cmd->getSceneGraph()->getRoot();
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()))
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.");
1877 if (!scene_graph->insertSceneGraph(*cmd->getSceneGraph(), *cmd->getJoint(), cmd->getPrefix()))
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.");
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(),
1894 std::inserter(diff_links, diff_links.begin()));
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)
1900 if (!link->collision.empty())
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);
1914 commands.push_back(cmd);
1920 const std::shared_ptr<const ChangeJointPositionLimitsCommand>& cmd)
1923 for (
const auto& jp : cmd->getLimits())
1930 for (
const auto& jp : cmd->getLimits())
1933 jl_copy.
lower = jp.second.first;
1934 jl_copy.
upper = jp.second.second;
1936 if (!scene_graph->changeJointLimits(jp.first, jl_copy))
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.");
1944 commands.push_back(cmd);
1950 const std::shared_ptr<const ChangeJointVelocityLimitsCommand>& cmd)
1953 for (
const auto& jp : cmd->getLimits())
1960 for (
const auto& jp : cmd->getLimits())
1965 if (!scene_graph->changeJointLimits(jp.first, jl_copy))
1968 if (!state_solver->changeJointVelocityLimits(jp.first, jp.second))
1969 throw std::runtime_error(
"Environment, failed to change joint velocity limits in state solver.");
1973 commands.push_back(cmd);
1979 const std::shared_ptr<const ChangeJointAccelerationLimitsCommand>& cmd)
1982 for (
const auto& jp : cmd->getLimits())
1989 for (
const auto& jp : cmd->getLimits())
1994 if (!scene_graph->changeJointLimits(jp.first, jl_copy))
1997 if (!state_solver->changeJointAccelerationLimits(jp.first, jp.second))
1998 throw std::runtime_error(
"Environment, failed to change joint acceleration limits in state solver.");
2002 commands.push_back(cmd);
2008 const std::shared_ptr<const AddKinematicsInformationCommand>& cmd)
2010 kinematics_information.
insert(cmd->getKinematicsInformation());
2012 if (!cmd->getKinematicsInformation().kinematics_plugin_info.empty())
2014 const auto& info = cmd->getKinematicsInformation().kinematics_plugin_info;
2015 for (
const auto& search_path : info.search_paths)
2018 for (
const auto& search_library : info.search_libraries)
2021 for (
const auto& group : info.fwd_plugin_infos)
2023 for (
const auto& solver : group.second.plugins)
2024 kinematics_factory.
addFwdKinPlugin(group.first, solver.first, solver.second);
2026 if (!group.second.default_plugin.empty())
2030 for (
const auto& group : info.inv_plugin_infos)
2032 for (
const auto& solver : group.second.plugins)
2033 kinematics_factory.
addInvKinPlugin(group.first, solver.first, solver.second);
2035 if (!group.second.default_plugin.empty())
2041 commands.push_back(cmd);
2047 const std::shared_ptr<const AddContactManagersPluginInfoCommand>& cmd)
2049 const auto& info = cmd->getContactManagersPluginInfo();
2053 contact_managers_plugin_info.
insert(info);
2055 for (
const auto& search_path : info.search_paths)
2058 for (
const auto& search_library : info.search_libraries)
2061 for (
const auto& cm : info.discrete_plugin_infos.plugins)
2064 if (!info.discrete_plugin_infos.default_plugin.empty())
2067 for (
const auto& cm : info.continuous_plugin_infos.plugins)
2070 if (!info.continuous_plugin_infos.default_plugin.empty())
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);
2083 CONSOLE_BRIDGE_logDebug(
"Environment, No discrete contact manager plugins were provided");
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);
2095 CONSOLE_BRIDGE_logDebug(
"Environment, No continuous contact manager plugins were provided");
2099 commands.push_back(cmd);
2105 const std::shared_ptr<const SetActiveContinuousContactManagerCommand>& cmd)
2110 commands.push_back(cmd);
2116 const std::shared_ptr<const SetActiveDiscreteContactManagerCommand>& cmd)
2121 commands.push_back(cmd);
2127 const std::shared_ptr<const ChangeCollisionMarginsCommand>& cmd)
2129 std::optional<double> default_margin = cmd->getDefaultCollisionMargin();
2132 if (default_margin.has_value())
2135 if (!pair_margins.
empty())
2136 collision_margin_data.
apply(pair_margins, cmd->getCollisionMarginPairOverrideType());
2138 std::unique_lock<std::shared_mutex> continuous_lock(continuous_manager_mutex);
2139 if (continuous_manager !=
nullptr)
2140 continuous_manager->setCollisionMarginData(collision_margin_data);
2142 std::unique_lock<std::shared_mutex> discrete_lock(discrete_manager_mutex);
2143 if (discrete_manager !=
nullptr)
2144 discrete_manager->setCollisionMarginData(collision_margin_data);
2147 commands.push_back(cmd);
2158 bool success{
false };
2160 std::unique_lock<std::shared_mutex> lock(
mutex_);
2161 success =
impl_->initHelper(commands);
2165 std::shared_lock<std::shared_mutex> lock(
mutex_);
2166 impl_->triggerCallbacks();
2172 const std::shared_ptr<const tesseract_srdf::SRDFModel>& srdf_model)
2175 return init(commands);
2179 const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2182 std::unique_lock<std::shared_mutex> lock(
mutex_);
2183 impl_->resource_locator = locator;
2192 catch (
const std::exception& e)
2194 CONSOLE_BRIDGE_logError(
"Failed to parse URDF.");
2200 return init(commands);
2204 const std::string& srdf_string,
2205 const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2208 std::unique_lock<std::shared_mutex> lock(
mutex_);
2209 impl_->resource_locator = locator;
2218 catch (
const std::exception& e)
2220 CONSOLE_BRIDGE_logError(
"Failed to parse URDF.");
2226 auto srdf = std::make_shared<tesseract_srdf::SRDFModel>();
2229 srdf->initString(*scene_graph, srdf_string, *locator);
2231 catch (
const std::exception& e)
2233 CONSOLE_BRIDGE_logError(
"Failed to parse SRDF.");
2239 return init(commands);
2243 const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2246 std::unique_lock<std::shared_mutex> lock(
mutex_);
2247 impl_->resource_locator = locator;
2256 catch (
const std::exception& e)
2258 CONSOLE_BRIDGE_logError(
"Failed to parse URDF.");
2264 return init(commands);
2268 const std::filesystem::path& srdf_path,
2269 const std::shared_ptr<const tesseract_common::ResourceLocator>& locator)
2272 std::unique_lock<std::shared_mutex> lock(
mutex_);
2273 impl_->resource_locator = locator;
2282 catch (
const std::exception& e)
2284 CONSOLE_BRIDGE_logError(
"Failed to parse URDF.");
2290 auto srdf = std::make_shared<tesseract_srdf::SRDFModel>();
2293 srdf->initFile(*scene_graph, srdf_path.string(), *locator);
2295 catch (
const std::exception& e)
2297 CONSOLE_BRIDGE_logError(
"Failed to parse SRDF.");
2303 return init(commands);
2308 bool success{
false };
2310 std::unique_lock<std::shared_mutex> lock(
mutex_);
2311 success =
impl_->reset();
2315 std::shared_lock<std::shared_mutex> lock(
mutex_);
2316 impl_->triggerCallbacks();
2323 std::unique_lock<std::shared_mutex> lock(
mutex_);
2329 std::shared_lock<std::shared_mutex> lock(
mutex_);
2330 return std::as_const<Implementation>(*impl_).initialized;
2335 std::shared_lock<std::shared_mutex> lock(
mutex_);
2336 return std::as_const<Implementation>(*impl_).revision;
2341 std::shared_lock<std::shared_mutex> lock(
mutex_);
2342 return std::as_const<Implementation>(*impl_).init_revision;
2347 std::shared_lock<std::shared_mutex> lock(
mutex_);
2348 return std::as_const<Implementation>(*impl_).commands;
2353 bool success{
false };
2355 std::unique_lock<std::shared_mutex> lock(
mutex_);
2356 success =
impl_->applyCommandsHelper(commands);
2358 std::shared_lock<std::shared_mutex> lock(
mutex_);
2359 impl_->triggerCallbacks();
2368 return std::as_const<Implementation>(*impl_).scene_graph;
2373 std::shared_lock<std::shared_mutex> lock(
mutex_);
2374 return std::as_const<Implementation>(*impl_).getGroupJointNames(group_name);
2379 std::shared_lock<std::shared_mutex> lock(
mutex_);
2380 return std::as_const<Implementation>(*impl_).getJointGroup(group_name);
2383 std::shared_ptr<const tesseract_kinematics::JointGroup>
2386 std::shared_lock<std::shared_mutex> lock(
mutex_);
2387 return std::as_const<Implementation>(*impl_).getJointGroup(
name, joint_names);
2390 std::shared_ptr<const tesseract_kinematics::KinematicGroup>
2393 std::shared_lock<std::shared_mutex> lock(
mutex_);
2394 return std::as_const<Implementation>(*impl_).getKinematicGroup(group_name, ik_solver_name);
2400 std::shared_lock<std::shared_mutex> lock(
mutex_);
2401 return std::as_const<Implementation>(*impl_).findTCPOffset(manip_info);
2406 std::unique_lock<std::shared_mutex> lock(
mutex_);
2407 impl_->find_tcp_cb.push_back(fn);
2412 std::shared_lock<std::shared_mutex> lock(
mutex_);
2413 return std::as_const<Implementation>(*impl_).find_tcp_cb;
2418 std::unique_lock<std::shared_mutex> lock(
mutex_);
2419 impl_->event_cb[hash] = fn;
2424 std::unique_lock<std::shared_mutex> lock(
mutex_);
2425 impl_->event_cb.erase(hash);
2430 std::unique_lock<std::shared_mutex> lock(
mutex_);
2431 impl_->event_cb.clear();
2436 std::shared_lock<std::shared_mutex> lock(
mutex_);
2437 return std::as_const<Implementation>(*impl_).event_cb;
2442 std::unique_lock<std::shared_mutex> lock(
mutex_);
2443 impl_->resource_locator = std::move(locator);
2448 std::shared_lock<std::shared_mutex> lock(
mutex_);
2449 return std::as_const<Implementation>(*impl_).resource_locator;
2454 std::unique_lock<std::shared_mutex> lock(
mutex_);
2460 std::shared_lock<std::shared_mutex> lock(
mutex_);
2461 return std::as_const<Implementation>(*impl_).scene_graph->getName();
2468 std::unique_lock<std::shared_mutex> lock(
mutex_);
2469 impl_->setState(joints, floating_joints);
2472 std::shared_lock<std::shared_mutex> lock(
mutex_);
2473 impl_->triggerCurrentStateChangedCallbacks();
2477 const Eigen::Ref<const Eigen::VectorXd>& joint_values,
2481 std::unique_lock<std::shared_mutex> lock(
mutex_);
2482 impl_->setState(joint_names, joint_values, floating_joints);
2485 std::shared_lock<std::shared_mutex> lock(
mutex_);
2486 impl_->triggerCurrentStateChangedCallbacks();
2492 std::unique_lock<std::shared_mutex> lock(
mutex_);
2493 impl_->setState(floating_joints);
2496 std::shared_lock<std::shared_mutex> lock(
mutex_);
2497 impl_->triggerCurrentStateChangedCallbacks();
2503 std::shared_lock<std::shared_mutex> lock(
mutex_);
2504 return std::as_const<Implementation>(*impl_).state_solver->getState(joints, floating_joints);
2508 const Eigen::Ref<const Eigen::VectorXd>& joint_values,
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);
2517 std::shared_lock<std::shared_mutex> lock(
mutex_);
2518 return std::as_const<Implementation>(*impl_).state_solver->getState(floating_joints);
2523 std::shared_lock<std::shared_mutex> lock(
mutex_);
2524 return std::as_const<Implementation>(*impl_).current_state;
2529 std::shared_lock<std::shared_mutex> lock(
mutex_);
2530 return std::as_const<Implementation>(*impl_).timestamp;
2535 std::shared_lock<std::shared_mutex> lock(
mutex_);
2536 return std::as_const<Implementation>(*impl_).current_state_timestamp;
2541 std::shared_lock<std::shared_mutex> lock(
mutex_);
2546 std::shared_ptr<const tesseract_scene_graph::JointLimits>
2549 std::shared_lock<std::shared_mutex> lock(
mutex_);
2550 return std::as_const<Implementation>(*impl_).scene_graph->getJointLimits(joint_name);
2555 std::shared_lock<std::shared_mutex> lock(
mutex_);
2556 return std::as_const<Implementation>(*impl_).scene_graph->getLinkCollisionEnabled(
name);
2561 std::shared_lock<std::shared_mutex> lock(
mutex_);
2562 return std::as_const<Implementation>(*impl_).scene_graph->getLinkVisibility(
name);
2567 std::shared_lock<std::shared_mutex> lock(
mutex_);
2568 return std::as_const<Implementation>(*impl_).scene_graph->getAllowedCollisionMatrix();
2573 std::shared_lock<std::shared_mutex> lock(
mutex_);
2574 return std::as_const<Implementation>(*impl_).state_solver->getJointNames();
2579 std::shared_lock<std::shared_mutex> lock(
mutex_);
2580 return std::as_const<Implementation>(*impl_).state_solver->getActiveJointNames();
2585 std::shared_lock<std::shared_mutex> lock(
mutex_);
2586 return std::as_const<Implementation>(*impl_).scene_graph->getJoint(
name);
2591 std::shared_lock<std::shared_mutex> lock(
mutex_);
2592 return std::as_const<Implementation>(*impl_).getCurrentJointValues();
2597 std::shared_lock<std::shared_mutex> lock(
mutex_);
2598 return std::as_const<Implementation>(*impl_).getCurrentJointValues(joint_names);
2603 std::shared_lock<std::shared_mutex> lock(
mutex_);
2604 return std::as_const<Implementation>(*impl_).getCurrentFloatingJointValues();
2610 std::shared_lock<std::shared_mutex> lock(
mutex_);
2611 return std::as_const<Implementation>(*impl_).getCurrentFloatingJointValues(joint_names);
2616 std::shared_lock<std::shared_mutex> lock(
mutex_);
2617 return std::as_const<Implementation>(*impl_).scene_graph->getRoot();
2622 std::shared_lock<std::shared_mutex> lock(
mutex_);
2623 return std::as_const<Implementation>(*impl_).state_solver->getLinkNames();
2628 std::shared_lock<std::shared_mutex> lock(
mutex_);
2629 return std::as_const<Implementation>(*impl_).state_solver->getActiveLinkNames();
2634 std::shared_lock<std::shared_mutex> lock(
mutex_);
2635 return std::as_const<Implementation>(*impl_).scene_graph->getJointChildrenNames(joint_names);
2640 std::shared_lock<std::shared_mutex> lock(
mutex_);
2641 return std::as_const<Implementation>(*impl_).state_solver->getStaticLinkNames();
2646 std::shared_lock<std::shared_mutex> lock(
mutex_);
2647 return std::as_const<Implementation>(*impl_).getStaticLinkNames(joint_names);
2652 std::shared_lock<std::shared_mutex> lock(
mutex_);
2653 return std::as_const<Implementation>(*impl_).state_solver->getLinkTransforms();
2658 std::shared_lock<std::shared_mutex> lock(
mutex_);
2659 return std::as_const<Implementation>(*impl_).state_solver->getLinkTransform(link_name);
2663 const std::string& to_link_name)
const
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);
2671 std::shared_lock<std::shared_mutex> lock(
mutex_);
2672 return std::as_const<Implementation>(*impl_).state_solver->clone();
2677 std::shared_lock<std::shared_mutex> lock(
mutex_);
2678 return std::as_const<Implementation>(*impl_).kinematics_information;
2683 std::shared_lock<std::shared_mutex> lock(
mutex_);
2684 return std::as_const<Implementation>(*impl_).kinematics_information.group_names;
2689 std::shared_lock<std::shared_mutex> lock(
mutex_);
2690 return std::as_const<Implementation>(*impl_).contact_managers_plugin_info;
2695 std::unique_lock<std::shared_mutex> lock(
mutex_);
2696 return impl_->setActiveDiscreteContactManager(
name);
2699 std::unique_ptr<tesseract_collision::DiscreteContactManager>
2702 std::shared_lock<std::shared_mutex> lock(
mutex_);
2703 return std::as_const<Implementation>(*impl_).getDiscreteContactManager(
name);
2708 std::unique_lock<std::shared_mutex> lock(
mutex_);
2709 return impl_->setActiveContinuousContactManager(
name);
2712 std::unique_ptr<tesseract_collision::ContinuousContactManager>
2715 std::shared_lock<std::shared_mutex> lock(
mutex_);
2716 return std::as_const<Implementation>(*impl_).getContinuousContactManager(
name);
2721 std::shared_lock<std::shared_mutex> lock(
mutex_);
2722 return std::as_const<Implementation>(*impl_).getDiscreteContactManager();
2727 std::shared_lock<std::shared_mutex> lock(
mutex_);
2728 std::as_const<Implementation>(*impl_).clearCachedDiscreteContactManager();
2733 std::shared_lock<std::shared_mutex> lock(
mutex_);
2734 return std::as_const<Implementation>(*impl_).getContinuousContactManager();
2739 std::shared_lock<std::shared_mutex> lock(
mutex_);
2740 std::as_const<Implementation>(*impl_).clearCachedContinuousContactManager();
2745 std::shared_lock<std::shared_mutex> lock(
mutex_);
2746 return std::as_const<Implementation>(*impl_).collision_margin_data;
2751 return std::shared_lock<std::shared_mutex>(
mutex_);
2756 std::shared_lock<std::shared_mutex> lock(
mutex_);
2757 return std::as_const<Implementation>(*
impl_) == std::as_const<Implementation>(*rhs.
impl_);
2764 std::shared_lock<std::shared_mutex> lock(
mutex_);
2765 return std::make_unique<Environment>(std::as_const<Implementation>(*impl_).clone());
2768 template <
class Archive>
2771 std::shared_lock<std::shared_mutex> lock(
mutex_);
2772 ar& BOOST_SERIALIZATION_NVP(
impl_);
2775 template <
class Archive>
2778 std::unique_lock<std::shared_mutex> lock(
mutex_);
2779 ar& BOOST_SERIALIZATION_NVP(
impl_);
2782 template <
class Archive>
2785 boost::serialization::split_member(ar, *
this, version);