KrisLibrary  1.0.0
ParabolicRamp.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (c) 2010-2011, the Trustees of Indiana University
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  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Indiana University nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16 
17  * THIS SOFTWARE IS PROVIDED BY THE TRUSTEES OF INDIANA UNIVERSITY ''AS IS''
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OF INDIANA UNIVERSITY BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  ***************************************************************************/
30 
31 #ifndef PARABOLIC_RAMP_H
32 #define PARABOLIC_RAMP_H
33 
34 #include <KrisLibrary/math/math.h>
35 #include <vector>
36 
37 namespace ParabolicRamp {
38 
39  typedef Math::Real Real;
40  typedef std::vector<Real> Vector;
41 
42 
55 {
56  public:
58  void SetConstant(Real x,Real t=0);
60  void SetLinear(Real x0,Real x1,Real t);
62  bool SolveMinTime(Real amax,Real vmax);
64  bool SolveMinTime2(Real amax,Real vmax,Real tLowerBound);
66  bool SolveMinAccel(Real endTime,Real vmax);
68  Real SolveMinAccel2(Real endTime,Real vmax);
70  void SolveBraking(Real amax);
72  Real Evaluate(Real t) const;
74  Real Derivative(Real t) const;
76  Real Accel(Real t) const;
78  Real EndTime() const { return ttotal; }
80  void Dilate(Real timeScale);
82  void TrimFront(Real tcut);
84  void TrimBack(Real tcut);
86  void Bounds(Real& xmin,Real& xmax) const;
88  void Bounds(Real ta,Real tb,Real& xmin,Real& xmax) const;
90  void DerivBounds(Real& vmin,Real& vmax) const;
92  void DerivBounds(Real ta,Real tb,Real& vmin,Real& vmax) const;
94  bool IsValid() const;
95 
97  Real x0,dx0;
98  Real x1,dx1;
99 
101  Real tswitch1,tswitch2; //time to switch between ramp/flat/ramp
102  Real ttotal;
103  Real a1,v,a2; // accel of first ramp, velocity of linear section, accel of second ramp
104 };
105 
111 {
112  public:
113  void SetConstant(const Vector& x,Real t=0);
114  void SetLinear(const Vector& x0,const Vector& x1,Real t);
115  bool SolveMinTimeLinear(const Vector& amax,const Vector& vmax);
116  bool SolveMinTime(const Vector& amax,const Vector& vmax);
117  bool SolveMinAccel(const Vector& vmax,Real time);
118  bool SolveMinAccelLinear(const Vector& vmax,Real time);
119  void SolveBraking(const Vector& amax);
120  void Evaluate(Real t,Vector& x) const;
121  void Derivative(Real t,Vector& dx) const;
122  void Accel(Real t,Vector& ddx) const;
123  void Output(Real dt,std::vector<Vector>& path) const;
124  void Dilate(Real timeScale);
125  void TrimFront(Real tcut);
126  void TrimBack(Real tcut);
127  void Bounds(Vector& xmin,Vector& xmax) const;
128  void Bounds(Real ta,Real tb,Vector& xmin,Vector& xmax) const;
129  void DerivBounds(Vector& vmin,Vector& vmax) const;
130  void DerivBounds(Real ta,Real tb,Vector& vmin,Vector& vmax) const;
131  bool IsValid() const;
132 
134  Vector x0,dx0;
135  Vector x1,dx1;
136 
138  Real endTime;
139  std::vector<ParabolicRamp1D> ramps;
140 };
141 
144 bool SolveMinTimeBounded(Real x0,Real v0,Real x1,Real v1,
145  Real amax,Real vmax,Real xmin,Real xmax,
146  ParabolicRamp1D& ramp);
147 
151 bool SolveMinAccelBounded(Real x0,Real v0,Real x1,Real v1,
152  Real endTime,Real vmax,Real xmin,Real xmax,
153  std::vector<ParabolicRamp1D>& ramps);
154 
157 Real SolveMinTimeBounded(const Vector& x0,const Vector& v0,const Vector& x1,const Vector& v1,
158  const Vector& amax,const Vector& vmax,const Vector& xmin,const Vector& xmax,
159  std::vector<std::vector<ParabolicRamp1D> >& ramps);
160 
163 bool SolveMinAccelBounded(const Vector& x0,const Vector& v0,const Vector& x1,const Vector& v1,
164  Real endTime,const Vector& vmax,const Vector& xmin,const Vector& xmax,
165  std::vector<std::vector<ParabolicRamp1D> >& ramps);
166 
168 void CombineRamps(const std::vector<std::vector<ParabolicRamp1D> >& ramps,std::vector<ParabolicRampND>& ndramps);
169 
170 } //namespace ParabolicRamp
171 
172 #endif
Common math typedefs, constants, functions.
void Bounds(Real &xmin, Real &xmax) const
Returns the x bounds on the path.
Definition: ParabolicRamp.cpp:1773
Real endTime
Calculated upon SolveX.
Definition: ParabolicRamp.h:138
bool IsValid() const
Sanity check.
Definition: ParabolicRamp.cpp:1877
void DerivBounds(Real &vmin, Real &vmax) const
Returns the v bounds on the path.
Definition: ParabolicRamp.cpp:1835
Solves for optimal trajectores for a velocity-bounded ND system.
Definition: ParabolicRamp.h:110
Real SolveMinAccel2(Real endTime, Real vmax)
Same, but if fails, returns the minimum time > endTime.
Definition: ParabolicRamp.cpp:39
Real Derivative(Real t) const
Evaluates the derivative of the trajectory.
Definition: ParabolicRamp.cpp:1361
void Dilate(Real timeScale)
Scales time to slow down (value > 1) or speed up (< 1) the trajectory.
Definition: ParabolicRamp.cpp:1731
Real Accel(Real t) const
Evaluates the second derivative of the trajectory.
Definition: ParabolicRamp.cpp:1373
Real Evaluate(Real t) const
Evaluates the trajectory.
Definition: ParabolicRamp.cpp:1348
Real x0
Input.
Definition: ParabolicRamp.h:97
void TrimBack(Real tcut)
Trims off the front [T-tcut,T] of the trajectory.
Definition: ParabolicRamp.cpp:1762
bool SolveMinTime2(Real amax, Real vmax, Real tLowerBound)
Solves for minimum time given acceleration and velocity bounds, min time.
Definition: ParabolicRamp.cpp:1614
bool SolveMinAccel(Real endTime, Real vmax)
Solves for minimum acceleration given end time and velocity bounds.
Definition: ParabolicRamp.cpp:1382
Vector x0
Input.
Definition: ParabolicRamp.h:134
Stores optimal trajectores for an acceleration and velocity-bounded 1D system.
Definition: ParabolicRamp.h:54
bool SolveMinTime(Real amax, Real vmax)
Solves for minimum time given acceleration and velocity bounds.
Definition: ParabolicRamp.cpp:1501
void SetConstant(Real x, Real t=0)
Sets the ramp to a constant function for time t.
Definition: ParabolicRamp.cpp:1328
void SetLinear(Real x0, Real x1, Real t)
Sets the ramp to a linear function from x0 to x1 with time t.
Definition: ParabolicRamp.cpp:1336
void TrimFront(Real tcut)
Trims off the front [0,tcut] of the trajectory.
Definition: ParabolicRamp.cpp:1744
void SolveBraking(Real amax)
Solves for the minimum-time braking trajectory starting from x0,dx0.
Definition: ParabolicRamp.cpp:1715
Real tswitch1
Calculated upon SolveX.
Definition: ParabolicRamp.h:101
Real EndTime() const
Returns the time at which x1 is reached.
Definition: ParabolicRamp.h:78