HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MinJerk.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_MinJerk.h ( UI Library, C++)
7  *
8  * COMMENTS:
9  *
10  * MinJerk generates a curve that MINimimises the JERK of the movement.
11  * Ie a curve with as little acceleration change as possible.
12  * Using the constraints of the start and end positions, velocity, acceleration
13  * and total travel time.
14  *
15  * It works typically well with positional values.
16  * But it can of course be used with any kind of data.
17  *
18  *
19  *
20  * Typical usage would look something like this:
21  *
22  * auto coefs = MinJerk_CalculateCoefficients(
23  * start_pos, end_pos,
24  * start_vel, end_vel,
25  * start_acc, end_acc,
26  * total_travel_time);
27  *
28  * sample_time = min(sample_time, total_travel_time);
29  *
30  * auto sample = MinJerkSample(coefs, sample_time);
31  *
32  * sample.pos;
33  * sample.vel;
34  * sample.acc;
35  *
36  * // To build a graph, do something like this.
37  * UT_Array points;
38  * for(float t=0; t<total_time; t+=time_step)
39  * {
40  * auto sample = MinJerkSample(coefs, t);
41  * points.append(sample.pos);
42  * }
43  *
44  *
45  */
46 
47 #ifndef __UT_MinJerk_h__
48 #define __UT_MinJerk_h__
49 
50 #include <SYS/SYS_Math.h>
51 
52 template <typename T>
54 {
55  T pos;
56  T vel;
57  T acc;
58 };
59 
60 template <typename T>
62 {
66 };
67 
68 template <typename T>
70 {
74 };
75 
76 template <typename T>
78 {
82 };
83 
84 
85 template <typename T>
86 void
88  const T pos0,
89  const T vel0,
90  const T acc0,
91  const T pos1,
92  const T vel1,
93  const T acc1,
94  const T sample_time,
95  const T total_time,
96  T& out_pos,
97  T& out_vel,
98  T& out_acc
99  )
100 {
101  if (total_time == 0.0)
102  {
103  return;
104  }
105 
106  T tt = total_time;
107  T tt2 = tt * tt;
108 
109  T a = pos0;
110  T b = vel0 * tt;
111  T c = acc0 * tt2 * 0.5;
112 
113  T pos = pos1 - pos0 - b - c;
114  T vel = vel1 * tt - b - 2.0 * c;
115  T acc = acc1 * tt2 - 2.0 * c;
116 
117  T d = ( 10.0 * pos) - (4.0 * vel) + (0.5 * acc);
118  T e = (-15.0 * pos) + (7.0 * vel) - (1.0 * acc);
119  T f = ( 6.0 * pos) - (3.0 * vel) + (0.5 * acc);
120 
121  T t = sample_time / total_time;
122  T t2 = t * t;
123  T t3 = t2 * t;
124  T t4 = t2 * t2;
125  T t5 = t2 * t3;
126 
127  out_pos =
128  a +
129  b * t +
130  c * t2 +
131  d * t3 +
132  e * t4 +
133  f * t5;
134 
135  out_vel = (
136  b +
137  c * 2.0 * t +
138  d * 3.0 * t2 +
139  e * 4.0 * t3 +
140  f * 5.0 * t4) * t;
141 
142  out_acc = (
143  c * 2.0 +
144  d * 6.0 * t +
145  e * 12.0 * t2 +
146  f * 20.0 * t3) * t2;
147 }
148 
149 
150 
151 template <typename T>
153 MinJerk(
154  const T pos0,
155  const T vel0,
156  const T acc0,
157  const T pos1,
158  const T vel1,
159  const T acc1,
160  const T sample_time,
161  const T total_time)
162 {
164  MinJerk(pos0, vel0, acc0, pos1, vel1, acc1, sample_time, total_time,
165  out.pos, out.vel, out.acc);
166  return out;
167 }
168 
169 #define COLLECT_MINJERK_AXIS(I) \
170  MinJerk(pos0.I(), vel0.I(), acc0.I(), pos1.I(), vel1.I(), acc1.I(), \
171  sample_time, total_time, \
172  out.pos.I(), out.vel.I(), out.acc.I());
173 
174 template <typename T>
176 MinJerk(
177  const UT_Vector2T<T>& pos0,
178  const UT_Vector2T<T>& vel0,
179  const UT_Vector2T<T>& acc0,
180  const UT_Vector2T<T>& pos1,
181  const UT_Vector2T<T>& vel1,
182  const UT_Vector2T<T>& acc1,
183  const T sample_time,
184  const T total_time
185  )
186 {
190 
191  return out;
192 }
193 
194 template <typename T>
196 MinJerk(
197  const UT_Vector3T<T>& pos0,
198  const UT_Vector3T<T>& vel0,
199  const UT_Vector3T<T>& acc0,
200  const UT_Vector3T<T>& pos1,
201  const UT_Vector3T<T>& vel1,
202  const UT_Vector3T<T>& acc1,
203  const T sample_time,
204  const T total_time)
205 {
210 
211  return out;
212 }
213 
214 template <typename T>
216 MinJerk(const UT_Vector4T<T>& pos0,
217  const UT_Vector4T<T>& vel0,
218  const UT_Vector4T<T>& acc0,
219  const UT_Vector4T<T>& pos1,
220  const UT_Vector4T<T>& vel1,
221  const UT_Vector4T<T>& acc1,
222  const T sample_time,
223  const T total_time)
224 {
230 
231  return out;
232 }
233 
234 #undef COLLECT_MINJERK_AXIS
235 
236 #endif
UT_Vector3T< T > vel
Definition: UT_MinJerk.h:72
void MinJerk(const T pos0, const T vel0, const T acc0, const T pos1, const T vel1, const T acc1, const T sample_time, const T total_time, T &out_pos, T &out_vel, T &out_acc)
Definition: UT_MinJerk.h:87
UT_Vector2T< T > vel
Definition: UT_MinJerk.h:64
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
UT_Vector3T< T > pos
Definition: UT_MinJerk.h:71
GLint y
Definition: glcorearb.h:103
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:176
2D Vector class.
Definition: UT_Vector2.h:162
UT_Vector4T< T > pos
Definition: UT_MinJerk.h:79
GLfloat f
Definition: glcorearb.h:1926
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
GLdouble t
Definition: glad.h:2397
UT_Vector4T< T > acc
Definition: UT_MinJerk.h:81
#define COLLECT_MINJERK_AXIS(I)
Definition: UT_MinJerk.h:169
UT_Vector3T< T > acc
Definition: UT_MinJerk.h:73
UT_Vector4T< T > vel
Definition: UT_MinJerk.h:80
UT_Vector2T< T > acc
Definition: UT_MinJerk.h:65
UT_Vector2T< T > pos
Definition: UT_MinJerk.h:63
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857