moveit2
The MoveIt Motion Planning Framework for ROS 2.
urdf_config.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2021, PickNik Robotics, 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 PickNik Robotics 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 #pragma once
36 
38 #if __has_include(<urdf/model.hpp>) // for testing a valid urdf is loaded
39 #include <urdf/model.hpp>
40 #else
41 #include <urdf/model.h>
42 #endif
43 
44 namespace moveit_setup
45 {
46 class URDFConfig : public SetupConfig
47 {
48 public:
50  {
51  urdf_model_ = std::make_shared<urdf::Model>();
52  }
53 
54  void onInit() override;
55 
56  void loadPrevious(const std::filesystem::path& package_path, const YAML::Node& node) override;
57  YAML::Node saveToYaml() const override;
58 
60  void loadFromPath(const std::filesystem::path& urdf_file_path, const std::string& xacro_args = "");
61  void loadFromPath(const std::filesystem::path& urdf_file_path, const std::vector<std::string>& xacro_args);
62  void loadFromPackage(const std::filesystem::path& package_name, const std::filesystem::path& relative_path,
63  const std::string& xacro_args = "");
64 
65  const urdf::Model& getModel() const
66  {
67  return *urdf_model_;
68  }
69 
70  const std::shared_ptr<urdf::Model>& getModelPtr() const
71  {
72  return urdf_model_;
73  }
74 
75  std::string getURDFPackageName() const
76  {
77  return urdf_pkg_name_;
78  }
79 
80  std::string getURDFContents() const
81  {
82  return urdf_string_;
83  }
84 
85  std::filesystem::path getURDFPath() const
86  {
87  return urdf_path_;
88  }
89 
90  std::string getXacroArgs() const
91  {
92  return xacro_args_;
93  }
94 
95  bool isConfigured() const override;
96 
97  bool isXacroFile() const;
98 
99  void collectDependencies(std::set<std::string>& packages) const override;
100 
101  void collectVariables(std::vector<TemplateVariable>& variables) override;
102 
103  std::string getRobotName() const
104  {
105  return urdf_model_->getName();
106  }
107 
108 protected:
109  void setPackageName();
110  void load();
111 
113  std::filesystem::path urdf_path_;
114 
116  std::string urdf_pkg_name_;
117 
119  std::filesystem::path urdf_pkg_relative_path_;
120 
123 
125  std::string xacro_args_;
126  std::vector<std::string> xacro_args_vec_;
127 
129  std::shared_ptr<urdf::Model> urdf_model_;
130 
132  std::string urdf_string_;
133 };
134 } // namespace moveit_setup
where all the data for each part of the configuration is stored.
Definition: config.hpp:58
void collectDependencies(std::set< std::string > &packages) const override
Collect the package dependencies generated by this configuration.
std::filesystem::path urdf_path_
Full file-system path to urdf.
void loadFromPath(const std::filesystem::path &urdf_file_path, const std::string &xacro_args="")
Load URDF File.
Definition: urdf_config.cpp:75
std::filesystem::path urdf_pkg_relative_path_
Path relative to urdf package (note: this may be same as urdf_path_)
const std::shared_ptr< urdf::Model > & getModelPtr() const
Definition: urdf_config.hpp:70
YAML::Node saveToYaml() const override
Optionally save "meta" information for saving in the .setup_assistant yaml file.
Definition: urdf_config.cpp:63
std::string getXacroArgs() const
Definition: urdf_config.hpp:90
bool isConfigured() const override
Return true if this part of the configuration is completely set up.
void loadFromPackage(const std::filesystem::path &package_name, const std::filesystem::path &relative_path, const std::string &xacro_args="")
std::string getRobotName() const
std::vector< std::string > xacro_args_vec_
bool urdf_from_xacro_
Flag indicating whether the URDF was loaded from .xacro format.
std::string getURDFContents() const
Definition: urdf_config.hpp:80
std::shared_ptr< urdf::Model > urdf_model_
URDF robot model.
void onInit() override
Overridable initialization method.
Definition: urdf_config.cpp:42
void loadPrevious(const std::filesystem::path &package_path, const YAML::Node &node) override
Loads the configuration from an existing MoveIt configuration.
Definition: urdf_config.cpp:47
std::string xacro_args_
xacro arguments in two different formats
void collectVariables(std::vector< TemplateVariable > &variables) override
Collect key/value pairs for use in templates.
std::string getURDFPackageName() const
Definition: urdf_config.hpp:75
std::filesystem::path getURDFPath() const
Definition: urdf_config.hpp:85
std::string urdf_string_
URDF robot model string.
const urdf::Model & getModel() const
Definition: urdf_config.hpp:65
std::string urdf_pkg_name_
Name of package containing urdf (note: this may be empty b/c user may not have urdf in pkg)
string package_name
Definition: setup.py:4
packages
Definition: setup.py:9