40 #include <boost/program_options/cmdline.hpp>
41 #include <boost/program_options/options_description.hpp>
42 #include <boost/program_options/parsers.hpp>
43 #include <boost/program_options/variables_map.hpp>
46 #include <rclcpp/executors.hpp>
47 #include <rclcpp/logger.hpp>
48 #include <rclcpp/logging.hpp>
49 #include <rclcpp/node.hpp>
50 #include <rclcpp/node_options.hpp>
51 #include <rclcpp/utilities.hpp>
54 static const std::string ROBOT_DESCRIPTION =
"robot_description";
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());
84 int 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);
193 qfout <<
"rpy " << rpy[0] <<
' ' << rpy[1] <<
' ' << rpy[2] <<
'\n';
195 qfout <<
'.' <<
'\n';
203 RCLCPP_INFO(node->get_logger(),
"Done.");
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void printStateInfo(std::ostream &out=std::cout) const
bool getConstraints(ConstraintsWithMetadata &msg_m, const std::string &name, const std::string &robot="", const std::string &group="") const
Get the constraints named name. Return false on failure.
void getKnownConstraints(std::vector< std::string > &names, const std::string &robot="", const std::string &group="") const
void getPlanningSceneNames(std::vector< std::string > &names) const
bool getPlanningScene(PlanningSceneWithMetadata &scene_m, const std::string &scene_name) const
Get the latest planning scene named scene_name.
void getKnownRobotStates(std::vector< std::string > &names, const std::string &robot="") const
bool getRobotState(RobotStateWithMetadata &msg_m, const std::string &name, const std::string &robot="") const
Get the constraints named name. Return false on failure.
PlanningSceneMonitor Subscribes to the topic planning_scene.
const planning_scene::PlanningScenePtr & getPlanningScene()
Avoid this function! Returns an unsafe pointer to the current planning scene.
const moveit::core::RobotModelConstPtr & getRobotModel() const
Vec3fX< details::Vec3Data< double > > Vector3d
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::msg::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
Convert a robot state msg (with accompanying extra transforms) to a MoveIt robot state.
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotState >::ConstPtr RobotStateWithMetadata
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::PlanningScene >::ConstPtr PlanningSceneWithMetadata
warehouse_ros::DatabaseConnection::Ptr loadDatabase(const rclcpp::Node::SharedPtr &node)
Load a database connection.
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::Constraints >::ConstPtr ConstraintsWithMetadata
void setNodeLoggerName(const std::string &name)
Call once after creating a node to initialize logging namespaces.
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