xy_theta_iterator.cpp
Go to the documentation of this file.
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 
37 #include <memory>
38 
39 namespace dwb_plugins
40 {
42 {
43  kinematics_ = kinematics;
44  nh.param("vx_samples", vx_samples_, 20);
45  nh.param("vy_samples", vy_samples_, 5);
46  vtheta_samples_ = nav_2d_utils::loadParameterWithDeprecation(nh, "vtheta_samples", "vth_samples", 20);
47 }
48 
49 void XYThetaIterator::startNewIteration(const nav_2d_msgs::Twist2D& current_velocity, double dt)
50 {
51  x_it_ = std::make_shared<OneDVelocityIterator>(current_velocity.x, kinematics_->getMinX(), kinematics_->getMaxX(),
52  kinematics_->getAccX(), kinematics_->getDecelX(), dt, vx_samples_);
53  y_it_ = std::make_shared<OneDVelocityIterator>(current_velocity.y, kinematics_->getMinY(), kinematics_->getMaxY(),
54  kinematics_->getAccY(), kinematics_->getDecelY(), dt, vy_samples_);
55  th_it_ = std::make_shared<OneDVelocityIterator>(current_velocity.theta,
56  kinematics_->getMinTheta(), kinematics_->getMaxTheta(),
57  kinematics_->getAccTheta(), kinematics_->getDecelTheta(),
58  dt, vtheta_samples_);
59  if (!isValidVelocity())
60  {
62  }
63 }
64 
66 {
67  return kinematics_->isValidSpeed(x_it_->getVelocity(), y_it_->getVelocity(), th_it_->getVelocity());
68 }
69 
71 {
72  return x_it_ && !x_it_->isFinished();
73 }
74 
75 
76 nav_2d_msgs::Twist2D XYThetaIterator::nextTwist()
77 {
78  nav_2d_msgs::Twist2D velocity;
79  velocity.x = x_it_->getVelocity();
80  velocity.y = y_it_->getVelocity();
81  velocity.theta = th_it_->getVelocity();
82 
84 
85  return velocity;
86 }
87 
89 {
90  bool valid = false;
91  while (!valid && hasMoreTwists())
92  {
93  ++(*th_it_);
94  if (th_it_->isFinished())
95  {
96  th_it_->reset();
97  ++(*y_it_);
98  if (y_it_->isFinished())
99  {
100  y_it_->reset();
101  ++(*x_it_);
102  }
103  }
104  valid = isValidVelocity();
105  }
106 }
107 
108 } // namespace dwb_plugins
nav_2d_msgs::Twist2D nextTwist() override
void initialize(ros::NodeHandle &nh, KinematicParameters::Ptr kinematics) override
std::shared_ptr< KinematicParameters > Ptr
void startNewIteration(const nav_2d_msgs::Twist2D &current_velocity, double dt) override
KinematicParameters::Ptr kinematics_
std::shared_ptr< OneDVelocityIterator > y_it_
bool param(const std::string &param_name, T &param_val, const T &default_val) const
std::shared_ptr< OneDVelocityIterator > th_it_
std::shared_ptr< OneDVelocityIterator > x_it_
param_t loadParameterWithDeprecation(const ros::NodeHandle &nh, const std::string current_name, const std::string old_name, const param_t &default_value)


dwb_plugins
Author(s):
autogenerated on Sun Jan 10 2021 04:08:37