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>
44 #include <rclcpp/executors/static_single_threaded_executor.hpp>
45 #include <rclcpp/logger.hpp>
46 #include <rclcpp/logging.hpp>
47 #include <rclcpp/node.hpp>
48 #include <rclcpp/node_options.hpp>
49 #include <rclcpp/publisher.hpp>
50 #include <rclcpp/qos_event.hpp>
51 #include <rclcpp/rate.hpp>
52 #include <rclcpp/utilities.hpp>
54 static const std::string PLANNING_SCENE_TOPIC =
"planning_scene";
55 static const std::string PLANNING_REQUEST_TOPIC =
"motion_plan_request";
56 static const std::string PLANNING_RESULTS_TOPIC =
"motion_plan_results";
58 static const std::string CONSTRAINTS_TOPIC =
"constraints";
60 static const std::string STATES_TOPIC =
"robot_states";
62 using namespace std::chrono_literals;
64 int main(
int argc,
char** argv)
66 rclcpp::init(argc, argv);
67 rclcpp::NodeOptions node_options;
68 node_options.allow_undeclared_parameters(
true);
69 node_options.automatically_declare_parameters_from_overrides(
true);
70 rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared(
"publish_warehouse_data", node_options);
71 const auto logger = node->get_logger();
77 boost::program_options::options_description desc;
78 desc.add_options()(
"help",
"Show help message")(
"host", boost::program_options::value<std::string>(),
80 "DB.")(
"port", boost::program_options::value<std::size_t>(),
82 "scene", boost::program_options::value<std::string>(),
"Name of scene to publish.")(
83 "planning_requests",
"Also publish the planning requests that correspond to the scene")(
84 "planning_results",
"Also publish the planning results that correspond to the scene")(
85 "constraint", boost::program_options::value<std::string>(),
"Name of constraint to publish.")(
86 "state", boost::program_options::value<std::string>(),
87 "Name of the robot state to publish.")(
"delay", boost::program_options::value<double>()->default_value(delay),
88 "Time to wait in between publishing messages (s)");
90 boost::program_options::variables_map vm;
91 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
92 boost::program_options::notify(vm);
94 if (vm.count(
"help") || (!vm.count(
"scene") && !vm.count(
"constraint") && !vm.count(
"state")))
96 std::cout << desc <<
'\n';
101 delay = vm[
"delay"].as<
double>();
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())
115 rclcpp::executors::StaticSingleThreadedExecutor executor;
116 executor.add_node(node);
118 rclcpp::Rate rate((int64_t)delay * 1000ms);
121 if (vm.count(
"scene"))
123 auto pub_scene = node->create_publisher<moveit_msgs::msg::PlanningScene>(PLANNING_SCENE_TOPIC, 10);
124 bool req = vm.count(
"planning_requests");
125 bool res = vm.count(
"planning_results");
128 executor.spin_once(0ns);
130 std::vector<std::string> scene_names;
133 for (
const std::string& scene_name : scene_names)
138 RCLCPP_INFO(logger,
"Publishing scene '%s'",
140 pub_scene->publish(
static_cast<const moveit_msgs::msg::PlanningScene&
>(*pswm));
141 executor.spin_once(0ns);
147 auto pub_res = node->create_publisher<moveit_msgs::msg::RobotTrajectory>(PLANNING_RESULTS_TOPIC, 100);
148 std::vector<moveit_warehouse::MotionPlanRequestWithMetadata> planning_queries;
149 std::vector<std::string> query_names;
151 RCLCPP_INFO(logger,
"There are %d planning queries associated to the scene",
152 static_cast<int>(planning_queries.size()));
153 rclcpp::sleep_for(500ms);
154 for (std::size_t i = 0; i < planning_queries.size(); ++i)
158 RCLCPP_INFO(logger,
"Publishing query '%s'", query_names[i].c_str());
160 executor.spin_once(0ns);
164 std::vector<moveit_warehouse::RobotTrajectoryWithMetadata> planning_results;
168 pub_res->publish(
static_cast<const moveit_msgs::msg::RobotTrajectory&
>(*planning_result));
169 executor.spin_once(0ns);
180 if (vm.count(
"constraint"))
183 auto pub_constr = node->create_publisher<moveit_msgs::msg::Constraints>(CONSTRAINTS_TOPIC, 100);
184 std::vector<std::string> cnames;
187 for (
const std::string& cname : cnames)
192 RCLCPP_INFO(logger,
"Publishing constraints '%s'",
194 pub_constr->publish(
static_cast<const moveit_msgs::msg::Constraints&
>(*cwm));
195 executor.spin_once(0ns);
202 if (vm.count(
"state"))
205 auto pub_state = node->create_publisher<moveit_msgs::msg::RobotState>(STATES_TOPIC, 100);
206 std::vector<std::string> rnames;
209 for (
const std::string& rname : rnames)
214 RCLCPP_INFO(logger,
"Publishing state '%s'",
216 pub_state->publish(
static_cast<const moveit_msgs::msg::RobotState&
>(*rswm));
217 executor.spin_once(0ns);
223 rclcpp::sleep_for(1s);
224 RCLCPP_INFO(logger,
"Done.");
int main(int argc, char **argv)
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
static const std::string CONSTRAINTS_ID_NAME
static const std::string PLANNING_SCENE_ID_NAME
void getPlanningResults(std::vector< RobotTrajectoryWithMetadata > &planning_results, const std::string &scene_name, const moveit_msgs::msg::MotionPlanRequest &planning_query) const
void getPlanningQueries(std::vector< MotionPlanRequestWithMetadata > &planning_queries, const std::string &scene_name) 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.
static const std::string STATE_NAME
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotState >::ConstPtr RobotStateWithMetadata
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotTrajectory >::ConstPtr RobotTrajectoryWithMetadata
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
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest