SMACC2
Loading...
Searching...
No Matches
cl_nav2z::forward_local_planner::ForwardLocalPlanner Class Reference

#include <forward_local_planner.hpp>

Inheritance diagram for cl_nav2z::forward_local_planner::ForwardLocalPlanner:
Inheritance graph
Collaboration diagram for cl_nav2z::forward_local_planner::ForwardLocalPlanner:
Collaboration graph

Public Member Functions

 ForwardLocalPlanner ()
 
 ~ForwardLocalPlanner () override
 
void configure (const rclcpp_lifecycle::LifecycleNode::WeakPtr &parent, std::string name, const std::shared_ptr< tf2_ros::Buffer > tf, const std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros) override
 
void activate () override
 
void deactivate () override
 
void cleanup () override
 
void setPlan (const nav_msgs::msg::Path &path) override
 nav2_core setPlan - Sets the global plan
 
geometry_msgs::msg::TwistStamped computeVelocityCommands (const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::Twist &velocity, nav2_core::GoalChecker *goal_checker) override
 nav2_core computeVelocityCommands - calculates the best command given the current pose and velocity
 
bool isGoalReached ()
 
void setSpeedLimit (const double &speed_limit, const bool &percentage) override
 

Private Member Functions

void updateParameters ()
 
void publishGoalMarker (double x, double y, double phi)
 
void cleanMarkers ()
 
void generateTrajectory (const Eigen::Vector3f &pos, const Eigen::Vector3f &vel, float maxdist, float maxangle, float maxtime, float dt, std::vector< Eigen::Vector3f > &outtraj)
 
Eigen::Vector3f computeNewPositions (const Eigen::Vector3f &pos, const Eigen::Vector3f &vel, double dt)
 

Private Attributes

nav2_util::LifecycleNode::SharedPtr nh_
 
std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmapRos_
 
std::string name_
 
rclcpp_lifecycle::LifecyclePublisher< visualization_msgs::msg::MarkerArray >::SharedPtr goalMarkerPublisher_
 
double k_rho_ = 0.0
 
double k_alpha_ = 0.0
 
double k_betta_ = 0.0
 
bool goalReached_ = false
 
const double alpha_offset_ = 0
 
const double betta_offset_ = 0
 
meter carrot_distance_ = 0.0
 
double yaw_goal_tolerance_ = 0.0
 
double xy_goal_tolerance_ = 0.0
 
double max_angular_z_speed_ = 0.0
 
double max_linear_x_speed_ = 0.0
 
double transform_tolerance_
 
int currentPoseIndex_ = 0
 
std::vector< geometry_msgs::msg::PoseStamped > plan_
 
bool waiting_ = false
 
rclcpp::Duration waitingTimeout_
 
rclcpp::Time waitingStamp_
 
std::shared_ptr< tf2_ros::Buffer > tf_
 

Detailed Description

Definition at line 38 of file forward_local_planner.hpp.

Constructor & Destructor Documentation

◆ ForwardLocalPlanner()

cl_nav2z::forward_local_planner::ForwardLocalPlanner::ForwardLocalPlanner ( )

◆ ~ForwardLocalPlanner()

cl_nav2z::forward_local_planner::ForwardLocalPlanner::~ForwardLocalPlanner ( )
override

Definition at line 44 of file forward_local_planner.cpp.

44{}

Member Function Documentation

◆ activate()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::activate ( )
override

Definition at line 46 of file forward_local_planner.cpp.

47{
48 RCLCPP_DEBUG_STREAM(nh_->get_logger(), "activating controller ForwardLocalPlanner");
49 this->updateParameters();
50 this->goalMarkerPublisher_->on_activate();
51}
rclcpp_lifecycle::LifecyclePublisher< visualization_msgs::msg::MarkerArray >::SharedPtr goalMarkerPublisher_

References goalMarkerPublisher_, nh_, and updateParameters().

Here is the call graph for this function:

◆ cleanMarkers()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::cleanMarkers ( )
private

Definition at line 254 of file forward_local_planner.cpp.

