basic_control.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014, ATR, Atsushi Watanabe
00003  * Copyright (c) 2014-2018, the neonavigation authors
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  *     * Redistributions of source code must retain the above copyright
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright
00012  *       notice, this list of conditions and the following disclaimer in the
00013  *       documentation and/or other materials provided with the distribution.
00014  *     * Neither the name of the copyright holder nor the names of its
00015  *       contributors may be used to endorse or promote products derived from
00016  *       this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028  * POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00031 #ifndef TRAJECTORY_TRACKER_BASIC_CONTROL_H
00032 #define TRAJECTORY_TRACKER_BASIC_CONTROL_H
00033 
00034 #include <cmath>
00035 
00036 namespace trajectory_tracker
00037 {
00038 inline float timeOptimalControl(const float angle, const float acc)
00039 {
00040   return -std::copysign(1.0, angle) * std::sqrt(std::abs(2 * angle * acc));
00041 }
00042 
00043 inline float clip(const float v, const float max)
00044 {
00045   if (v > max)
00046     return max;
00047   else if (v < -max)
00048     return -max;
00049 
00050   return v;
00051 }
00052 
00053 inline float angleNormalized(float ang)
00054 {
00055   while (ang < -M_PI)
00056     ang += 2.0 * M_PI;
00057   while (ang > M_PI)
00058     ang -= 2.0 * M_PI;
00059   return ang;
00060 }
00061 
00062 class VelAccLimitter
00063 {
00064 private:
00065   float val_prev_;
00066 
00067 public:
00068   inline VelAccLimitter()
00069     : val_prev_(0)
00070   {
00071   }
00072   inline float increment(
00073       const float v, const float vel, const float acc, const float dt)
00074   {
00075     return set(val_prev_ + v, vel, acc, dt);
00076   }
00077   inline float set(
00078       float v, const float vel, const float acc, const float dt)
00079   {
00080     v = clip(v, vel);
00081 
00082     if (v > val_prev_ + dt * acc)
00083       v = val_prev_ + dt * acc;
00084     else if (v < val_prev_ - dt * acc)
00085       v = val_prev_ - dt * acc;
00086 
00087     if (!std::isfinite(v))
00088       v = 0;
00089 
00090     val_prev_ = v;
00091     return v;
00092   }
00093   inline float get() const
00094   {
00095     return val_prev_;
00096   }
00097   inline void clear()
00098   {
00099     val_prev_ = 0;
00100   }
00101 };
00102 }  // namespace trajectory_tracker
00103 
00104 #endif  // TRAJECTORY_TRACKER_BASIC_CONTROL_H


trajectory_tracker
Author(s): Atsushi Watanabe
autogenerated on Sat Jun 22 2019 20:07:25