moveit2
The MoveIt Motion Planning Framework for ROS 2.
rdf_loader.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan, Mathias Lüdtke, Dave Coleman */
36 
37 #pragma once
38 
41 #if __has_include(<urdf/model.hpp>)
42 #include <urdf/model.hpp>
43 #else
44 #include <urdf/model.h>
45 #endif
46 #include <srdfdom/model.h>
47 #include <rclcpp/rclcpp.hpp>
48 
49 namespace rdf_loader
50 {
51 MOVEIT_CLASS_FORWARD(RDFLoader); // Defines RDFLoaderPtr, ConstPtr, WeakPtr... etc
52 
53 using NewModelCallback = std::function<void()>;
54 
57 class RDFLoader
58 {
59 public:
76  RDFLoader(const std::shared_ptr<rclcpp::Node>& node, const std::string& ros_name = "robot_description",
77  bool default_continuous_value = false, double default_timeout = 10.0);
78 
80  RDFLoader(const std::string& urdf_string, const std::string& srdf_string);
81 
83  const std::string& getRobotDescription() const
84  {
85  return ros_name_;
86  }
87 
89  const std::string& getURDFString() const
90  {
91  return urdf_string_;
92  }
93 
95  const urdf::ModelInterfaceSharedPtr& getURDF() const
96  {
97  return urdf_;
98  }
99 
101  const srdf::ModelSharedPtr& getSRDF() const
102  {
103  return srdf_;
104  }
105 
107  {
108  new_model_cb_ = cb;
109  }
110 
112  static bool isXacroFile(const std::string& path);
113 
115  static bool loadFileToString(std::string& buffer, const std::string& path);
116 
118  static bool loadXacroFileToString(std::string& buffer, const std::string& path,
119  const std::vector<std::string>& xacro_args);
120 
123  static bool loadXmlFileToString(std::string& buffer, const std::string& path,
124  const std::vector<std::string>& xacro_args);
125 
127  static bool loadPkgFileToString(std::string& buffer, const std::string& package_name,
128  const std::string& relative_path, const std::vector<std::string>& xacro_args);
129 
130 private:
131  bool loadFromStrings();
132 
133  void urdfUpdateCallback(const std::string& new_urdf_string);
134  void srdfUpdateCallback(const std::string& new_srdf_string);
135 
136  NewModelCallback new_model_cb_;
137 
138  std::string ros_name_;
139  std::string urdf_string_, srdf_string_;
140 
141  SynchronizedStringParameter urdf_ssp_;
142  SynchronizedStringParameter srdf_ssp_;
143 
144  srdf::ModelSharedPtr srdf_;
145  urdf::ModelInterfaceSharedPtr urdf_;
146 };
147 } // namespace rdf_loader
static bool loadXmlFileToString(std::string &buffer, const std::string &path, const std::vector< std::string > &xacro_args)
helper that branches between loadFileToString() and loadXacroFileToString() based on result of isXacr...
Definition: rdf_loader.cpp:206
static bool isXacroFile(const std::string &path)
determine if given path points to a xacro file
Definition: rdf_loader.cpp:120
const srdf::ModelSharedPtr & getSRDF() const
Get the parsed SRDF model.
Definition: rdf_loader.h:101
const std::string & getURDFString() const
Get the URDF string.
Definition: rdf_loader.h:89
const std::string & getRobotDescription() const
Get the resolved parameter name for the robot description.
Definition: rdf_loader.h:83
void setNewModelCallback(const NewModelCallback &cb)
Definition: rdf_loader.h:106
const urdf::ModelInterfaceSharedPtr & getURDF() const
Get the parsed URDF model.
Definition: rdf_loader.h:95
static bool loadPkgFileToString(std::string &buffer, const std::string &package_name, const std::string &relative_path, const std::vector< std::string > &xacro_args)
helper that generates a file path based on package name and relative file path to package
Definition: rdf_loader.cpp:217
RDFLoader(const std::shared_ptr< rclcpp::Node > &node, const std::string &ros_name="robot_description", bool default_continuous_value=false, double default_timeout=10.0)
Default constructor.
Definition: rdf_loader.cpp:67
static bool loadFileToString(std::string &buffer, const std::string &path)
load file from given path into buffer
Definition: rdf_loader.cpp:128
static bool loadXacroFileToString(std::string &buffer, const std::string &path, const std::vector< std::string > &xacro_args)
run xacro with the given args on the file, return result in buffer
Definition: rdf_loader.cpp:159
SynchronizedStringParameter is a way to load a string from the ROS environment.
MOVEIT_CLASS_FORWARD(RDFLoader)
std::function< void()> NewModelCallback
Definition: rdf_loader.h:53
string package_name
Definition: setup.py:4