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 #include <urdf/model.h> // for testing a valid urdf is loaded
39 
40 namespace moveit_setup
41 {
42 class URDFConfig : public SetupConfig
43 {
44 public:
46  {
47  urdf_model_ = std::make_shared<urdf::Model>();
48  }
49 
50  void onInit() override;
51 
52  void loadPrevious(const std::filesystem::path& package_path, const YAML::Node& node) override;
53  YAML::Node saveToYaml() const override;
54 
56  void loadFromPath(const std::filesystem::path& urdf_file_path, const std::string& xacro_args = "");
57  void loadFromPath(const std::filesystem::path& urdf_file_path, const std::vector<std::string>& xacro_args);
58  void loadFromPackage(const std::filesystem::path& package_name, const std::filesystem::path& relative_path,
59  const std::string& xacro_args = "");
60 
61  const urdf::Model& getModel() const
62  {
63  return *urdf_model_;
64  }
65 
66  const std::shared_ptr<urdf::Model>& getModelPtr() const
67  {
68  return urdf_model_;
69  }
70 
71  std::string getURDFPackageName() const
72  {
73  return urdf_pkg_name_;
74  }
75 
76  std::string getURDFContents() const
77  {
78  return urdf_string_;
79  }
80 
81  std::filesystem::path getURDFPath() const
82  {
83  return urdf_path_;
84  }
85 
86  std::string getXacroArgs() const
87  {
88  return xacro_args_;
89  }
90 
91  bool isConfigured() const override;
92 
93  bool isXacroFile() const;
94 
95  void collectDependencies(std::set<std::string>& packages) const override;
96 
97  void collectVariables(std::vector<TemplateVariable>& variables) override;
98 
99  std::string getRobotName() const
100  {
101  return urdf_model_->getName();
102  }
103 
104 protected:
105  void setPackageName();
106  void load();
107 
109  std::filesystem::path urdf_path_;
110 
112  std::string urdf_pkg_name_;
113 
115  std::filesystem::path urdf_pkg_relative_path_;
116 
119 
121  std::string xacro_args_;
122  std::vector<std::string> xacro_args_vec_;
123 
125  std::shared_ptr<urdf::Model> urdf_model_;
126 
128  std::string urdf_string_;
129 };
130 } // 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:66
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:86
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
Definition: urdf_config.hpp:99
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:76
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:71
std::filesystem::path getURDFPath() const
Definition: urdf_config.hpp:81
std::string urdf_string_
URDF robot model string.
const urdf::Model & getModel() const
Definition: urdf_config.hpp:61
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