-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrajectory.h
86 lines (79 loc) · 1.88 KB
/
trajectory.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
軌跡生成ライブラリ
*/
#ifndef ___KAL_TRAJECTORY_H
#define ___KAL_TRAJECTORY_H
#include <math.h>
#include "config.h"
//type
#define STEP 0
#define LINER 1
#define COSIN 2
#define JERK 3
namespace kal{
template<class T>
class trajectory{
public:
int type = 0;
double start_time = 0.0;
double goal_time;
double t;//相対時刻
T start_val;
T goal_val;
double interval;
T L;
bool start_flag = 0;
bool goal_flag = 0;
T a;
T b;
T c;
T d;
trajectory();
void creat(T start_val_in,T goal_val_in,double start_time_in,double interval_in,int type_in);
T get(double now_time);
};
template<class T>
trajectory<T>::trajectory(){
}
template<class T>
void trajectory<T>::creat(T start_val_in,T goal_val_in,double start_time_in,double interval_in,int type_in){
start_val = start_val_in;
goal_val = goal_val_in;
start_time = start_time_in;
interval = interval_in;
goal_time = start_time + interval;
type = type_in;
L = goal_val - start_val;
start_flag = true;
goal_flag = false;
}
template<class T>
T trajectory<T>::get(double now_time){
T ret_val;
t = now_time -start_time;
if(now_time > goal_time){
goal_flag = true;
ret_val = goal_val;
}
else if(now_time < start_time){
ret_val = start_val;//@todo:要チェック
}
else{
if(type == STEP){
ret_val = goal_val;
}
else if(type == LINER){
ret_val = (goal_val-start_val)*t + start_val;
}
else if(type == COSIN){
ret_val = (goal_val-start_val)/2.0 * (1 -cos(t/interval*PI)) + start_val;
}
else if(type == JERK){//jerk min
double tau = t/interval;
ret_val = start_val + (goal_val-start_val)*(10.0*tau*tau*tau-15.0*tau*tau*tau*tau+6.0*tau*tau*tau*tau*tau);
}
}
return ret_val;
}
}
#endif