60 const rclcpp::Logger& logger)
62 for (
const moveit_msgs::msg::PositionConstraint& position_constraint : constraints.position_constraints)
65 const moveit_msgs::msg::PositionConstraint& pc = position_constraint;
66 lcp.first = pc.constraint_region.primitive_poses[0].position;
67 lcmap[position_constraint.link_name] = lcp;
70 for (
const moveit_msgs::msg::OrientationConstraint& orientation_constraint : constraints.orientation_constraints)
72 if (lcmap.count(orientation_constraint.link_name))
74 lcmap[orientation_constraint.link_name].second = orientation_constraint.orientation;
78 RCLCPP_WARN(logger,
"Orientation constraint for %s has no matching position constraint",
79 orientation_constraint.link_name.c_str());
84int main(
int argc,
char** argv)
86 rclcpp::init(argc, argv);
87 rclcpp::NodeOptions node_options;
88 node_options.allow_undeclared_parameters(
true);
89 node_options.automatically_declare_parameters_from_overrides(
true);
90 rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared(
"save_warehouse_as_text", node_options);
93 boost::program_options::options_description desc;
94 desc.add_options()(
"help",
"Show help message")(
"host", boost::program_options::value<std::string>(),
96 "DB.")(
"port", boost::program_options::value<std::size_t>(),
99 boost::program_options::variables_map vm;
100 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
101 boost::program_options::notify(vm);
103 if (vm.count(
"help"))
105 std::cout << desc <<
'\n';
110 if (vm.count(
"host") && vm.count(
"port"))
111 conn->setParams(vm[
"host"].as<std::string>(), vm[
"port"].as<std::size_t>());
112 if (!conn->connect())
121 std::vector<std::string> scene_names;
124 for (
const std::string& scene_name : scene_names)
129 RCLCPP_INFO(node->get_logger(),
"Saving scene '%s'", scene_name.c_str());
130 psm.
getPlanningScene()->setPlanningSceneMsg(
static_cast<const moveit_msgs::msg::PlanningScene&
>(*pswm));
131 std::ofstream fout((scene_name +
".scene").c_str());
135 std::vector<std::string> robot_state_names;
138 std::stringstream rsregex;
139 rsregex <<
".*" << scene_name <<
".*";
143 std::vector<std::string> constraint_names;
145 std::stringstream csregex;
146 csregex <<
".*" << scene_name <<
".*";
149 if (!(robot_state_names.empty() && constraint_names.empty()))
151 std::ofstream qfout((scene_name +
".queries").c_str());
152 qfout << scene_name <<
'\n';
153 if (!robot_state_names.empty())
155 qfout <<
"start" <<
'\n';
156 qfout << robot_state_names.size() <<
'\n';
157 for (
const std::string& robot_state_name : robot_state_names)
159 RCLCPP_INFO(node->get_logger(),
"Saving start state %s for scene %s", robot_state_name.c_str(),
161 qfout << robot_state_name <<
'\n';
167 qfout <<
'.' <<
'\n';
171 if (!constraint_names.empty())
173 qfout <<
"goal" <<
'\n';
174 qfout << constraint_names.size() <<
'\n';
175 for (
const std::string& constraint_name : constraint_names)
177 RCLCPP_INFO(node->get_logger(),
"Saving goal %s for scene %s", constraint_name.c_str(), scene_name.c_str());
178 qfout <<
"link_constraint" <<
'\n';
179 qfout << constraint_name <<
'\n';
185 for (std::pair<const std::string, LinkConstraintPair>& iter : lcmap)
187 std::string link_name = iter.first;
189 qfout << link_name <<
'\n';
190 qfout <<
"xyz " << lcp.first.x <<
' ' << lcp.first.y <<
' ' << lcp.first.z <<
'\n';
191 Eigen::Quaterniond orientation(lcp.second.w, lcp.second.x, lcp.second.y, lcp.second.z);
192 Eigen::Vector3d rpy = orientation.matrix().eulerAngles(0, 1, 2);
193 qfout <<
"rpy " << rpy[0] <<
' ' << rpy[1] <<
' ' << rpy[2] <<
'\n';
195 qfout <<
'.' <<
'\n';
203 RCLCPP_INFO(node->get_logger(),
"Done.");
void collectLinkConstraints(const moveit_msgs::msg::Constraints &constraints, LinkConstraintMap &lcmap, const rclcpp::Logger &logger)
std::map< std::string, LinkConstraintPair > LinkConstraintMap
int main(int argc, char **argv)
std::pair< geometry_msgs::msg::Point, geometry_msgs::msg::Quaternion > LinkConstraintPair