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>
53 static const std::string ROBOT_DESCRIPTION =
"robot_description";
55 static const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"moveit.ros.warehouse.save_to_text");
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);
92 boost::program_options::options_description desc;
93 desc.add_options()(
"help",
"Show help message")(
"host", boost::program_options::value<std::string>(),
95 "DB.")(
"port", boost::program_options::value<std::size_t>(),
98 boost::program_options::variables_map vm;
99 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
100 boost::program_options::notify(vm);
102 if (vm.count(
"help"))
104 std::cout << desc <<
'\n';
109 if (vm.count(
"host") && vm.count(
"port"))
110 conn->setParams(vm[
"host"].as<std::string>(), vm[
"port"].as<std::size_t>());
111 if (!conn->connect())
120 std::vector<std::string> scene_names;
123 for (
const std::string& scene_name : scene_names)
128 RCLCPP_INFO(LOGGER,
"Saving scene '%s'", scene_name.c_str());
129 psm.
getPlanningScene()->setPlanningSceneMsg(
static_cast<const moveit_msgs::msg::PlanningScene&
>(*pswm));
130 std::ofstream fout((scene_name +
".scene").c_str());
134 std::vector<std::string> robot_state_names;
137 std::stringstream rsregex;
138 rsregex <<
".*" << scene_name <<
".*";
142 std::vector<std::string> constraint_names;
144 std::stringstream csregex;
145 csregex <<
".*" << scene_name <<
".*";
148 if (!(robot_state_names.empty() && constraint_names.empty()))
150 std::ofstream qfout((scene_name +
".queries").c_str());
151 qfout << scene_name <<
'\n';
152 if (!robot_state_names.empty())
154 qfout <<
"start" <<
'\n';
155 qfout << robot_state_names.size() <<
'\n';
156 for (
const std::string& robot_state_name : robot_state_names)
158 RCLCPP_INFO(LOGGER,
"Saving start state %s for scene %s", robot_state_name.c_str(), scene_name.c_str());
159 qfout << robot_state_name <<
'\n';
165 qfout <<
"." <<
'\n';
169 if (!constraint_names.empty())
171 qfout <<
"goal" <<
'\n';
172 qfout << constraint_names.size() <<
'\n';
173 for (
const std::string& constraint_name : constraint_names)
175 RCLCPP_INFO(LOGGER,
"Saving goal %s for scene %s", constraint_name.c_str(), scene_name.c_str());
176 qfout <<
"link_constraint" <<
'\n';
177 qfout << constraint_name <<
'\n';
183 for (std::pair<const std::string, LinkConstraintPair>& iter : lcmap)
185 std::string link_name = iter.first;
187 qfout << link_name <<
'\n';
188 qfout <<
"xyz " << lcp.first.x <<
" " << lcp.first.y <<
" " << lcp.first.z <<
'\n';
189 Eigen::Quaterniond orientation(lcp.second.w, lcp.second.x, lcp.second.y, lcp.second.z);
191 qfout <<
"rpy " << rpy[0] <<
" " << rpy[1] <<
" " << rpy[2] <<
'\n';
193 qfout <<
"." <<
'\n';
201 RCLCPP_INFO(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
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
void collectLinkConstraints(const moveit_msgs::msg::Constraints &constraints, LinkConstraintMap &lcmap)