blob: 676da65db62aeebb5208d07b9d149e12b061013d [file] [log] [blame]
Austin Schuhad596222018-01-31 23:34:03 -08001#include <chrono>
2#include <cmath>
3#include <thread>
4
Austin Schuh87dc7bb2018-10-29 21:53:23 -07005#include "gflags/gflags.h"
Austin Schuhad596222018-01-31 23:34:03 -08006#include "third_party/matplotlib-cpp/matplotlibcpp.h"
7#include "y2018/control_loops/python/arm_bounds.h"
8
9DEFINE_double(boundary_scalar, 20000.0, "quadratic slope");
10DEFINE_double(boundary_rate, 1000.0, "linear slope");
11DEFINE_double(bounds_offset, 0.02, "Offset the quadratic boundary in by this");
12
13using ::y2018::control_loops::Point;
14
15int main(int argc, char **argv) {
16 gflags::ParseCommandLineFlags(&argc, &argv, false);
17
18 ::y2018::control_loops::BoundsCheck arm_space =
19 ::y2018::control_loops::MakeClippedArmSpace();
20
21 matplotlibcpp::figure();
22 ::std::vector<double> bounds_x;
23 ::std::vector<double> bounds_y;
24 for (const Point p : arm_space.points()) {
25 bounds_x.push_back(p.x());
26 bounds_y.push_back(p.y());
27 }
28 matplotlibcpp::plot(bounds_x, bounds_y, {{"label", "actual region"}});
29 matplotlibcpp::legend();
30
31 ::std::vector<::std::vector<double>> cost_x;
32 ::std::vector<::std::vector<double>> cost_y;
33 ::std::vector<::std::vector<double>> cost_z;
34 ::std::vector<::std::vector<double>> cost_z2;
35 ::std::vector<::std::vector<double>> cost_z3;
36
37 for (double x_coordinate = -0.5; x_coordinate < 1.2; x_coordinate += 0.05) {
38 ::std::vector<double> cost_x_row;
39 ::std::vector<double> cost_y_row;
40 ::std::vector<double> cost_z_row;
41 ::std::vector<double> cost_z2_row;
42 ::std::vector<double> cost_z3_row;
43
44 for (double y_coordinate = -1.0; y_coordinate < 5.0; y_coordinate += 0.05) {
45 cost_x_row.push_back(x_coordinate);
46 cost_y_row.push_back(y_coordinate);
47
48 ::Eigen::Matrix<double, 2, 1> norm;
49 double min_distance =
50 arm_space.min_distance(Point(x_coordinate, y_coordinate), &norm);
51 cost_z_row.push_back(::std::min(
52 500.0 * ::std::max(min_distance + FLAGS_bounds_offset, 0.0), 40.0));
53
54 cost_z2_row.push_back(::std::min(
55 FLAGS_boundary_scalar *
56 ::std::max(0.0, min_distance + FLAGS_bounds_offset) *
57 ::std::max(0.0, min_distance + FLAGS_bounds_offset) +
58 FLAGS_boundary_rate *
59 ::std::max(0.0, min_distance + FLAGS_bounds_offset),
60 200.0));
61
62 cost_z3_row.push_back(min_distance);
63 }
64 cost_x.push_back(cost_x_row);
65 cost_y.push_back(cost_y_row);
66 cost_z.push_back(cost_z_row);
67 cost_z2.push_back(cost_z2_row);
68 cost_z3.push_back(cost_z3_row);
69 }
70
71 matplotlibcpp::plot_surface(cost_x, cost_y, cost_z);
72 matplotlibcpp::plot_surface(cost_x, cost_y, cost_z2);
73 matplotlibcpp::plot_surface(cost_x, cost_y, cost_z3);
74 matplotlibcpp::show();
75}