-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChapter4.h
81 lines (69 loc) · 1.36 KB
/
Chapter4.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
#include "Chapter3.h"
struct Bike {
double x = 0;
double y = 0;
double theta = 0;
ArrayXd x_path;
ArrayXd y_path;
ArrayXd theta_path;
};
void BikeModel(Bike & Bike, double v, double w, double dt = 0.001, double t = 1, double handbrake = 0, double a = 1, double L = 1) {
if (v > 5) // 速度限制
v = 5;
if (v < -5)
v = -5;
if (w > 10) // 角速度限制
w = 10;
if (w < -10)
w = -10;
if (a > 5) // 加速度限制
a = 5;
if (a < -5)
a = -5;
w = tan(w) / L * v;
double vx = v * cos(Bike.theta);
double vy = v * sin(Bike.theta);
double xx = Bike.x;
double yy = Bike.y;
double th = Bike.theta;
Bike.x_path = ArrayXd(int(t / dt));
Bike.y_path = ArrayXd(int(t / dt));
Bike.theta_path = ArrayXd(int(t / dt));
int ii = 0;
for (double tt = 0; tt < t; tt += dt) {
Bike.x_path(ii) = xx;
Bike.y_path(ii) = yy;
Bike.theta_path(ii) = th;
ii++;
xx += vx * dt;
yy += vy * dt;
th += w * dt;
v += a * dt;
if (handbrake) {
w = 0;
v = 0;
}
if (th > 60) th = 60;
if (th < -60) th = -60;
if (v > 5) // 速度限制
v = 5;
if (v < -5)
v = -5;
if (w > 10) // 角速度限制
w = 10;
if (w < -10)
w = -10;
vx = v * cos(th);
vy = v * sin(th);
}
Bike.x = xx;
Bike.y = yy;
Bike.theta = th;
}
void LaneChangeMode() {
double v = 1;
double w = 0;
Bike Bike;
BikeModel(Bike, v, w);
cout << Bike.x_path;
}