-
Notifications
You must be signed in to change notification settings - Fork 19
/
profile.hh
43 lines (40 loc) · 977 Bytes
/
profile.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef __PROFILE_HH
#define __PROFILE_HH
#include <math.h>
class Profile
{
public:
Profile(void) { reset(); }
Profile(float distance, float duration) {
reset(distance, duration);
}
void reset(void) {
m_distance = 0;
m_duration = 0;
}
void reset(float distance, float duration) {
m_distance = distance;
m_duration = duration;
};
float distance(void) { return m_distance; }
float duration(void) { return m_duration; }
bool empty(void) { return m_duration == 0; }
float value(float time) {
float retval;
if (time > 0)
if (time < m_duration)
retval = m_distance * (M_PI * time / m_duration - 0.5 * sin(2 * M_PI * time / m_duration)) / M_PI;
else
retval = m_distance;
else
retval = 0;
return retval;
}
static float timeRequired(float distance, float maxJerk) {
return cbrtf(4 * M_PI * M_PI * distance / maxJerk);
}
protected:
float m_distance;
float m_duration;
};
#endif