Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
trajectory_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_CORE__TRAJECTORY_GENERATOR_HPP_
36 #define DWB_CORE__TRAJECTORY_GENERATOR_HPP_
37 
38 #include <vector>
39 #include <string>
40 #include <memory>
41 #include "nav_2d_msgs/msg/twist2_d.hpp"
42 #include "dwb_msgs/msg/trajectory2_d.hpp"
43 #include "nav2_ros_common/lifecycle_node.hpp"
44 
45 namespace dwb_core
46 {
47 
64 {
65 public:
66  typedef std::shared_ptr<dwb_core::TrajectoryGenerator> Ptr;
67 
68  virtual ~TrajectoryGenerator() {}
69 
74  virtual void initialize(
75  const nav2::LifecycleNode::SharedPtr & nh,
76  const std::string & plugin_name) = 0;
80  virtual void activate() = 0;
84  virtual void deactivate() = 0;
85  virtual void reset() {}
90  virtual void startNewIteration(const nav_2d_msgs::msg::Twist2D & current_velocity) = 0;
91 
96  virtual bool hasMoreTwists() = 0;
97 
102  virtual nav_2d_msgs::msg::Twist2D nextTwist() = 0;
103 
112  virtual std::vector<nav_2d_msgs::msg::Twist2D> getTwists(
113  const nav_2d_msgs::msg::Twist2D & current_velocity)
114  {
115  std::vector<nav_2d_msgs::msg::Twist2D> twists;
116  startNewIteration(current_velocity);
117  while (hasMoreTwists()) {
118  twists.push_back(nextTwist());
119  }
120  return twists;
121  }
122 
129  virtual dwb_msgs::msg::Trajectory2D generateTrajectory(
130  const geometry_msgs::msg::Pose & start_pose,
131  const nav_2d_msgs::msg::Twist2D & start_vel,
132  const nav_2d_msgs::msg::Twist2D & cmd_vel) = 0;
133 
141  virtual void setSpeedLimit(const double & speed_limit, const bool & percentage) = 0;
142 };
143 
144 } // namespace dwb_core
145 
146 #endif // DWB_CORE__TRAJECTORY_GENERATOR_HPP_
Interface for iterating through possible velocities and creating trajectories.
virtual void initialize(const nav2::LifecycleNode::SharedPtr &nh, const std::string &plugin_name)=0
Initialize parameters as needed.
virtual 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)=0
Given a cmd_vel in the robot's frame and initial conditions, generate a Trajectory2D.
virtual nav_2d_msgs::msg::Twist2D nextTwist()=0
Return the next twist and advance the iteration.
virtual std::vector< nav_2d_msgs::msg::Twist2D > getTwists(const nav_2d_msgs::msg::Twist2D &current_velocity)
Get all the twists for an iteration.
virtual void activate()=0
Activate callbacks as needed.
virtual bool hasMoreTwists()=0
Test to see whether there are more twists to test.
virtual void deactivate()=0
Deactivate callbacks as needed.
virtual void startNewIteration(const nav_2d_msgs::msg::Twist2D &current_velocity)=0
Start a new iteration based on the current velocity.
virtual void setSpeedLimit(const double &speed_limit, const bool &percentage)=0
Limits the maximum linear speed of the robot.