6 #include <geometry_msgs/PolygonStamped.h> 7 #include <geometry_msgs/PointStamped.h> 11 #include <frontier_exploration/ExploreTaskAction.h> 12 #include <frontier_exploration/ExploreTaskActionGoal.h> 13 #include <frontier_exploration/GetNextFrontier.h> 14 #include <frontier_exploration/UpdateBoundaryPolygon.h> 20 #include <move_base_msgs/MoveBaseAction.h> 22 #include <visualization_msgs/Marker.h> 23 #include <boost/foreach.hpp> 41 geometry_msgs::PolygonStamped
input_;
50 visualization_msgs::Marker points, line_strip;
52 points.header = line_strip.header = input_.header;
53 points.ns = line_strip.ns =
"explore_points";
58 points.type = visualization_msgs::Marker::SPHERE_LIST;
59 line_strip.type = visualization_msgs::Marker::LINE_STRIP;
61 if(!input_.polygon.points.empty()){
63 points.action = line_strip.action = visualization_msgs::Marker::ADD;
64 points.pose.orientation.w = line_strip.pose.orientation.w = 1.0;
66 points.scale.x = points.scale.y = 0.1;
67 line_strip.scale.x = 0.05;
69 BOOST_FOREACH(geometry_msgs::Point32 point, input_.polygon.points){
74 if(waiting_for_center_){
76 points.color.a = points.color.r = line_strip.color.r = line_strip.color.a = 1.0;
78 points.color.a = points.color.b = line_strip.color.b = line_strip.color.a = 1.0;
81 points.action = line_strip.action = visualization_msgs::Marker::DELETE;
84 point_viz_pub_.
publish(line_strip);
92 void pointCb(
const geometry_msgs::PointStampedConstPtr& point){
94 double average_distance =
polygonPerimeter(input_.polygon) / input_.polygon.points.size();
96 if(waiting_for_center_){
100 ROS_ERROR(
"Center not inside polygon, restarting");
105 frontier_exploration::ExploreTaskGoal goal;
106 goal.explore_center = *point;
107 goal.explore_boundary =
input_;
110 waiting_for_center_ =
false;
111 input_.polygon.points.clear();
113 }
else if(input_.polygon.points.empty()){
116 input_.header = point->header;
119 }
else if(input_.header.frame_id != point->header.frame_id){
120 ROS_ERROR(
"Frame mismatch, restarting polygon selection");
121 input_.polygon.points.clear();
123 }
else if(input_.polygon.points.size() > 1 &&
pointsNearby(input_.polygon.points.front(), point->point,
124 average_distance*0.1)){
127 if(input_.polygon.points.size() < 3){
128 ROS_ERROR(
"Not a valid polygon, restarting");
129 input_.polygon.points.clear();
131 waiting_for_center_ =
true;
132 ROS_WARN(
"Please select an initial point for exploration inside the polygon");
152 waiting_for_center_(false)
154 input_.header.frame_id =
"map";
156 point_viz_pub_ = nh_.
advertise<visualization_msgs::Marker>(
"exploration_polygon_marker", 10);
158 ROS_INFO(
"Please use the 'Point' tool in Rviz to select an exporation boundary.");
165 int main(
int argc,
char** argv)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
void publish(const boost::shared_ptr< M > &message) const
geometry_msgs::Point32 toPoint32(geometry_msgs::Point pt)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool pointsNearby(const T &one, const S &two, const double &proximity)
Evaluate whether two points are approximately adjacent, within a specified proximity distance...
int main(int argc, char **argv)
FrontierExplorationClient()
Constructor for the client.
geometry_msgs::PolygonStamped input_
void vizPubCb()
Publish markers for visualization of points for boundary polygon.
ROSCPP_DECL void spin(Spinner &spinner)
double polygonPerimeter(const geometry_msgs::Polygon &polygon)
Calculate polygon perimeter.
ros::Publisher point_viz_pub_
WallTimer createWallTimer(WallDuration period, void(T::*callback)(const WallTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
ros::NodeHandle private_nh_
void pointCb(const geometry_msgs::PointStampedConstPtr &point)
Build boundary polygon from points received through rviz gui.
geometry_msgs::Point toPoint(geometry_msgs::Point32 pt)
bool pointInPolygon(const T &point, const geometry_msgs::Polygon &polygon)
Evaluate if point is inside area defined by polygon. Undefined behaviour for points on line...
Client for FrontierExplorationServer that receives control points from rviz, and creates boundary pol...
ros::WallTimer point_viz_timer_