Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
standard_traj_generator.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef DWB_PLUGINS__STANDARD_TRAJ_GENERATOR_HPP_
36 #define DWB_PLUGINS__STANDARD_TRAJ_GENERATOR_HPP_
37 
38 #include <vector>
39 #include <memory>
40 #include <string>
41 
42 #include "dwb_core/trajectory_generator.hpp"
43 #include "dwb_plugins/velocity_iterator.hpp"
44 #include "dwb_plugins/kinematic_parameters.hpp"
45 #include "nav2_ros_common/lifecycle_node.hpp"
46 
47 namespace dwb_plugins
48 {
49 
55 {
56 public:
57  // Standard TrajectoryGenerator interface
58  void initialize(
59  const nav2::LifecycleNode::SharedPtr & nh,
60  const std::string & plugin_name) override;
61  void startNewIteration(const nav_2d_msgs::msg::Twist2D & current_velocity) override;
62  bool hasMoreTwists() override;
63  nav_2d_msgs::msg::Twist2D nextTwist() override;
64 
65  dwb_msgs::msg::Trajectory2D generateTrajectory(
66  const geometry_msgs::msg::Pose & start_pose,
67  const nav_2d_msgs::msg::Twist2D & start_vel,
68  const nav_2d_msgs::msg::Twist2D & cmd_vel) override;
69 
77  void setSpeedLimit(const double & speed_limit, const bool & percentage) override
78  {
79  if (kinematics_handler_) {
80  kinematics_handler_->setSpeedLimit(speed_limit, percentage);
81  }
82  }
83 
87  void activate() override;
88 
92  void deactivate() override;
93 
94 protected:
98  virtual void initializeIterator(const nav2::LifecycleNode::SharedPtr & nh);
99 
108  virtual nav_2d_msgs::msg::Twist2D computeNewVelocity(
109  const nav_2d_msgs::msg::Twist2D & cmd_vel, const nav_2d_msgs::msg::Twist2D & start_vel,
110  const double dt);
111 
120  virtual geometry_msgs::msg::Pose computeNewPosition(
121  const geometry_msgs::msg::Pose start_pose, const nav_2d_msgs::msg::Twist2D & vel,
122  const double dt);
123 
124 
137  virtual std::vector<double> getTimeSteps(const nav_2d_msgs::msg::Twist2D & cmd_vel);
138 
139  KinematicsHandler::Ptr kinematics_handler_;
140  std::shared_ptr<VelocityIterator> velocity_iterator_;
141 
142  double sim_time_;
143 
144  // Sampling Parameters
145  bool discretize_by_time_;
146 
149 
152 
155 
157  std::string plugin_name_;
158 
161 };
162 
163 
164 } // namespace dwb_plugins
165 
166 #endif // DWB_PLUGINS__STANDARD_TRAJ_GENERATOR_HPP_
Interface for iterating through possible velocities and creating trajectories.
Standard DWA-like trajectory generator.
void startNewIteration(const nav_2d_msgs::msg::Twist2D &current_velocity) override
Start a new iteration based on the current velocity.
double angular_granularity_
If not discretizing by time, the amount of angular space between points.
virtual nav_2d_msgs::msg::Twist2D computeNewVelocity(const nav_2d_msgs::msg::Twist2D &cmd_vel, const nav_2d_msgs::msg::Twist2D &start_vel, const double dt)
Calculate the velocity after a set period of time, given the desired velocity and acceleration limits...
void setSpeedLimit(const double &speed_limit, const bool &percentage) override
Limits the maximum linear speed of the robot.
std::string plugin_name_
the name of the overlying plugin ID
bool hasMoreTwists() override
Test to see whether there are more twists to test.
virtual std::vector< double > getTimeSteps(const nav_2d_msgs::msg::Twist2D &cmd_vel)
Compute an array of time deltas between the points in the generated trajectory.
bool limit_vel_cmd_in_traj_
Option to limit velocity in the trajectory generator by using current velocity.
void activate() override
Registers callbacks for dynamic parameter handling.
double linear_granularity_
If not discretizing by time, the amount of linear space between points.
virtual geometry_msgs::msg::Pose computeNewPosition(const geometry_msgs::msg::Pose start_pose, const nav_2d_msgs::msg::Twist2D &vel, const double dt)
Use the robot's kinematic model to predict new positions for the robot.
double time_granularity_
If discretizing by time, the amount of time between each point in the traj.
void initialize(const nav2::LifecycleNode::SharedPtr &nh, const std::string &plugin_name) override
Initialize parameters as needed.
virtual void initializeIterator(const nav2::LifecycleNode::SharedPtr &nh)
Initialize the VelocityIterator pointer. Put in its own function for easy overriding.
dwb_msgs::msg::Trajectory2D generateTrajectory(const geometry_msgs::msg::Pose &start_pose, const nav_2d_msgs::msg::Twist2D &start_vel, const nav_2d_msgs::msg::Twist2D &cmd_vel) override
Given a cmd_vel in the robot's frame and initial conditions, generate a Trajectory2D.
void deactivate() override
Resets callbacks for dynamic parameter handling.
nav_2d_msgs::msg::Twist2D nextTwist() override
Return the next twist and advance the iteration.