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 
38 namespace dwb_plugins
39 {
41 {
42  kinematics_ = kinematics;
43  nh.param("vx_samples", vx_samples_, 20);
44  nh.param("vy_samples", vy_samples_, 5);
45  vtheta_samples_ = nav_2d_utils::loadParameterWithDeprecation(nh, "vtheta_samples", "vth_samples", 20);
46 }
47 
48 void XYThetaIterator::startNewIteration(const nav_2d_msgs::Twist2D& current_velocity, double dt)
49 {
50  x_it_ = std::make_shared<OneDVelocityIterator>(current_velocity.x, kinematics_->getMinX(), kinematics_->getMaxX(),
51  kinematics_->getAccX(), kinematics_->getDecelX(), dt, vx_samples_);
52  y_it_ = std::make_shared<OneDVelocityIterator>(current_velocity.y, kinematics_->getMinY(), kinematics_->getMaxY(),
53  kinematics_->getAccY(), kinematics_->getDecelY(), dt, vy_samples_);
54  th_it_ = std::make_shared<OneDVelocityIterator>(current_velocity.theta,
55  kinematics_->getMinTheta(), kinematics_->getMaxTheta(),
56  kinematics_->getAccTheta(), kinematics_->getDecelTheta(),
57  dt, vtheta_samples_);
58  if (!isValidVelocity())
59  {
61  }
62 }
63 
65 {
66  return kinematics_->isValidSpeed(x_it_->getVelocity(), y_it_->getVelocity(), th_it_->getVelocity());
67 }
68 
70 {
71  return x_it_ && !x_it_->isFinished();
72 }
73 
74 
75 nav_2d_msgs::Twist2D XYThetaIterator::nextTwist()
76 {
77  nav_2d_msgs::Twist2D velocity;
78  velocity.x = x_it_->getVelocity();
79  velocity.y = y_it_->getVelocity();
80  velocity.theta = th_it_->getVelocity();
81 
83 
84  return velocity;
85 }
86 
88 {
89  bool valid = false;
90  while (!valid && hasMoreTwists())
91  {
92  ++(*th_it_);
93  if (th_it_->isFinished())
94  {
95  th_it_->reset();
96  ++(*y_it_);
97  if (y_it_->isFinished())
98  {
99  y_it_->reset();
100  ++(*x_it_);
101  }
102  }
103  valid = isValidVelocity();
104  }
105 }
106 
107 } // 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 Wed Jun 26 2019 20:06:16