255{
256 RCLCPP_INFO_STREAM(nh_->get_logger(), "[ForwardLocalPlanner] cleaning markers.");
257 visualization_msgs::msg::Marker marker;
258
259 marker.header.frame_id = costmapRos_->getGlobalFrameID();
260 marker.header.stamp = nh_->now();
261 marker.ns = "my_namespace2";
262 marker.id = 0;
263 marker.action = visualization_msgs::msg::Marker::DELETEALL;
264
265 visualization_msgs::msg::MarkerArray ma;
266 ma.markers.push_back(marker);
267
268 goalMarkerPublisher_->publish(ma);
269}
std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmapRos_

References costmapRos_, goalMarkerPublisher_, and nh_.

Referenced by cleanup(), and deactivate().

Here is the caller graph for this function:

◆ cleanup()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::cleanup ( )
override

◆ computeNewPositions()

Eigen::Vector3f cl_nav2z::forward_local_planner::ForwardLocalPlanner::computeNewPositions ( const Eigen::Vector3f & pos,
const Eigen::Vector3f & vel,
double dt )
private

Definition at line 198 of file forward_local_planner.cpp.

200{
201 Eigen::Vector3f new_pos = Eigen::Vector3f::Zero();
202 new_pos[0] = pos[0] + (static_cast<double>(vel[0]) * cos(pos[2]) +
203 static_cast<double>(vel[1]) * cos(M_PI_2 + pos[2])) *
204 dt;
205 new_pos[1] = pos[1] + (static_cast<double>(vel[0]) * sin(pos[2]) +
206 static_cast<double>(vel[1]) * sin(M_PI_2 + pos[2])) *
207 dt;
208 new_pos[2] = pos[2] + vel[2] * dt;
209 return new_pos;
210}

Referenced by generateTrajectory().

Here is the caller graph for this function:

◆ computeVelocityCommands()

geometry_msgs::msg::TwistStamped cl_nav2z::forward_local_planner::ForwardLocalPlanner::computeVelocityCommands ( const geometry_msgs::msg::PoseStamped & currentPose,
const geometry_msgs::msg::Twist & velocity,
nav2_core::GoalChecker * goal_checker )
override

nav2_core computeVelocityCommands - calculates the best command given the current pose and velocity

It is presumed that the global plan is already set.

This is mostly a wrapper for the protected computeVelocityCommands function which has additional debugging info.

Parameters
poseCurrent robot pose
velocityCurrent robot velocity
Returns
The best command for the robot to drive

computeVelocityCommands()

Definition at line 311 of file forward_local_planner.cpp.

