moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
collisions_updater.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, Fraunhofer IPA
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 Fraunhofer IPA 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: Mathias Lüdtke */
36
37#include <cstdint>
43#include <boost/program_options.hpp>
44#include <rclcpp/logger.hpp>
45#include <rclcpp/logging.hpp>
46
47namespace po = boost::program_options;
48
49int main(int argc, char* argv[])
50{
51 std::filesystem::path config_pkg_path;
52 std::filesystem::path urdf_path;
53 std::filesystem::path srdf_path;
54 std::filesystem::path output_path;
55
56 bool include_default = false, include_always = false, keep_old = false, verbose = false;
57
58 double min_collision_fraction = 1.0;
59
60 uint32_t never_trials = 0;
61
62 // clang-format off
63 po::options_description desc("Allowed options");
64 desc.add_options()("help", "show help")("config-pkg", po::value(&config_pkg_path), "path to MoveIt config package")(
65 "urdf", po::value(&urdf_path), "path to URDF ( or xacro)")("srdf", po::value(&srdf_path),
66 "path to SRDF ( or xacro)")(
67 "output", po::value(&output_path),
68 "output path for SRDF")("xacro-args", po::value<std::vector<std::string> >()->composing(),
69 "additional arguments for xacro")("default", po::bool_switch(&include_default),
70 "disable default colliding pairs")(
71 "always", po::bool_switch(&include_always), "disable always colliding pairs")("keep", po::bool_switch(&keep_old),
72 "keep disabled link from SRDF")(
73 "verbose", po::bool_switch(&verbose), "verbose output")("trials", po::value(&never_trials),
74 "number of trials for searching never colliding pairs")(
75 "min-collision-fraction", po::value(&min_collision_fraction),
76 "fraction of small sample size to determine links that are always colliding");
77 // clang-format on
78
79 po::positional_options_description pos_desc;
80 pos_desc.add("xacro-args", -1);
81
82 po::variables_map vm;
83 po::store(po::command_line_parser(argc, argv).options(desc).positional(pos_desc).run(), vm);
84 po::notify(vm);
85
86 if (vm.count("help"))
87 {
88 std::cout << desc << '\n';
89 return 1;
90 }
91
92 rclcpp::init(argc, argv);
93 rclcpp::Node::SharedPtr node = std::make_shared<rclcpp::Node>("collision_updater");
94 moveit_setup::DataWarehousePtr config_data = std::make_shared<moveit_setup::DataWarehouse>(node);
95
97 setup_step.initialize(node, config_data);
98
99 if (!config_pkg_path.empty())
100 {
101 auto package_settings = config_data->get<moveit_setup::PackageSettingsConfig>("package_settings");
102 try
103 {
104 package_settings->loadExisting(config_pkg_path.string());
105 }
106 catch (const std::runtime_error& e)
107 {
108 RCLCPP_ERROR_STREAM(node->get_logger(), "Could not load config at '" << config_pkg_path << "'. " << e.what());
109 return 1;
110 }
111 }
112 else if (urdf_path.empty() || srdf_path.empty())
113 {
114 RCLCPP_ERROR_STREAM(node->get_logger(), "Please provide config package or URDF and SRDF path");
115 return 1;
116 }
117 else if (rdf_loader::RDFLoader::isXacroFile(srdf_path.string()) && output_path.empty())
118 {
119 RCLCPP_ERROR_STREAM(node->get_logger(), "Please provide a different output file for SRDF xacro input file");
120 return 1;
121 }
122
123 auto srdf_config = config_data->get<moveit_setup::SRDFConfig>("srdf");
124
125 // overwrite config paths if applicable
126 if (!urdf_path.empty())
127 {
128 auto config = config_data->get<moveit_setup::URDFConfig>("urdf");
129
130 std::vector<std::string> xacro_args;
131 if (vm.count("xacro-args"))
132 xacro_args = vm["xacro-args"].as<std::vector<std::string> >();
133
134 config->loadFromPath(urdf_path, xacro_args);
135 }
136 if (!srdf_path.empty())
137 {
138 srdf_config->loadSRDFFile(srdf_path);
139 }
140
141 if (!keep_old)
142 {
143 srdf_config->clearCollisionData();
144 }
145
146 setup_step.startGenerationThread(never_trials, min_collision_fraction, verbose);
147 int thread_progress;
148 int last_progress = 0;
149 while ((thread_progress = setup_step.getThreadProgress()) < 100)
150 {
151 if (thread_progress - last_progress > 10)
152 {
153 RCLCPP_INFO(node->get_logger(), "%d%% complete...", thread_progress);
154 last_progress = thread_progress;
155 }
156 }
157 setup_step.joinGenerationThread();
158 RCLCPP_INFO(node->get_logger(), "100%% complete...");
159
160 size_t skip_mask = 0;
161 if (!include_default)
162 skip_mask |= (1 << moveit_setup::srdf_setup::DEFAULT);
163 if (!include_always)
164 skip_mask |= (1 << moveit_setup::srdf_setup::ALWAYS);
165
166 setup_step.linkPairsToSRDFSorted(skip_mask);
167
168 srdf_config->write(output_path.empty() ? srdf_config->getPath() : output_path);
169
170 return 0;
171}
void initialize(const rclcpp::Node::SharedPtr &parent_node, const DataWarehousePtr &config_data)
Called after construction to initialize the step.
void loadFromPath(const std::filesystem::path &urdf_file_path, const std::string &xacro_args="")
Load URDF File.
void startGenerationThread(unsigned int num_trials, double min_frac, bool verbose=true)
void linkPairsToSRDFSorted(size_t skip_mask=0)
Output Link Pairs to SRDF Format; sorted; with optional filter.
static bool isXacroFile(const std::string &path)
determine if given path points to a xacro file
int main(int argc, char *argv[])