parse_srdf_example.cpp
Go to the documentation of this file.
1 #include <console_bridge/console.h>
9 #include <tesseract_srdf/utils.h>
10 
11 using namespace tesseract_scene_graph;
12 using namespace tesseract_srdf;
13 
14 std::string toString(const ShortestPath& path)
15 {
16  std::stringstream ss;
17  ss << path;
18  return ss.str();
19 }
20 
21 std::string toString(bool b) { return b ? "true" : "false"; }
22 
23 int main(int /*argc*/, char** /*argv*/)
24 {
25  // documentation:start:1: Create scene graph
26  SceneGraph g;
27 
28  g.setName("kuka_lbr_iiwa_14_r820");
29 
30  Link base_link("base_link");
31  Link link_1("link_1");
32  Link link_2("link_2");
33  Link link_3("link_3");
34  Link link_4("link_4");
35  Link link_5("link_5");
36  Link link_6("link_6");
37  Link link_7("link_7");
38  Link tool0("tool0");
39 
40  g.addLink(base_link);
41  g.addLink(link_1);
42  g.addLink(link_2);
43  g.addLink(link_3);
44  g.addLink(link_4);
45  g.addLink(link_5);
46  g.addLink(link_6);
47  g.addLink(link_7);
48  g.addLink(tool0);
49 
50  Joint base_joint("base_joint");
51  base_joint.parent_link_name = "base_link";
52  base_joint.child_link_name = "link_1";
53  base_joint.type = JointType::FIXED;
54  g.addJoint(base_joint);
55 
56  Joint joint_1("joint_1");
57  joint_1.parent_link_name = "link_1";
58  joint_1.child_link_name = "link_2";
59  joint_1.type = JointType::REVOLUTE;
60  g.addJoint(joint_1);
61 
62  Joint joint_2("joint_2");
63  joint_2.parent_to_joint_origin_transform.translation()(0) = 1.25;
64  joint_2.parent_link_name = "link_2";
65  joint_2.child_link_name = "link_3";
66  joint_2.type = JointType::REVOLUTE;
67  g.addJoint(joint_2);
68 
69  Joint joint_3("joint_3");
70  joint_3.parent_to_joint_origin_transform.translation()(0) = 1.25;
71  joint_3.parent_link_name = "link_3";
72  joint_3.child_link_name = "link_4";
73  joint_3.type = JointType::REVOLUTE;
74  g.addJoint(joint_3);
75 
76  Joint joint_4("joint_4");
77  joint_4.parent_to_joint_origin_transform.translation()(1) = 1.25;
78  joint_4.parent_link_name = "link_4";
79  joint_4.child_link_name = "link_5";
80  joint_4.type = JointType::REVOLUTE;
81  g.addJoint(joint_4);
82 
83  Joint joint_5("joint_5");
84  joint_5.parent_to_joint_origin_transform.translation()(1) = 1.25;
85  joint_5.parent_link_name = "link_5";
86  joint_5.child_link_name = "link_6";
87  joint_5.type = JointType::REVOLUTE;
88  g.addJoint(joint_5);
89 
90  Joint joint_6("joint_6");
91  joint_6.parent_to_joint_origin_transform.translation()(1) = 1.25;
92  joint_6.parent_link_name = "link_6";
93  joint_6.child_link_name = "link_7";
94  joint_6.type = JointType::REVOLUTE;
95  g.addJoint(joint_6);
96 
97  Joint joint_tool0("joint_tool0");
98  joint_tool0.parent_link_name = "link_7";
99  joint_tool0.child_link_name = "tool0";
100  joint_tool0.type = JointType::FIXED;
101  g.addJoint(joint_tool0);
102  // documentation:end:1: Create scene graph
103 
104  // documentation:start:2: Get the srdf file path
106  std::string srdf_file =
107  locator.locateResource("package://tesseract_support/urdf/lbr_iiwa_14_r820.srdf")->getFilePath();
108  // documentation:end:2: Get the srdf file path
109 
110  // documentation:start:3: Parse the srdf
111  SRDFModel srdf;
112  try
113  {
114  srdf.initFile(g, srdf_file, locator);
115  }
116  catch (const std::exception& e)
117  {
118  CONSOLE_BRIDGE_logError("Failed to parse SRDF.");
120  return 1;
121  }
122  // documentation:end:3: Parse the srdf
123 
124  // documentation:start:4: Add allowed collision matrix to scene graph
125  g.addAllowedCollision("link_1", "link_2", "adjacent");
126 
128  // documentation:end:4: Add allowed collision matrix to scene graph
129 
130  // documentation:start:5: Get info about allowed collision matrix
132  const tesseract_common::AllowedCollisionEntries& acm_entries = acm->getAllAllowedCollisions();
133  CONSOLE_BRIDGE_logInform("ACM Number of entries: %d", acm_entries.size());
134  // documentation:end:5: Get info about allowed collision matrix
135 }
tesseract_scene_graph::JointType::REVOLUTE
@ REVOLUTE
graph.h
tesseract_srdf
Main namespace.
Definition: collision_margins.h:43
allowed_collision_matrix.h
tesseract_common::AllowedCollisionEntries
std::unordered_map< tesseract_common::LinkNamesPair, std::string, tesseract_common::PairHash > AllowedCollisionEntries
utils.h
tesseract_scene_graph::SceneGraph::addAllowedCollision
void addAllowedCollision(const std::string &link_name1, const std::string &link_name2, const std::string &reason)
resource_locator.h
joint.h
tesseract_scene_graph::Joint::parent_to_joint_origin_transform
Eigen::Isometry3d parent_to_joint_origin_transform
tesseract_scene_graph::SceneGraph::getAllowedCollisionMatrix
std::shared_ptr< tesseract_common::AllowedCollisionMatrix > getAllowedCollisionMatrix()
tesseract_scene_graph::SceneGraph
tesseract_srdf::SRDFModel
Representation of semantic information about the robot.
Definition: srdf_model.h:54
tesseract_scene_graph::SceneGraph::addLink
bool addLink(const Link &link, bool replace_allowed=false)
utils.h
Tesseract SRDF utility functions.
tesseract_srdf::SRDFModel::initFile
void initFile(const tesseract_scene_graph::SceneGraph &scene_graph, const std::string &filename, const tesseract_common::ResourceLocator &locator)
Load Model given a filename.
Definition: srdf_model.cpp:62
tesseract_common::AllowedCollisionMatrix::ConstPtr
std::shared_ptr< const AllowedCollisionMatrix > ConstPtr
tesseract_scene_graph::Joint::child_link_name
std::string child_link_name
tesseract_scene_graph::SceneGraph::addJoint
bool addJoint(const Joint &joint)
tesseract_common::printNestedException
void printNestedException(const std::exception &e, int level=0)
tesseract_scene_graph::ShortestPath
tesseract_scene_graph::Joint
tesseract_common::GeneralResourceLocator::locateResource
std::shared_ptr< Resource > locateResource(const std::string &url) const override
tesseract_scene_graph::SceneGraph::setName
void setName(const std::string &name)
toString
std::string toString(const ShortestPath &path)
Definition: parse_srdf_example.cpp:14
tesseract_common::GeneralResourceLocator
tesseract_scene_graph::Joint::type
JointType type
tesseract_srdf::processSRDFAllowedCollisions
void processSRDFAllowedCollisions(tesseract_scene_graph::SceneGraph &scene_graph, const SRDFModel &srdf_model)
Add allowed collisions to the scene graph.
Definition: utils.cpp:33
srdf_model.h
Parse srdf xml.
tesseract_scene_graph
tesseract_scene_graph::Joint::parent_link_name
std::string parent_link_name
tesseract_scene_graph::JointType::FIXED
@ FIXED
main
int main(int, char **)
Definition: parse_srdf_example.cpp:23


tesseract_srdf
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:04