314{
315 this->updateParameters();
316
317 if (this->plan_.size() > 0)
318 {
319 RCLCPP_INFO_STREAM(
320 nh_->get_logger(), "[ForwardLocalPlanner] Current pose frame id: "
321 << plan_.front().header.frame_id
322 << ", path pose frame id: " << currentPose.header.frame_id);
323
324 if (plan_.front().header.frame_id != currentPose.header.frame_id)
325 {
326 RCLCPP_ERROR_STREAM(nh_->get_logger(), "[ForwardLocalPlanner] Inconsistent frames");
327 }
328 }
329
330 // xy_goal_tolerance and yaw_goal_tolerance are just used for logging proposes and clamping the carrot
331 // goal distance (parameter safety)
332 if (xy_goal_tolerance_ == -1 || yaw_goal_tolerance_ == -1)
333 {
334 geometry_msgs::msg::Pose posetol;
335 geometry_msgs::msg::Twist twistol;
336 if (goal_checker->getTolerances(posetol, twistol))
337 {
338 xy_goal_tolerance_ = posetol.position.x;
339 yaw_goal_tolerance_ = tf2::getYaw(posetol.orientation);
340 //xy_goal_tolerance_ = posetol.position.x * 0.35; // WORKAROUND DIFFERENCE WITH NAV CONTROLLER GOAL CHECKER
341 //yaw_goal_tolerance_ = tf2::getYaw(posetol.orientation) * 0.35;
342 RCLCPP_INFO_STREAM(
343 nh_->get_logger(), "[ForwardLocalPlanner] xy_goal_tolerance_: " << xy_goal_tolerance_
344 << ", yaw_goal_tolerance_: "
346 }
347 else
348 {
349 RCLCPP_INFO_STREAM(
350 nh_->get_logger(), "[ForwardLocalPlanner] could not get tolerances from goal checker");
351 }
352 }
353
354 geometry_msgs::msg::TwistStamped cmd_vel;
355 goalReached_ = false;
356 RCLCPP_DEBUG(
357 nh_->get_logger(), "[ForwardLocalPlanner] ----- COMPUTE VELOCITY COMMAND LOCAL PLANNER ---");
358
359 bool ok = false;
360 while (!ok)
361 {
362 // iterate the point from the current position and ahead until reaching a new goal point in the path
363 while (!ok && currentPoseIndex_ < (int)plan_.size())
364 {
365 auto & pose = plan_[currentPoseIndex_];
366 const geometry_msgs::msg::Point & p = pose.pose.position;
367 tf2::Quaternion q;
368 tf2::fromMsg(pose.pose.orientation, q);
369
370 // take error from the current position to the path point
371 double dx = p.x - currentPose.pose.position.x;
372 double dy = p.y - currentPose.pose.position.y;
373 double dist = sqrt(dx * dx + dy * dy);
374
375 double pangle = tf2::getYaw(q);
376 double angle = tf2::getYaw(currentPose.pose.orientation);
377 double angular_error = angles::shortest_angular_distance(pangle, angle);
378
379 if (dist >= carrot_distance_ || fabs(angular_error) > 0.1)
380 {
381 // the target pose is enough different to be defined as a target
382 ok = true;
383 RCLCPP_DEBUG(
384 nh_->get_logger(),
385 "current index: %d, carrot goal percentaje: %lf, dist: %lf, maxdist: %lf, angle_error: "
386 "%lf",
388 angular_error);
389 }
390 else
391 {
393 }
394 }
395
396 RCLCPP_DEBUG_STREAM(
397 nh_->get_logger(), "[ForwardLocalPlanner] selected carrot pose index "
398 << currentPoseIndex_ << "/" << plan_.size());
399
400 if (currentPoseIndex_ >= (int)plan_.size())
401 {
402 // even the latest point is quite similar, then take the last since it is the final goal
403 cmd_vel.twist.linear.x = 0;
404 cmd_vel.twist.angular.z = 0;
405 // RCLCPP_INFO(nh_->get_logger(), "End Local planner");
406 ok = true;
407 currentPoseIndex_ = (int)plan_.size() - 1;
408 }
409 }
410
411 // RCLCPP_INFO(nh_->get_logger(), "pose control algorithm");
412
413 const geometry_msgs::msg::PoseStamped & finalgoalpose = plan_.back();
414 const geometry_msgs::msg::PoseStamped & carrot_goalpose = plan_[currentPoseIndex_];
415 const geometry_msgs::msg::Point & goalposition = carrot_goalpose.pose.position;
416
417 tf2::Quaternion carrotGoalQ;
418 tf2::fromMsg(carrot_goalpose.pose.orientation, carrotGoalQ);
419 // RCLCPP_INFO_STREAM(nh_->get_logger(), "Plan goal quaternion at "<< carrot_goalpose.pose.orientation);
420
421 // goal orientation (global frame)
422 double betta = tf2::getYaw(carrot_goalpose.pose.orientation) + betta_offset_;
423 double dx = goalposition.x - currentPose.pose.position.x;
424 double dy = goalposition.y - currentPose.pose.position.y;
425
426 // distance error to the targetpoint
427 double rho_error = sqrt(dx * dx + dy * dy);
428
429 tf2::Quaternion currentOrientation;
430 tf2::convert(currentPose.pose.orientation, currentOrientation);
431
432 // current angle
433 double theta = tf2::getYaw(currentOrientation);
434 double alpha = atan2(dy, dx);
435 alpha = alpha + alpha_offset_;
436
437 double alpha_error = angles::shortest_angular_distance(alpha, theta);
438 double betta_error = angles::shortest_angular_distance(betta, theta);
439
440 double vetta = 0;
441 double gamma = 0;
442
443 if (
444 rho_error >
445 xy_goal_tolerance_) // regular control rule, be careful, rho error is with the carrot not with the
446 // final goal (this is something to improve like the backwards planner)
447 {
448 vetta = k_rho_ * rho_error;
449 gamma = k_alpha_ * alpha_error;
450 }
451 else if (fabs(betta_error) >= yaw_goal_tolerance_) // pureSpining
452 {
453 vetta = 0;
454 gamma = k_betta_ * betta_error;
455 }
456 else // goal reached
457 {
458 RCLCPP_DEBUG(nh_->get_logger(), "GOAL REACHED");
459 vetta = 0;
460 gamma = 0;
461 goalReached_ = true;
462 }
463
464 // linear speed clamp
465 if (vetta > max_linear_x_speed_)
466 {
467 vetta = max_linear_x_speed_;
468 }
469 else if (vetta < -max_linear_x_speed_)
470 {
471 vetta = -max_linear_x_speed_;
472 }
473
474 // angular speed clamp
475 if (gamma > max_angular_z_speed_)
476 {
477 gamma = max_angular_z_speed_;
478 }
479 else if (gamma < -max_angular_z_speed_)
480 {
481 gamma = -max_angular_z_speed_;
482 }
483
484 cmd_vel.twist.linear.x = vetta;
485 cmd_vel.twist.angular.z = gamma;
486
487 publishGoalMarker(goalposition.x, goalposition.y, betta);
488
489 RCLCPP_DEBUG_STREAM(
490 nh_->get_logger(), "Forward local planner,"
491 << '\n'
492 << " theta: " << theta << '\n'
493 << " betta: " << betta << '\n'
494 << " err_x: " << dx << '\n'
495 << " err_y:" << dy << '\n'
496 << " rho_error:" << rho_error << '\n'
497 << " alpha_error:" << alpha_error << '\n'
498 << " betta_error:" << betta_error << '\n'
499 << " vetta:" << vetta << '\n'
500 << " gamma:" << gamma << '\n'
501 << " xy_goal_tolerance:" << xy_goal_tolerance_ << '\n'
502 << " yaw_goal_tolerance:" << yaw_goal_tolerance_ << '\n');
503
504 // integrate trajectory and check collision
505
506 assert(currentPose.header.frame_id == "odom" || currentPose.header.frame_id == "map");
507 auto global_pose = currentPose;
508
509 auto * costmap2d = costmapRos_->getCostmap();
510 auto yaw = tf2::getYaw(global_pose.pose.orientation);
511
512 auto & pos = global_pose.pose.position;
513
514 Eigen::Vector3f currentpose(pos.x, pos.y, yaw);
515 Eigen::Vector3f currentvel(
516 cmd_vel.twist.linear.x, cmd_vel.twist.linear.y, cmd_vel.twist.angular.z);
517
518 std::vector<Eigen::Vector3f> trajectory;
519 this->generateTrajectory(
520 currentpose, currentvel, 0.8 /*meters*/, M_PI / 8 /*rads*/, 3.0 /*seconds*/, 0.05 /*seconds*/,
521 trajectory);
522
523 // check plan rejection
524 bool aceptedplan = true;
525
526 unsigned int mx = 0, my = 0;
527
528 // RCLCPP_INFO_STREAM(nh_->get_logger(), "lplanner goal: " << finalgoalpose.pose.position);
529 for (auto & p : trajectory)
530 {
531 float goaldx = p[0] - finalgoalpose.pose.position.x;
532 float goaldy = p[1] - finalgoalpose.pose.position.y;
533
534 float dst = sqrt(goaldx * goaldx + goaldy * goaldy);
535 if (dst < xy_goal_tolerance_)
536 {
537 // RCLCPP_INFO(nh_->get_logger(), "trajectory checking skipped, goal reached");
538 break;
539 }
540
541 costmap2d->worldToMap(p[0], p[1], mx, my);
542
543 // RCLCPP_INFO(nh_->get_logger(), "checking cost pt %d [%lf, %lf] cell[%d,%d] = %d", i, p[0], p[1], mx, my, cost);
544 // RCLCPP_INFO_STREAM(nh_->get_logger(), "cost: " << cost);
545
546 // Costmap values: 255 no information, 254 lethal obstacle, 253 inscribed inflated obstacle, 0 free space.
547 if (costmap2d->getCost(mx, my) >= nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
548 {
549 aceptedplan = false;
550 // RCLCPP_WARN(nh_->get_logger(), "ABORTED LOCAL PLAN BECAUSE OBSTACLE DETEDTED");
551 break;
552 }
553 }
554
555 bool success = false;
556 if (aceptedplan)
557 {
558 waiting_ = false;
559 success = true;
560 RCLCPP_DEBUG(nh_->get_logger(), "simulated trajectory is accepted.");
561 }
562 else
563 {
564 RCLCPP_DEBUG(nh_->get_logger(), "simulated trajectory is not accepted. Stop command.");
565
566 // stop and wait
567 cmd_vel.twist.linear.x = 0;
568 cmd_vel.twist.angular.z = 0;
569
570 if (!waiting_)
571 {
572 RCLCPP_DEBUG(nh_->get_logger(), "Start waiting obstacle disappear");
573 waiting_ = true;
574 waitingStamp_ = nh_->now();
575 }
576 else
577 {
578 auto waitingduration = nh_->now() - waitingStamp_;
579 RCLCPP_DEBUG(
580 nh_->get_logger(), "waiting obstacle disappear, elapsed: %lf seconds",
581 waitingduration.seconds());
582
583 if (waitingduration > this->waitingTimeout_)
584 {
585 RCLCPP_WARN(
586 nh_->get_logger(), "TIMEOUT waiting obstacle disappear, elapsed: %lf seconds",
587 waitingduration.seconds());
588 success = false;
589 }
590 }
591 }
592
593 if (!success)
594 {
595 RCLCPP_DEBUG(
596 nh_->get_logger(),
597 "[ForwardLocalPlanner] object detected waiting stopped until it disappears.");
598 }
599
600 cmd_vel.header.stamp = nh_->now();
601 return cmd_vel;
602}
void generateTrajectory(const Eigen::Vector3f &pos, const Eigen::Vector3f &vel, float maxdist, float maxangle, float maxtime, float dt, std::vector< Eigen::Vector3f > &outtraj)

References alpha_offset_, betta_offset_, carrot_distance_, costmapRos_, currentPoseIndex_, generateTrajectory(), goalReached_, k_alpha_, k_betta_, k_rho_, max_angular_z_speed_, max_linear_x_speed_, nh_, plan_, publishGoalMarker(), updateParameters(), waiting_, waitingStamp_, waitingTimeout_, xy_goal_tolerance_, and yaw_goal_tolerance_.

Here is the call graph for this function:

◆ configure()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::configure ( const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
std::string name,
const std::shared_ptr< tf2_ros::Buffer > tf,
const std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros )
override

Definition at line 68 of file forward_local_planner.cpp.

72{
73 nh_ = node.lock();
74 costmapRos_ = costmap_ros;
75 tf_ = tf;
76 name_ = name;
77 k_rho_ = 1.0;
78 k_alpha_ = -0.4;
79 k_betta_ = -1.0; // set to zero means that orientation is not important
80
81 goalReached_ = false;
82 carrot_distance_ = 0.4;
87
89
90 declareOrSet(nh_, name_ + ".k_rho", k_rho_);
91 declareOrSet(nh_, name_ + ".k_alpha", k_alpha_);
92 declareOrSet(nh_, name_ + ".k_betta", k_betta_);
93 declareOrSet(nh_, name_ + ".carrot_distance", carrot_distance_);
94 declareOrSet(nh_, name_ + ".yaw_goal_tolerance", yaw_goal_tolerance_);
95 declareOrSet(nh_, name_ + ".xy_goal_tolerance", xy_goal_tolerance_);
96 declareOrSet(nh_, name_ + ".max_linear_x_speed", max_linear_x_speed_);
97 declareOrSet(nh_, name_ + ".max_angular_z_speed", max_angular_z_speed_);
98 declareOrSet(nh_, name_ + ".transform_tolerance", transform_tolerance_);
99
100 RCLCPP_DEBUG(
101 nh_->get_logger(),
102 "[ForwardLocalPlanner] max linear speed: %lf, max angular speed: %lf, k_rho: %lf, "
103 "carrot_distance: "
104 "%lf, ",
106 goalMarkerPublisher_ = nh_->create_publisher<visualization_msgs::msg::MarkerArray>(
107 "forward_local_planner/carrot_goal_marker", rclcpp::QoS(1));
108
109 waiting_ = false;
110 waitingTimeout_ = rclcpp::Duration(10s);
111}
void declareOrSet(rclcpp_lifecycle::LifecycleNode::SharedPtr &node, std::string param, T &value)
Definition common.hpp:34

References carrot_distance_, costmapRos_, currentPoseIndex_, declareOrSet(), goalMarkerPublisher_, goalReached_, k_alpha_, k_betta_, k_rho_, max_angular_z_speed_, max_linear_x_speed_, name_, nh_, tf_, transform_tolerance_, waiting_, waitingTimeout_, xy_goal_tolerance_, and yaw_goal_tolerance_.

Here is the call graph for this function:

◆ deactivate()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::deactivate ( )
override

Definition at line 53 of file forward_local_planner.cpp.

54{
55 this->cleanMarkers();
56 this->goalMarkerPublisher_->on_deactivate();
57}

References cleanMarkers(), and goalMarkerPublisher_.

Here is the call graph for this function:

◆ generateTrajectory()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::generateTrajectory ( const Eigen::Vector3f & pos,
const Eigen::Vector3f & vel,
float maxdist,
float maxangle,
float maxtime,
float dt,
std::vector< Eigen::Vector3f > & outtraj )
private

Definition at line 142 of file forward_local_planner.cpp.

145{
146 // simulate the trajectory and check for collisions, updating costs along the way
147 bool end = false;
148 float time = 0;
149 Eigen::Vector3f currentpos = pos;
150 while (!end)
151 {
152 // add the point to the trajectory so we can draw it later if we want
153 // traj.addPoint(pos[0], pos[1], pos[2]);
154
155 auto loop_vel = vel;
156 // update the position of the robot using the velocities passed in
157 auto newpos = computeNewPositions(currentpos, loop_vel, dt);
158
159 auto dx = newpos[0] - currentpos[0];
160 auto dy = newpos[1] - currentpos[1];
161 float dist = 0.0;
162
163 // RCLCPP_DEBUG(nh_->get_logger(), "traj point %d", i);
164 dist = sqrt(dx * dx + dy * dy);
165 if (dist > maxdist)
166 {
167 end = true;
168 // RCLCPP_DEBUG(nh_->get_logger(), "dist break: %f", dist);
169 }
170 else
171 {
172 // ouble from, double to
173 float angledist = fabs(angles::shortest_angular_distance(currentpos[2], newpos[2]));
174 if (angledist > maxanglediff)
175 {
176 end = true;
177 // RCLCPP_DEBUG(nh_->get_logger(), "angle dist break: %f", angledist);
178 }
179 else
180 {
181 outtraj.push_back(newpos);
182
183 time += dt;
184 if (time > maxtime)
185 {
186 end = true;
187 // RCLCPP_DEBUG(nh_->get_logger(), "time break: %f", time);
188 }
189
190 // RCLCPP_DEBUG(nh_->get_logger(), "dist: %f, angledist: %f, time: %f", dist, angledist, time);
191 }
192 }
193
194 currentpos = newpos;
195 } // end for simulation steps
196}
Eigen::Vector3f computeNewPositions(const Eigen::Vector3f &pos, const Eigen::Vector3f &vel, double dt)

References computeNewPositions().

Referenced by computeVelocityCommands().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isGoalReached()

bool cl_nav2z::forward_local_planner::ForwardLocalPlanner::isGoalReached ( )

isGoalReached()

Definition at line 617 of file forward_local_planner.cpp.

617{ return goalReached_; }

References goalReached_.

◆ publishGoalMarker()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::publishGoalMarker ( double x,
double y,
double phi )
private

publishGoalMarker()

Definition at line 217 of file forward_local_planner.cpp.

218{
219 visualization_msgs::msg::Marker marker;
220
221 marker.header.frame_id = costmapRos_->getGlobalFrameID();
222 marker.header.stamp = nh_->now();
223 marker.ns = "my_namespace2";
224 marker.id = 0;
225 marker.type = visualization_msgs::msg::Marker::ARROW;
226 marker.action = visualization_msgs::msg::Marker::ADD;
227 marker.pose.orientation.w = 1;
228 marker.lifetime = rclcpp::Duration(1.0s);
229
230 marker.scale.x = 0.1;
231 marker.scale.y = 0.3;
232 marker.scale.z = 0.1;
233 marker.color.a = 1.0;
234 marker.color.r = 0;
235 marker.color.g = 0;
236 marker.color.b = 1.0;
237
238 geometry_msgs::msg::Point start, end;
239 start.x = x;
240 start.y = y;
241
242 end.x = x + 0.5 * cos(phi);
243 end.y = y + 0.5 * sin(phi);
244
245 marker.points.push_back(start);
246 marker.points.push_back(end);
247
248 visualization_msgs::msg::MarkerArray ma;
249 ma.markers.push_back(marker);
250
251 goalMarkerPublisher_->publish(ma);
252}

References costmapRos_, goalMarkerPublisher_, and nh_.

Referenced by computeVelocityCommands().

Here is the caller graph for this function:

◆ setPlan()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::setPlan ( const nav_msgs::msg::Path & plan)
override

nav2_core setPlan - Sets the global plan

Parameters
pathThe global plan

setPlan()

Definition at line 624 of file forward_local_planner.cpp.

625{
626 nav_msgs::msg::Path transformedPlan;
627
628 rclcpp::Duration ttol = rclcpp::Duration::from_seconds(transform_tolerance_);
629 // transform global plan
630 for (auto & p : plan.poses)
631 {
632 geometry_msgs::msg::PoseStamped transformedPose;
633 nav_2d_utils::transformPose(tf_, costmapRos_->getGlobalFrameID(), p, transformedPose, ttol);
634 transformedPose.header.frame_id = costmapRos_->getGlobalFrameID();
635 transformedPlan.poses.push_back(transformedPose);
636 }
637
638 plan_ = transformedPlan.poses;
639 goalReached_ = false;
640}

References costmapRos_, goalReached_, plan_, tf_, and transform_tolerance_.

◆ setSpeedLimit()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::setSpeedLimit ( const double & speed_limit,
const bool & percentage )
override

Definition at line 604 of file forward_local_planner.cpp.

605{
606 RCLCPP_WARN_STREAM(
607 nh_->get_logger(),
608 "ForwardLocalPlanner::setSpeedLimit invoked. Ignored, functionality not "
609 "implemented.");
610}

References nh_.

◆ updateParameters()

void cl_nav2z::forward_local_planner::ForwardLocalPlanner::updateParameters ( )
private

Definition at line 113 of file forward_local_planner.cpp.

114{
115 nh_->get_parameter(name_ + ".k_rho", k_rho_);
116 nh_->get_parameter(name_ + ".k_alpha", k_alpha_);
117 nh_->get_parameter(name_ + ".k_betta", k_betta_);
118 nh_->get_parameter(name_ + ".carrot_distance", carrot_distance_);
119 nh_->get_parameter(name_ + ".yaw_goal_tolerance", yaw_goal_tolerance_);
120 nh_->get_parameter(name_ + ".xy_goal_tolerance", xy_goal_tolerance_);
121 nh_->get_parameter(name_ + ".max_linear_x_speed", max_linear_x_speed_);
122 nh_->get_parameter(name_ + ".max_angular_z_speed", max_angular_z_speed_);
123 nh_->get_parameter(name_ + ".transform_tolerance", transform_tolerance_);
124
125 RCLCPP_INFO_STREAM(nh_->get_logger(), "[ForwardLocalPlanner.k_rho: " << k_rho_);
126 RCLCPP_INFO_STREAM(nh_->get_logger(), "[ForwardLocalPlanner.k_alpha: " << k_alpha_);
127 RCLCPP_INFO_STREAM(nh_->get_logger(), "[ForwardLocalPlanner.k_betta: " << k_betta_);
128 RCLCPP_INFO_STREAM(
129 nh_->get_logger(), "[ForwardLocalPlanner.carrot_distance: " << carrot_distance_);
130 RCLCPP_INFO_STREAM(
131 nh_->get_logger(), "[ForwardLocalPlanner.yaw_goal_tolerance:" << yaw_goal_tolerance_);
132 RCLCPP_INFO_STREAM(
133 nh_->get_logger(), "[ForwardLocalPlanner.xy_goal_tolerance: " << xy_goal_tolerance_);
134 RCLCPP_INFO_STREAM(
135 nh_->get_logger(), "[ForwardLocalPlanner.max_linear_x_speed:" << max_linear_x_speed_);
136 RCLCPP_INFO_STREAM(
137 nh_->get_logger(), "[ForwardLocalPlanner.max_angular_z_speed:" << max_angular_z_speed_);
138 RCLCPP_INFO_STREAM(
139 nh_->get_logger(), "[ForwardLocalPlanner.transform_tolerance:" << transform_tolerance_);
140}

References carrot_distance_, k_alpha_, k_betta_, k_rho_, max_angular_z_speed_, max_linear_x_speed_, name_, nh_, transform_tolerance_, xy_goal_tolerance_, and yaw_goal_tolerance_.

Referenced by activate(), and computeVelocityCommands().

Here is the caller graph for this function:

Member Data Documentation

◆ alpha_offset_

const double cl_nav2z::forward_local_planner::ForwardLocalPlanner::alpha_offset_ = 0
private

Definition at line 105 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands().

◆ betta_offset_

const double cl_nav2z::forward_local_planner::ForwardLocalPlanner::betta_offset_ = 0
private

Definition at line 106 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands().

◆ carrot_distance_

meter cl_nav2z::forward_local_planner::ForwardLocalPlanner::carrot_distance_ = 0.0
private

Definition at line 108 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), configure(), and updateParameters().

◆ costmapRos_

std::shared_ptr<nav2_costmap_2d::Costmap2DROS> cl_nav2z::forward_local_planner::ForwardLocalPlanner::costmapRos_
private

◆ currentPoseIndex_

int cl_nav2z::forward_local_planner::ForwardLocalPlanner::currentPoseIndex_ = 0
private

Definition at line 118 of file forward_local_planner.hpp.

Referenced by cleanup(), computeVelocityCommands(), and configure().

◆ goalMarkerPublisher_

rclcpp_lifecycle::LifecyclePublisher<visualization_msgs::msg::MarkerArray>::SharedPtr cl_nav2z::forward_local_planner::ForwardLocalPlanner::goalMarkerPublisher_
private

◆ goalReached_

bool cl_nav2z::forward_local_planner::ForwardLocalPlanner::goalReached_ = false
private

◆ k_alpha_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::k_alpha_ = 0.0
private

Definition at line 101 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), configure(), and updateParameters().

◆ k_betta_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::k_betta_ = 0.0
private

Definition at line 102 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), configure(), and updateParameters().

