15#include <angles/angles.h>
19#include <nav_2d_utils/tf_help.hpp>
20#include <pluginlib/class_list_macros.hpp>
24namespace pure_spinning_local_planner
27void tryGetOrSet(rclcpp_lifecycle::LifecycleNode::SharedPtr & node, std::string param,
T & value)
29 if (!node->get_parameter(param, value))
31 node->set_parameter(rclcpp::Parameter(param, value));
41 RCLCPP_INFO_STREAM(
nh_->get_logger(),
"activating controller PureSpinningLocalPlanner");
55 const rclcpp_lifecycle::LifecycleNode::WeakPtr & node, std::string name,
56 const std::shared_ptr<tf2_ros::Buffer> & tf,
57 const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> & costmap_ros)
76 nh_->get_logger(),
"[PureSpinningLocalPlanner] pure spinning planner already created");
89 const geometry_msgs::msg::PoseStamped & pose,
const geometry_msgs::msg::Twist & ,
90 nav2_core::GoalChecker * goal_checker)
95 geometry_msgs::msg::Pose posetol;
96 geometry_msgs::msg::Twist twistol;
97 if (goal_checker->getTolerances(posetol, twistol))
108 nh_->get_logger(),
"[PureSpinningLocalPlanner] could not get tolerances from goal checker");
112 geometry_msgs::msg::TwistStamped cmd_vel;
117 geometry_msgs::msg::PoseStamped currentPose = pose;
120 tf2::fromMsg(currentPose.pose.orientation, q);
121 auto currentYaw = tf2::getYaw(currentPose.pose.orientation);
122 double angular_error = 0;
128 targetYaw = tf2::getYaw(goal.pose.orientation);
131 angular_error = angles::shortest_angular_distance(currentYaw, targetYaw);
133 angular_error = targetYaw - currentYaw;
151 auto omega = angular_error *
k_betta_;
152 cmd_vel.twist.angular.z =
158 RCLCPP_INFO_STREAM(
nh_->get_logger(),
"[PureSpinningLocalPlanner] k_betta_: " <<
k_betta_);
160 nh_->get_logger(),
"[PureSpinningLocalPlanner] angular error: " << angular_error <<
"(tol "
164 "[PureSpinningLocalPlanner] command angular speed: " << cmd_vel.twist.angular.z);
172 nh_->get_logger(),
"[PureSpinningLocalPlanner] GOAL REACHED. Sending stop command.");
174 cmd_vel.twist.linear.x = 0;
175 cmd_vel.twist.angular.z = 0;
182 const double & ,
const bool & )
186 "PureSpinningLocalPlanner::setSpeedLimit invoked. Ignored, funcionality not "
194 RCLCPP_INFO_STREAM(
nh_->get_logger(),
"activating controller PureSpinningLocalPlanner");
196 nav_msgs::msg::Path transformedPlan;
200 for (
auto & p : path.poses)
202 geometry_msgs::msg::PoseStamped transformedPose;
203 nav_2d_utils::transformPose(
tf_,
costmapRos_->getGlobalFrameID(), p, transformedPose, ttol);
204 transformedPose.header.frame_id =
costmapRos_->getGlobalFrameID();
205 transformedPlan.poses.push_back(transformedPose);
208 plan_ = transformedPlan.poses;
218PLUGINLIB_EXPORT_CLASS(
rad intermediate_goal_yaw_tolerance_
PureSpinningLocalPlanner()
std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmapRos_
rad_s max_angular_z_speed_
virtual void setSpeedLimit(const double &speed_limit, const bool &percentage) override
virtual ~PureSpinningLocalPlanner()
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 deactivate() override
std::vector< geometry_msgs::msg::PoseStamped > plan_
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
std::shared_ptr< tf2_ros::Buffer > tf_
nav2_util::LifecycleNode::SharedPtr nh_
bool use_shortest_angular_distance_
void setPlan(const nav_msgs::msg::Path &path) override
nav2_core setPlan - Sets the global plan
double transform_tolerance_
void declareOrSet(rclcpp_lifecycle::LifecycleNode::SharedPtr &node, std::string param, T &value)
void publishGoalMarker(double, double, double)
void tryGetOrSet(rclcpp_lifecycle::LifecycleNode::SharedPtr &node, std::string param, T &value)