-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanner.java
52 lines (47 loc) · 1.26 KB
/
Planner.java
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
//
// Description: Implement a trapezoidal velocity profile.
//
// Always work in the interval [0,abs(T-X0)].
// When we are passed in a value X, transform it to x = abs(X-X0).
//
//
public class Planner {
private double a = 1.0;
private double b = -1.0;
private double y0 = 0.01;
private double ymax = 1.0;
private double X0;
private double T;
private double x1, x2, xint;
private boolean isTriangle = false;
public Planner (double X0, double T) {
this.X0 = X0;
this.T = T;
x1 = (ymax - y0)/a;
x2 = ymax/b + Math.abs(T-X0);
if (x1 > x2) {
isTriangle = true;
xint = ((-b)*Math.abs(T-X0) - y0)/(a - b);
}
}
public double getRate (double X) {
double x = Math.abs(X - X0);
double rate;
if (isTriangle) {
if (x <= xint) {
rate = (a*x + y0);
} else {
rate = b*(x - Math.abs(T-X0));
}
} else {
if (x <= x1) {
rate = (a*x + y0);
} else if (x <= x2) {
rate = ymax;
} else {
rate = b*(x - Math.abs(T-X0));
}
}
return rate;
}
}