SMACC2
Loading...
Searching...
No Matches
backward_local_planner.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20#pragma once
21#include <tf2/transform_datatypes.h>
22#include <tf2_ros/buffer.h>
23#include <geometry_msgs/msg/pose_stamped.hpp>
24#include <nav2_core/controller.hpp>
25#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
26#include <visualization_msgs/msg/marker_array.hpp>
27
28#include <tf2/utils.h>
29#include <eigen3/Eigen/Eigen>
30
31typedef double meter;
32typedef double rad;
33
34namespace cl_nav2z
35{
36namespace backward_local_planner
37{
38class BackwardLocalPlanner : public nav2_core::Controller
39{
40public:
42
43 virtual ~BackwardLocalPlanner();
44
45 void configure(
46 const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, std::string name,
47 const std::shared_ptr<tf2_ros::Buffer> tf,
48 const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) override;
49
50 void activate() override;
51
52 void deactivate() override;
53
54 void cleanup() override;
55
60 void setPlan(const nav_msgs::msg::Path & path) override;
61
74 virtual geometry_msgs::msg::TwistStamped computeVelocityCommands(
75 const geometry_msgs::msg::PoseStamped & pose, const geometry_msgs::msg::Twist & velocity,
76 nav2_core::GoalChecker * goal_checker) override;
77
78 /*deprecated in navigation2*/
79 bool isGoalReached();
80
81 virtual void setSpeedLimit(const double & speed_limit, const bool & percentage) override;
82
83private:
84 void updateParameters();
85
86 // returns true if found
87 bool findInitialCarrotGoal(geometry_msgs::msg::PoseStamped & pose);
88
89 // returns true for a pure spinning motion request
90 bool updateCarrotGoal(const geometry_msgs::msg::PoseStamped & pose);
91
93
95 const geometry_msgs::msg::PoseStamped & pose, double & vetta, double & gamma,
96 double alpha_error, double betta_error, double rho_error);
97
98 void clearMarkers();
99 void publishGoalMarker(double x, double y, double phi);
100
102 const geometry_msgs::msg::PoseStamped & pose, double & dist, double & angular_error);
103
105 const geometry_msgs::msg::PoseStamped & pose, double vetta, double gamma, double alpha_error,
106 geometry_msgs::msg::Twist & cmd_vel);
107
109 const geometry_msgs::msg::PoseStamped & tfpose, const geometry_msgs::msg::Twist & currentTwist,
110 double angle_error, bool & linearGoalReached, nav2_core::GoalChecker * goalChecker);
111
113
114 bool divergenceDetectionUpdate(const geometry_msgs::msg::PoseStamped & pose);
115
116 bool checkCarrotHalfPlainConstraint(const geometry_msgs::msg::PoseStamped & pose);
117
118 rclcpp_lifecycle::LifecycleNode::SharedPtr nh_;
119 std::string name_;
120
121 std::vector<geometry_msgs::msg::PoseStamped> backwardsPlanPath_;
122 std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmapRos_;
123 std::shared_ptr<tf2_ros::Buffer> tf_;
124
125 std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<visualization_msgs::msg::MarkerArray>>
127 std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> planPub_;
128
129 // --- control parameters ---
130 double k_rho_;
131 double k_alpha_;
132 double k_betta_;
135
136 const double alpha_offset_ = M_PI;
137 const double betta_offset_ = 0;
138
139 double max_linear_x_speed_; // meters/sec
140 double max_angular_z_speed_; // rads/sec
141
142 double yaw_goal_tolerance_; // radians
143 double xy_goal_tolerance_; // meters
144
148
150
151 rclcpp::Duration waitingTimeout_;
152 rclcpp::Time waitingStamp_;
153
154 // --- controller state ---
161
162 // references the current point inside the backwardsPlanPath were the robot is located
164
166 const Eigen::Vector3f & pos, const Eigen::Vector3f & vel, float maxdist, float maxangle,
167 float maxtime, float dt, std::vector<Eigen::Vector3f> & outtraj);
168
169 Eigen::Vector3f computeNewPositions(
170 const Eigen::Vector3f & pos, const Eigen::Vector3f & vel, double dt);
171};
172} // namespace backward_local_planner
173} // namespace cl_nav2z
double meter
bool updateCarrotGoal(const geometry_msgs::msg::PoseStamped &pose)
bool checkCarrotHalfPlainConstraint(const geometry_msgs::msg::PoseStamped &pose)
Eigen::Vector3f computeNewPositions(const Eigen::Vector3f &pos, const Eigen::Vector3f &vel, double dt)
bool checkGoalReached(const geometry_msgs::msg::PoseStamped &pose, double vetta, double gamma, double alpha_error, geometry_msgs::msg::Twist &cmd_vel)
virtual 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
void straightBackwardsAndPureSpinCmd(const geometry_msgs::msg::PoseStamped &pose, double &vetta, double &gamma, double alpha_error, double betta_error, double rho_error)
std::vector< geometry_msgs::msg::PoseStamped > backwardsPlanPath_
void generateTrajectory(const Eigen::Vector3f &pos, const Eigen::Vector3f &vel, float maxdist, float maxangle, float maxtime, float dt, std::vector< Eigen::Vector3f > &outtraj)
std::shared_ptr< rclcpp_lifecycle::LifecyclePublisher< visualization_msgs::msg::MarkerArray > > goalMarkerPublisher_
bool findInitialCarrotGoal(geometry_msgs::msg::PoseStamped &pose)
bool divergenceDetectionUpdate(const geometry_msgs::msg::PoseStamped &pose)
void setPlan(const nav_msgs::msg::Path &path) override
nav2_core setPlan - Sets the global plan
void computeCurrentEuclideanAndAngularErrorsToCarrotGoal(const geometry_msgs::msg::PoseStamped &pose, double &dist, double &angular_error)
bool checkCurrentPoseInGoalRange(const geometry_msgs::msg::PoseStamped &tfpose, const geometry_msgs::msg::Twist &currentTwist, double angle_error, bool &linearGoalReached, nav2_core::GoalChecker *goalChecker)
std::shared_ptr< rclcpp_lifecycle::LifecyclePublisher< nav_msgs::msg::Path > > planPub_
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
virtual void setSpeedLimit(const double &speed_limit, const bool &percentage) override
std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmapRos_