Skip to content

Commit 29a1117

Browse files
committed
check goal distance from ground when reprojecting
1 parent 21d0ef0 commit 29a1117

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/move_base_node.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class MoveBase
8282
pcl::PointCloud<pcl::PointXYZI> navfn_;
8383
pcl::octree::OctreePointCloudSearch<pcl::PointXYZI>::Ptr navfn_octree_ptr_;
8484
ros::Timer controller_timer_;
85+
double robot_radius_;
8586
double goal_reached_threshold_;
8687
double controller_frequency_;
8788
double local_target_radius_;
@@ -96,7 +97,7 @@ class MoveBase
9697
void onGoal(const geometry_msgs::PointStamped::ConstPtr& msg);
9798
void onGoal(const geometry_msgs::PoseStamped::ConstPtr& msg);
9899
int projectPositionToNavigationFunction(const geometry_msgs::Point& pos);
99-
void projectGoalPositionToNavigationFunction();
100+
bool projectGoalPositionToNavigationFunction();
100101
bool getRobotPose();
101102
double positionError();
102103
double orientationError();
@@ -110,7 +111,8 @@ MoveBase::MoveBase()
110111
: pnh_("~"),
111112
frame_id_("/map"),
112113
robot_frame_id_("/base_link"),
113-
goal_reached_threshold_(0.2),
114+
robot_radius_(0.2),
115+
goal_reached_threshold_(0.5),
114116
controller_frequency_(2.0),
115117
local_target_radius_(0.4),
116118
twist_linear_gain_(0.5),
@@ -119,6 +121,7 @@ MoveBase::MoveBase()
119121
{
120122
pnh_.param("frame_id", frame_id_, frame_id_);
121123
pnh_.param("robot_frame_id", robot_frame_id_, robot_frame_id_);
124+
pnh_.param("robot_radius", robot_radius_, robot_radius_);
122125
pnh_.param("goal_reached_threshold", goal_reached_threshold_, goal_reached_threshold_);
123126
pnh_.param("controller_frequency", controller_frequency_, controller_frequency_);
124127
pnh_.param("local_target_radius", local_target_radius_, local_target_radius_);
@@ -175,11 +178,14 @@ void MoveBase::onGoal(const geometry_msgs::PointStamped::ConstPtr& msg)
175178
goal_.pose.orientation.y = 0.0;
176179
goal_.pose.orientation.z = 0.0;
177180
goal_.pose.orientation.w = 0.0;
178-
projectGoalPositionToNavigationFunction();
179-
ROS_INFO("goal set to point (%f, %f, %f)",
180-
goal_.pose.position.x, goal_.pose.position.y, goal_.pose.position.z);
181181

182-
startController();
182+
if(projectGoalPositionToNavigationFunction())
183+
{
184+
ROS_INFO("goal set to point (%f, %f, %f)",
185+
goal_.pose.position.x, goal_.pose.position.y, goal_.pose.position.z);
186+
187+
startController();
188+
}
183189
}
184190
catch(tf::TransformException& ex)
185191
{
@@ -193,13 +199,16 @@ void MoveBase::onGoal(const geometry_msgs::PoseStamped::ConstPtr& msg)
193199
try
194200
{
195201
tf_listener_.transformPose(frame_id_, *msg, goal_);
196-
projectGoalPositionToNavigationFunction();
197-
ROS_INFO("goal set to pose (%f, %f, %f), (%f, %f, %f, %f)",
198-
goal_.pose.position.x, goal_.pose.position.y, goal_.pose.position.z,
199-
goal_.pose.orientation.x, goal_.pose.orientation.y, goal_.pose.orientation.z,
200-
goal_.pose.orientation.w);
202+
203+
if(projectGoalPositionToNavigationFunction())
204+
{
205+
ROS_INFO("goal set to pose (%f, %f, %f), (%f, %f, %f, %f)",
206+
goal_.pose.position.x, goal_.pose.position.y, goal_.pose.position.z,
207+
goal_.pose.orientation.x, goal_.pose.orientation.y, goal_.pose.orientation.z,
208+
goal_.pose.orientation.w);
201209

202-
startController();
210+
startController();
211+
}
203212
}
204213
catch(tf::TransformException& ex)
205214
{
@@ -224,17 +233,23 @@ int MoveBase::projectPositionToNavigationFunction(const geometry_msgs::Point& po
224233
}
225234

226235

227-
void MoveBase::projectGoalPositionToNavigationFunction()
236+
bool MoveBase::projectGoalPositionToNavigationFunction()
228237
{
229238
int goal_index = projectPositionToNavigationFunction(goal_.pose.position);
230239
if(goal_index == -1)
231240
{
232241
ROS_ERROR("Failed to project goal position to navfn pcl");
233-
return;
242+
return false;
243+
}
244+
if(dist(goal_.pose.position, navfn_[goal_index]) > robot_radius_)
245+
{
246+
ROS_ERROR("Failed to project goal position to navfn pcl (point is too far from ground)");
247+
return false;
234248
}
235249
goal_.pose.position.x = navfn_[goal_index].x;
236250
goal_.pose.position.y = navfn_[goal_index].y;
237251
goal_.pose.position.z = navfn_[goal_index].z;
252+
return true;
238253
}
239254

240255

0 commit comments

Comments
 (0)