@@ -82,6 +82,7 @@ class MoveBase
82
82
pcl::PointCloud<pcl::PointXYZI> navfn_;
83
83
pcl::octree::OctreePointCloudSearch<pcl::PointXYZI>::Ptr navfn_octree_ptr_;
84
84
ros::Timer controller_timer_;
85
+ double robot_radius_;
85
86
double goal_reached_threshold_;
86
87
double controller_frequency_;
87
88
double local_target_radius_;
@@ -96,7 +97,7 @@ class MoveBase
96
97
void onGoal (const geometry_msgs::PointStamped::ConstPtr& msg);
97
98
void onGoal (const geometry_msgs::PoseStamped::ConstPtr& msg);
98
99
int projectPositionToNavigationFunction (const geometry_msgs::Point& pos);
99
- void projectGoalPositionToNavigationFunction ();
100
+ bool projectGoalPositionToNavigationFunction ();
100
101
bool getRobotPose ();
101
102
double positionError ();
102
103
double orientationError ();
@@ -110,7 +111,8 @@ MoveBase::MoveBase()
110
111
: pnh_(" ~" ),
111
112
frame_id_(" /map" ),
112
113
robot_frame_id_(" /base_link" ),
113
- goal_reached_threshold_(0.2 ),
114
+ robot_radius_(0.2 ),
115
+ goal_reached_threshold_(0.5 ),
114
116
controller_frequency_(2.0 ),
115
117
local_target_radius_(0.4 ),
116
118
twist_linear_gain_(0.5 ),
@@ -119,6 +121,7 @@ MoveBase::MoveBase()
119
121
{
120
122
pnh_.param (" frame_id" , frame_id_, frame_id_);
121
123
pnh_.param (" robot_frame_id" , robot_frame_id_, robot_frame_id_);
124
+ pnh_.param (" robot_radius" , robot_radius_, robot_radius_);
122
125
pnh_.param (" goal_reached_threshold" , goal_reached_threshold_, goal_reached_threshold_);
123
126
pnh_.param (" controller_frequency" , controller_frequency_, controller_frequency_);
124
127
pnh_.param (" local_target_radius" , local_target_radius_, local_target_radius_);
@@ -175,11 +178,14 @@ void MoveBase::onGoal(const geometry_msgs::PointStamped::ConstPtr& msg)
175
178
goal_.pose .orientation .y = 0.0 ;
176
179
goal_.pose .orientation .z = 0.0 ;
177
180
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 );
181
181
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
+ }
183
189
}
184
190
catch (tf::TransformException& ex)
185
191
{
@@ -193,13 +199,16 @@ void MoveBase::onGoal(const geometry_msgs::PoseStamped::ConstPtr& msg)
193
199
try
194
200
{
195
201
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 );
201
209
202
- startController ();
210
+ startController ();
211
+ }
203
212
}
204
213
catch (tf::TransformException& ex)
205
214
{
@@ -224,17 +233,23 @@ int MoveBase::projectPositionToNavigationFunction(const geometry_msgs::Point& po
224
233
}
225
234
226
235
227
- void MoveBase::projectGoalPositionToNavigationFunction ()
236
+ bool MoveBase::projectGoalPositionToNavigationFunction ()
228
237
{
229
238
int goal_index = projectPositionToNavigationFunction (goal_.pose .position );
230
239
if (goal_index == -1 )
231
240
{
232
241
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 ;
234
248
}
235
249
goal_.pose .position .x = navfn_[goal_index].x ;
236
250
goal_.pose .position .y = navfn_[goal_index].y ;
237
251
goal_.pose .position .z = navfn_[goal_index].z ;
252
+ return true ;
238
253
}
239
254
240
255
0 commit comments