49int main(
int argc,
char* argv[])
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;
56 bool include_default =
false, include_always =
false, keep_old =
false, verbose =
false;
58 double min_collision_fraction = 1.0;
60 uint32_t never_trials = 0;
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");
79 po::positional_options_description pos_desc;
80 pos_desc.add(
"xacro-args", -1);
83 po::store(po::command_line_parser(argc, argv).options(desc).positional(pos_desc).run(), vm);
88 std::cout << desc <<
'\n';
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);
99 if (!config_pkg_path.empty())
104 package_settings->loadExisting(config_pkg_path.string());
106 catch (
const std::runtime_error& e)
108 RCLCPP_ERROR_STREAM(node->get_logger(),
"Could not load config at '" << config_pkg_path <<
"'. " << e.what());
112 else if (urdf_path.empty() || srdf_path.empty())
114 RCLCPP_ERROR_STREAM(node->get_logger(),
"Please provide config package or URDF and SRDF path");
119 RCLCPP_ERROR_STREAM(node->get_logger(),
"Please provide a different output file for SRDF xacro input file");
126 if (!urdf_path.empty())
130 std::vector<std::string> xacro_args;
131 if (vm.count(
"xacro-args"))
132 xacro_args = vm[
"xacro-args"].as<std::vector<std::string> >();
136 if (!srdf_path.empty())
138 srdf_config->loadSRDFFile(srdf_path);
143 srdf_config->clearCollisionData();
148 int last_progress = 0;
151 if (thread_progress - last_progress > 10)
153 RCLCPP_INFO(node->get_logger(),
"%d%% complete...", thread_progress);
154 last_progress = thread_progress;
158 RCLCPP_INFO(node->get_logger(),
"100%% complete...");
160 size_t skip_mask = 0;
161 if (!include_default)
168 srdf_config->write(output_path.empty() ? srdf_config->getPath() : output_path);