43 #include <tf2_eigen/tf2_eigen.hpp>
44 #include <boost/program_options/cmdline.hpp>
45 #include <boost/program_options/options_description.hpp>
46 #include <boost/program_options/parsers.hpp>
47 #include <boost/program_options/variables_map.hpp>
50 static const std::string ROBOT_DESCRIPTION =
"robot_description";
62 if (in.good() && !in.eof())
64 for (
int i = 0; i < count; ++i)
66 std::map<std::string, double> v;
69 if (in.good() && !in.eof())
75 while (joint !=
"." && in.good() && !in.eof())
95 moveit_msgs::msg::RobotState msg;
97 RCLCPP_INFO(
getLogger(),
"Parsed start state '%s'",
name.c_str());
107 Eigen::Translation3d pos(Eigen::Vector3d::Zero());
108 Eigen::Quaterniond rot(Eigen::Quaterniond::Identity());
110 bool have_position =
false;
111 bool have_orientation =
false;
114 std::getline(in,
name);
117 std::string link_name;
118 std::getline(in, link_name);
123 while (type !=
"." && in.good() && !in.eof())
127 have_position =
true;
130 pos = Eigen::Translation3d(x, y, z);
132 else if (type ==
"rpy")
134 have_orientation =
true;
137 rot = Eigen::Quaterniond(Eigen::AngleAxisd(r, Eigen::Vector3d::UnitX()) *
138 Eigen::AngleAxisd(p, Eigen::Vector3d::UnitY()) *
139 Eigen::AngleAxisd(y, Eigen::Vector3d::UnitZ()));
142 RCLCPP_ERROR(
getLogger(),
"Unknown link constraint element: '%s'", type.c_str());
147 std::string end_link;
148 std::getline(in, end_link);
150 if (have_position && have_orientation)
152 geometry_msgs::msg::PoseStamped pose;
153 pose.pose = tf2::toMsg(pos * rot);
154 pose.header.frame_id = psm->
getRobotModel()->getModelFrame();
157 RCLCPP_INFO(
getLogger(),
"Parsed link constraint '%s'",
name.c_str());
169 std::string end_link;
170 std::getline(in, end_link);
172 if (in.good() && !in.eof())
174 for (
int i = 0; i < count; ++i)
177 std::getline(in, type);
179 if (in.good() && !in.eof())
181 if (type ==
"link_constraint")
187 RCLCPP_INFO(
getLogger(),
"Unknown goal type: '%s'", type.c_str());
197 std::string scene_name;
199 while (in.good() && !in.eof())
204 if (in.good() && !in.eof())
210 else if (type ==
"goal")
216 RCLCPP_ERROR(
getLogger(),
"Unknown query type: '%s'", type.c_str());
222 int main(
int argc,
char** argv)
224 rclcpp::init(argc, argv);
225 rclcpp::NodeOptions node_options;
226 node_options.allow_undeclared_parameters(
true);
227 node_options.automatically_declare_parameters_from_overrides(
true);
228 rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared(
"import_from_text_to_warehouse", node_options);
232 boost::program_options::options_description desc;
233 desc.add_options()(
"help",
"Show help message")(
"queries", boost::program_options::value<std::string>(),
234 "Name of file containing motion planning queries.")(
235 "scene", boost::program_options::value<std::string>(),
"Name of file containing motion planning scene.")(
236 "host", boost::program_options::value<std::string>(),
237 "Host for the DB.")(
"port", boost::program_options::value<std::size_t>(),
"Port for the DB.");
240 boost::program_options::variables_map vm;
241 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
242 boost::program_options::notify(vm);
244 if (vm.count(
"help") || argc == 1)
246 std::cout << desc <<
'\n';
251 if (vm.count(
"host") && vm.count(
"port"))
252 conn->setParams(vm[
"host"].as<std::string>(), vm[
"port"].as<std::size_t>());
253 if (!conn->connect())
259 RCLCPP_ERROR(node->get_logger(),
"Unable to initialize PlanningSceneMonitor");
267 if (vm.count(
"scene"))
269 std::ifstream fin(vm[
"scene"].as<std::string>().c_str());
272 moveit_msgs::msg::PlanningScene psmsg;
277 if (vm.count(
"queries"))
279 std::ifstream fin(vm[
"queries"].as<std::string>().c_str());
280 if (fin.good() && !fin.eof())
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void setVariablePositions(const double *position)
It is assumed positions is an array containing the new positions for all variables in this state....
void addConstraints(const moveit_msgs::msg::Constraints &msg, const std::string &robot="", const std::string &group="")
void addPlanningScene(const moveit_msgs::msg::PlanningScene &scene)
void addRobotState(const moveit_msgs::msg::RobotState &msg, const std::string &name, const std::string &robot="")
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
int main(int argc, char **argv)
void parseQueries(std::istream &in, planning_scene_monitor::PlanningSceneMonitor *psm, moveit_warehouse::RobotStateStorage *rs, moveit_warehouse::ConstraintsStorage *cs)
void parseGoal(std::istream &in, planning_scene_monitor::PlanningSceneMonitor *psm, moveit_warehouse::ConstraintsStorage *cs)
rclcpp::Logger getLogger()
void parseLinkConstraint(std::istream &in, planning_scene_monitor::PlanningSceneMonitor *psm, moveit_warehouse::ConstraintsStorage *cs)
void parseStart(std::istream &in, planning_scene_monitor::PlanningSceneMonitor *psm, moveit_warehouse::RobotStateStorage *rs)
moveit_msgs::msg::Constraints constructGoalConstraints(const moveit::core::RobotState &state, const moveit::core::JointModelGroup *jmg, double tolerance_below, double tolerance_above)
Generates a constraint message intended to be used as a goal constraint for a joint group....
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::msg::RobotState &robot_state, bool copy_attached_bodies=true)
Convert a MoveIt robot state to a robot state message.
warehouse_ros::DatabaseConnection::Ptr loadDatabase(const rclcpp::Node::SharedPtr &node)
Load a database connection.
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
void setNodeLoggerName(const std::string &name)
Call once after creating a node to initialize logging namespaces.