basic_control.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, ATR, Atsushi Watanabe
3  * Copyright (c) 2014-2018, the neonavigation authors
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef TRAJECTORY_TRACKER_BASIC_CONTROL_H
32 #define TRAJECTORY_TRACKER_BASIC_CONTROL_H
33 
34 #include <cmath>
35 
36 namespace trajectory_tracker
37 {
38 inline float timeOptimalControl(const float angle, const float acc)
39 {
40  return -std::copysign(1.0, angle) * std::sqrt(std::abs(2 * angle * acc));
41 }
42 
43 inline float clip(const float v, const float max)
44 {
45  if (v > max)
46  return max;
47  else if (v < -max)
48  return -max;
49 
50  return v;
51 }
52 
53 inline float angleNormalized(float ang)
54 {
55  while (ang < -M_PI)
56  ang += 2.0 * M_PI;
57  while (ang > M_PI)
58  ang -= 2.0 * M_PI;
59  return ang;
60 }
61 
63 {
64 private:
65  float val_prev_;
66 
67 public:
68  inline VelAccLimitter()
69  : val_prev_(0)
70  {
71  }
72  inline float increment(
73  const float v, const float vel, const float acc, const float dt)
74  {
75  return set(val_prev_ + v, vel, acc, dt);
76  }
77  inline float set(
78  float v, const float vel, const float acc, const float dt)
79  {
80  v = clip(v, vel);
81 
82  if (v > val_prev_ + dt * acc)
83  v = val_prev_ + dt * acc;
84  else if (v < val_prev_ - dt * acc)
85  v = val_prev_ - dt * acc;
86 
87  if (!std::isfinite(v))
88  v = 0;
89 
90  val_prev_ = v;
91  return v;
92  }
93  inline float get() const
94  {
95  return val_prev_;
96  }
97  inline void clear()
98  {
99  val_prev_ = 0;
100  }
101 };
102 } // namespace trajectory_tracker
103 
104 #endif // TRAJECTORY_TRACKER_BASIC_CONTROL_H
float increment(const float v, const float vel, const float acc, const float dt)
Definition: basic_control.h:72
float angleNormalized(float ang)
Definition: basic_control.h:53
float timeOptimalControl(const float angle, const float acc)
Definition: basic_control.h:38
float clip(const float v, const float max)
Definition: basic_control.h:43


trajectory_tracker
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:09