1
+ #include < pybind11/embed.h>
2
+ #include < pybind11/stl.h>
3
+
4
+ #include < mpc_playground/mpc_interface.hpp>
5
+
6
+ using namespace MPC ;
7
+ namespace py = pybind11;
8
+ using namespace py ::literals;
9
+
10
+ int main (int argc, char * argv[]) {
11
+ auto mpc = ModelPredictiveController ();
12
+
13
+ mpc.SetMass (1000.0 );
14
+ mpc.SetGoalXPosition (2.0 );
15
+ mpc.SetGoalYPosition (-4.0 );
16
+ mpc.SetSteeringAngleLowerBound (-0.57596 );
17
+ mpc.SetSteeringAngleUpperBound (0.57596 );
18
+ mpc.SetLongitudinalSpeedInitialValue (0.2 );
19
+ mpc.SetLongitudinalSpeedLowerBound (0.1 );
20
+ mpc.SetLongitudinalSpeedUpperBound (5.0 );
21
+ mpc.SetLongitudinalAccelerationLowerBound (-5.0 );
22
+ mpc.SetLongitudinalAccelerationUpperBound (5.0 );
23
+ mpc.SetLongitudinalJerkLowerBound (-5.5 );
24
+ mpc.SetLongitudinalJerkUpperBound (5.5 );
25
+ mpc.SetSteeringRateLowerBound (-1.2 * 0.57596 );
26
+ mpc.SetSteeringRateUpperBound (1.2 * 0.57596 );
27
+
28
+ mpc.Initialise ();
29
+ mpc.Plan ();
30
+
31
+ auto j_opt = mpc.GetOptimalLongitudinalJerk ();
32
+ auto delta_dot_opt = mpc.GetOptimalSteeringRate ();
33
+ auto x_opt = mpc.GetOptimalXPosition ();
34
+ auto y_opt = mpc.GetOptimalYPosition ();
35
+ auto t_opt = mpc.GetOptimalTimeSpan ();
36
+
37
+ // std::vector<float> j_opt{0, 1, 2};
38
+ // std::vector<float> x_opt{0, 1, 2};
39
+ // std::vector<float> y_opt{0, 1, 2};
40
+ // std::vector<float> t_opt{0, 1, 2};
41
+ // std::vector<float> delta_dot_opt{0, 1, 2};
42
+
43
+ py::scoped_interpreter guard{};
44
+ py::dict locals =
45
+ py::dict{" x_opt" _a = x_opt, " y_opt" _a = y_opt, " j_opt" _a = j_opt, " delta_dot_opt" _a = delta_dot_opt, " t_opt" _a =
46
+ t_opt};
47
+ py::exec (R"(
48
+ import matplotlib.pyplot as plt
49
+
50
+ fig, ax = plt.subplots()
51
+ ax.plot(x_opt, y_opt, "-o")
52
+ ax.set_title("AGV trajectory")
53
+ ax.set_xlabel("X Coordinate [m]")
54
+ ax.set_ylabel("Y Coordinate [m]")
55
+ ax.set_aspect('equal', adjustable='box')
56
+
57
+ dir = 'assets/img'
58
+ plt.savefig(f"""{dir}/ack-trajectory.png""")
59
+ )" , py::globals (), locals);
60
+
61
+ py::exec (R"(
62
+ fig, ax = plt.subplots()
63
+ ax.set_title('AGV longitudinal jerk')
64
+ ax.plot(t_opt, j_opt, "-o")
65
+ ax.set_xlabel("Time [s]")
66
+ ax.set_ylabel("Longitudinal jerk [m/s^3]")
67
+ ax.set_aspect('equal', adjustable = 'box')
68
+ plt.savefig(f"""{dir}/ack-controls-1.png""")
69
+
70
+ fig, ax = plt.subplots()
71
+ ax.set_title('AGV steering rate')
72
+ ax.plot(t_opt, delta_dot_opt, "-o")
73
+ ax.set_xlabel("Time [s]")
74
+ ax.set_ylabel("Steering rate [rad/s]")
75
+ ax.set_aspect('equal', adjustable = 'box')
76
+ plt.savefig(f"""{dir}/ack-controls-2.png""")
77
+ )" , py::globals (), locals);
78
+
79
+ return EXIT_SUCCESS;
80
+ }
0 commit comments