moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
modified_urdf_config.hpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2022, Metro Robots
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 Metro Robots 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: David V. Lu!! */
36
37#pragma once
38
41
42namespace moveit_setup
43{
50{
51public:
52 void onInit() override;
53 bool isConfigured() const override;
54
55 void loadPrevious(const std::filesystem::path& /*config_package_path*/, const YAML::Node& node) override;
56 YAML::Node saveToYaml() const override;
57
61 bool hasChanges() const;
62
64 {
65 public:
66 GeneratedModifiedURDF(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
67 ModifiedUrdfConfig& parent)
68 : TemplatedGeneratedFile(package_path, last_gen_time), parent_(parent)
69 {
70 }
71
72 std::filesystem::path getRelativePath() const override
73 {
74 return std::filesystem::path("config") / (parent_.urdf_config_->getRobotName() + ".urdf.xacro");
75 }
76
77 std::filesystem::path getTemplatePath() const override
78 {
79 return getSharePath("moveit_setup_controllers") / "templates" / "config" / "modified.urdf.xacro";
80 }
81
82 std::string getDescription() const override
83 {
84 return "A modified version of the original URDF file with additional interfaces (e.g. ros2_control, simulation)";
85 }
86
87 bool hasChanges() const override
88 {
89 return parent_.hasChanges();
90 }
91
92 protected:
94 };
95
96 void collectFiles(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
97 std::vector<GeneratedFilePtr>& files) override;
98 void collectDependencies(std::set<std::string>& packages) const override;
99 void collectVariables(std::vector<TemplateVariable>& variables) override;
100
101protected:
102 std::unordered_map<std::string, IncludedXacroConfig::Ptr> getIncludedXacroMap() const
103 {
104 return config_data_->getAll<IncludedXacroConfig>();
105 }
106
107 std::vector<IncludedXacroConfig::Ptr> getIncludedXacros() const
108 {
109 std::vector<IncludedXacroConfig::Ptr> xacros;
110 for (auto& pair : getIncludedXacroMap())
111 {
112 if (pair.second->isConfigured())
113 xacros.push_back(pair.second);
114 }
115 return xacros;
116 }
117
118 std::vector<std::string> getIncludedXacroNames() const
119 {
120 std::vector<std::string> names;
121 for (auto& pair : getIncludedXacroMap())
122 {
123 if (pair.second->isConfigured())
124 names.push_back(pair.first);
125 }
126
127 return names;
128 }
129
130 std::shared_ptr<URDFConfig> urdf_config_;
131 std::set<std::string> cached_xacro_names_;
132};
133} // namespace moveit_setup
A virtual class that represents a xacro header that should be included in the modified urdf configura...
std::filesystem::path getRelativePath() const override
Returns the path relative to the configuration package root.
std::filesystem::path getTemplatePath() const override
Returns the full path to the template file.
bool hasChanges() const override
Returns true if this file will have changes when it is written to file.
GeneratedModifiedURDF(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, ModifiedUrdfConfig &parent)
std::string getDescription() const override
Returns an English description of this file's purpose.
A configuration that stores info about modifications to the URDF.
void onInit() override
Overridable initialization method.
void collectDependencies(std::set< std::string > &packages) const override
Collect the package dependencies generated by this configuration.
void collectVariables(std::vector< TemplateVariable > &variables) override
Collect key/value pairs for use in templates.
std::vector< IncludedXacroConfig::Ptr > getIncludedXacros() const
YAML::Node saveToYaml() const override
Optionally save "meta" information for saving in the .setup_assistant yaml file.
bool isConfigured() const override
Return true if this part of the configuration is completely set up.
void loadPrevious(const std::filesystem::path &, const YAML::Node &node) override
Loads the configuration from an existing MoveIt configuration.
std::shared_ptr< URDFConfig > urdf_config_
std::unordered_map< std::string, IncludedXacroConfig::Ptr > getIncludedXacroMap() const
void collectFiles(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, std::vector< GeneratedFilePtr > &files) override
Collect the files generated by this configuration and add them to the vector.
bool hasChanges() const
Returns true if this or any of the included xacros have changes, requiring the URDF to be regenerated...
std::vector< std::string > getIncludedXacroNames() const
std::set< std::string > cached_xacro_names_
where all the data for each part of the configuration is stored.
Definition config.hpp:58
std::shared_ptr< DataWarehouse > config_data_
Definition config.hpp:161
Specialization of GeneratedFile for generating a text file from a template.
Definition templates.hpp:60
std::filesystem::path getSharePath(const std::string &package_name)
Return a path for the given package's share folder.
Definition utilities.hpp:51
std::filesystem::file_time_type GeneratedTime