41 : size_x_(0), size_y_(0)
46 : size_x_(size_x), size_y_(size_y)
64 for(
unsigned int i = 0; i <
size_y_; ++i){
65 for(
unsigned int j = 0; j <
size_x_; ++j){
66 unsigned int id =
size_x_ * i + j;
85 if(
map_.size() != size_x * size_y)
86 map_.resize(size_x * size_y);
92 for(
unsigned int i = 0; i <
size_y_; ++i){
93 for(
unsigned int j = 0; j <
size_x_; ++j){
107 unsigned char cost = costmap.
getCost(check_cell->
cx, check_cell->
cy);
115 double new_target_dist = current_cell->
target_dist + 1;
116 if (new_target_dist < check_cell->target_dist) {
125 for(
unsigned int i = 0; i <
map_.size(); ++i) {
127 map_[i].target_mark =
false;
128 map_[i].within_robot =
false;
134 if (global_plan_in.
size() == 0) {
137 double last_x = global_plan_in[0].pose.position.x;
138 double last_y = global_plan_in[0].pose.position.y;
139 global_plan_out.
push_back(global_plan_in[0]);
141 double min_sq_resolution = resolution * resolution;
143 for (
unsigned int i = 1; i < global_plan_in.
size(); ++i) {
144 double loop_x = global_plan_in[i].pose.position.x;
145 double loop_y = global_plan_in[i].pose.position.y;
146 double sqdist = (loop_x - last_x) * (loop_x - last_x) + (loop_y - last_y) * (loop_y - last_y);
147 if (sqdist > min_sq_resolution) {
148 int steps =
ceil((
sqrt(sqdist)) / resolution);
150 double deltax = (loop_x - last_x) / steps;
151 double deltay = (loop_y - last_y) / steps;
153 for (
int j = 1; j < steps; ++j) {
154 geometry_msgs::PoseStamped pose;
155 pose.pose.position.x = last_x + j * deltax;
156 pose.pose.position.y = last_y + j * deltay;
157 pose.pose.position.z = global_plan_in[i].pose.position.z;
158 pose.pose.orientation = global_plan_in[i].pose.orientation;
159 pose.header = global_plan_in[i].header;
163 global_plan_out.
push_back(global_plan_in[i]);
174 bool started_path =
false;
180 if (adjusted_global_plan.
size() != global_plan.
size()) {
181 ROS_DEBUG(
"Adjusted global plan resolution, added %zu points", adjusted_global_plan.
size() - global_plan.
size());
185 for (i = 0; i < adjusted_global_plan.
size(); ++i) {
186 double g_x = adjusted_global_plan[i].pose.position.x;
187 double g_y = adjusted_global_plan[i].pose.position.y;
188 unsigned int map_x, map_y;
193 path_dist_queue.
push(¤t);
195 }
else if (started_path) {
200 ROS_ERROR(
"None of the %d first of %zu (%zu) points of the global plan were in the local costmap and free",
201 i, adjusted_global_plan.
size(), global_plan.
size());
213 int local_goal_x = -1;
214 int local_goal_y = -1;
215 bool started_path =
false;
221 for (
unsigned int i = 0; i < adjusted_global_plan.
size(); ++i) {
222 double g_x = adjusted_global_plan[i].pose.position.x;
223 double g_y = adjusted_global_plan[i].pose.position.y;
224 unsigned int map_x, map_y;
226 local_goal_x = map_x;
227 local_goal_y = map_y;
236 ROS_ERROR(
"None of the points of the global plan were in the local costmap, global plan points too far from robot");
241 if (local_goal_x >= 0 && local_goal_y >= 0) {
246 path_dist_queue.
push(¤t);
257 unsigned int last_col =
size_x_ - 1;
258 unsigned int last_row =
size_y_ - 1;
259 while(!dist_queue.
empty()){
260 current_cell = dist_queue.
front();
265 if(current_cell->
cx > 0){
266 check_cell = current_cell - 1;
271 dist_queue.
push(check_cell);
276 if(current_cell->
cx < last_col){
277 check_cell = current_cell + 1;
281 dist_queue.
push(check_cell);
286 if(current_cell->
cy > 0){
287 check_cell = current_cell -
size_x_;
291 dist_queue.
push(check_cell);
296 if(current_cell->
cy < last_row){
297 check_cell = current_cell +
size_x_;
301 dist_queue.
push(check_cell);