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>
49 static const std::string ROBOT_DESCRIPTION =
"robot_description";
51 static const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"moveit.ros.warehouse.planning_scene_storage");
58 if (in.good() && !in.eof())
60 for (
int i = 0; i < count; ++i)
62 std::map<std::string, double> v;
65 if (in.good() && !in.eof())
71 while (joint !=
"." && in.good() && !in.eof())
89 moveit_msgs::msg::RobotState msg;
91 RCLCPP_INFO(LOGGER,
"Parsed start state '%s'",
name.c_str());
101 Eigen::Translation3d pos(Eigen::Vector3d::Zero());
102 Eigen::Quaterniond rot(Eigen::Quaterniond::Identity());
104 bool have_position =
false;
105 bool have_orientation =
false;
108 std::getline(in,
name);
111 std::string link_name;
112 std::getline(in, link_name);
117 while (
type !=
"." && in.good() && !in.eof())
121 have_position =
true;
124 pos = Eigen::Translation3d(
x,
y,
z);
126 else if (
type ==
"rpy")
128 have_orientation =
true;
131 rot = Eigen::Quaterniond(Eigen::AngleAxisd(
r, Eigen::Vector3d::UnitX()) *
132 Eigen::AngleAxisd(
p, Eigen::Vector3d::UnitY()) *
133 Eigen::AngleAxisd(
y, Eigen::Vector3d::UnitZ()));
136 RCLCPP_ERROR(LOGGER,
"Unknown link constraint element: '%s'",
type.c_str());
141 std::string end_link;
142 std::getline(in, end_link);
144 if (have_position && have_orientation)
146 geometry_msgs::msg::PoseStamped pose;
147 pose.pose = tf2::toMsg(pos * rot);
148 pose.header.frame_id = psm->
getRobotModel()->getModelFrame();
151 RCLCPP_INFO(LOGGER,
"Parsed link constraint '%s'",
name.c_str());
163 std::string end_link;
164 std::getline(in, end_link);
166 if (in.good() && !in.eof())
168 for (
int i = 0; i < count; ++i)
171 std::getline(in,
type);
173 if (in.good() && !in.eof())
175 if (
type ==
"link_constraint")
178 RCLCPP_INFO(LOGGER,
"Unknown goal type: '%s'",
type.c_str());
187 std::string scene_name;
189 while (in.good() && !in.eof())
194 if (in.good() && !in.eof())
198 else if (
type ==
"goal")
201 RCLCPP_ERROR(LOGGER,
"Unknown query type: '%s'",
type.c_str());
206 int main(
int argc,
char** argv)
208 rclcpp::init(argc, argv);
209 rclcpp::NodeOptions node_options;
210 node_options.allow_undeclared_parameters(
true);
211 node_options.automatically_declare_parameters_from_overrides(
true);
212 rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared(
"import_from_text_to_warehouse", node_options);
215 boost::program_options::options_description desc;
216 desc.add_options()(
"help",
"Show help message")(
"queries", boost::program_options::value<std::string>(),
217 "Name of file containing motion planning queries.")(
218 "scene", boost::program_options::value<std::string>(),
"Name of file containing motion planning scene.")(
219 "host", boost::program_options::value<std::string>(),
220 "Host for the DB.")(
"port", boost::program_options::value<std::size_t>(),
"Port for the DB.");
223 boost::program_options::variables_map vm;
224 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
225 boost::program_options::notify(vm);
227 if (vm.count(
"help") || argc == 1)
229 std::cout << desc <<
'\n';
234 if (vm.count(
"host") && vm.count(
"port"))
235 conn->setParams(vm[
"host"].as<std::string>(), vm[
"port"].as<std::size_t>());
236 if (!conn->connect())
242 RCLCPP_ERROR(LOGGER,
"Unable to initialize PlanningSceneMonitor");
250 if (vm.count(
"scene"))
252 std::ifstream fin(vm[
"scene"].as<std::string>().c_str());
255 moveit_msgs::msg::PlanningScene psmsg;
260 if (vm.count(
"queries"))
262 std::ifstream fin(vm[
"queries"].as<std::string>().c_str());
263 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)
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.
const rclcpp::Logger LOGGER