◆ k_rho_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::k_rho_ = 0.0
private

Definition at line 100 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), configure(), and updateParameters().

◆ max_angular_z_speed_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::max_angular_z_speed_ = 0.0
private

Definition at line 113 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), configure(), and updateParameters().

◆ max_linear_x_speed_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::max_linear_x_speed_ = 0.0
private

Definition at line 114 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), configure(), and updateParameters().

◆ name_

std::string cl_nav2z::forward_local_planner::ForwardLocalPlanner::name_
private

Definition at line 95 of file forward_local_planner.hpp.

Referenced by configure(), and updateParameters().

◆ nh_

nav2_util::LifecycleNode::SharedPtr cl_nav2z::forward_local_planner::ForwardLocalPlanner::nh_
private

◆ plan_

std::vector<geometry_msgs::msg::PoseStamped> cl_nav2z::forward_local_planner::ForwardLocalPlanner::plan_
private

Definition at line 120 of file forward_local_planner.hpp.

Referenced by cleanup(), computeVelocityCommands(), and setPlan().

◆ tf_

std::shared_ptr<tf2_ros::Buffer> cl_nav2z::forward_local_planner::ForwardLocalPlanner::tf_
private

Definition at line 125 of file forward_local_planner.hpp.

Referenced by configure(), and setPlan().

◆ transform_tolerance_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::transform_tolerance_
private

Definition at line 115 of file forward_local_planner.hpp.

Referenced by configure(), setPlan(), and updateParameters().

◆ waiting_

bool cl_nav2z::forward_local_planner::ForwardLocalPlanner::waiting_ = false
private

Definition at line 122 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), and configure().

◆ waitingStamp_

rclcpp::Time cl_nav2z::forward_local_planner::ForwardLocalPlanner::waitingStamp_
private

Definition at line 124 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands().

◆ waitingTimeout_

rclcpp::Duration cl_nav2z::forward_local_planner::ForwardLocalPlanner::waitingTimeout_
private

Definition at line 123 of file forward_local_planner.hpp.

Referenced by computeVelocityCommands(), and configure().

◆ xy_goal_tolerance_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::xy_goal_tolerance_ = 0.0
private

◆ yaw_goal_tolerance_

double cl_nav2z::forward_local_planner::ForwardLocalPlanner::yaw_goal_tolerance_ = 0.0
private

The documentation for this class was generated from the following files: