45 #include <ilqgames/constraint/single_dimension_constraint.h> 46 #include <ilqgames/cost/polyline2_signed_distance_cost.h> 47 #include <ilqgames/cost/quadratic_cost.h> 48 #include <ilqgames/dynamics/two_player_unicycle_4d.h> 49 #include <ilqgames/examples/two_player_reachability_example.h> 50 #include <ilqgames/geometry/draw_shapes.h> 51 #include <ilqgames/geometry/polyline2.h> 52 #include <ilqgames/solver/ilq_solver.h> 53 #include <ilqgames/solver/problem.h> 54 #include <ilqgames/solver/solver_params.h> 55 #include <ilqgames/utils/types.h> 57 #include <gflags/gflags.h> 63 DEFINE_double(px0, 0.0,
"Initial x-position (m).");
64 DEFINE_double(py0, -10.0,
"Initial y-position (m).");
65 DEFINE_double(theta0, M_PI / 4.0,
"Initial heading (rad).");
66 DEFINE_double(v0, 5.0,
"Initial speed (m/s).");
72 static constexpr
float kOmegaMax = 0.1;
73 static constexpr
float kAMax = 1.0;
74 static constexpr
float kDMax = 0.5;
75 static constexpr
float kControlCostWeight = 0.1;
78 using Dyn = TwoPlayerUnicycle4D;
82 void TwoPlayerReachabilityExample::ConstructDynamics() {
83 dynamics_.reset(
new TwoPlayerUnicycle4D());
86 void TwoPlayerReachabilityExample::ConstructInitialState() {
87 x0_ = VectorXf::Zero(dynamics_->XDim());
88 x0_(Dyn::kPxIdx) = FLAGS_px0;
89 x0_(Dyn::kPyIdx) = FLAGS_py0;
90 x0_(Dyn::kThetaIdx) = FLAGS_theta0;
91 x0_(Dyn::kVIdx) = FLAGS_v0;
94 void TwoPlayerReachabilityExample::ConstructPlayerCosts() {
96 player_costs_.emplace_back(
"P1");
97 player_costs_.emplace_back(
"P2");
98 auto& p1_cost = player_costs_[0];
99 auto& p2_cost = player_costs_[1];
101 const auto control_cost = std::make_shared<QuadraticCost>(
102 kControlCostWeight, -1, 0.0,
"ControlCost");
103 p1_cost.AddControlCost(0, control_cost);
104 p2_cost.AddControlCost(1, control_cost);
107 static constexpr
bool kReach =
true;
108 const float kTargetRadius = 1.0;
109 const Polyline2 circle = DrawCircle(Point2::Zero(), kTargetRadius, 10);
110 const std::shared_ptr<Polyline2SignedDistanceCost> p1_target_cost(
111 new Polyline2SignedDistanceCost(circle, {Dyn::kPxIdx, Dyn::kPyIdx},
113 const std::shared_ptr<Polyline2SignedDistanceCost> p2_target_cost(
114 new Polyline2SignedDistanceCost(circle, {Dyn::kPxIdx, Dyn::kPyIdx},
117 p1_cost.AddStateCost(p1_target_cost);
118 p2_cost.AddStateCost(p2_target_cost);
121 p1_cost.SetMaxOverTime();
122 p2_cost.SetMinOverTime();
125 inline std::vector<float> TwoPlayerReachabilityExample::Xs(
126 const VectorXf& x)
const {
127 return {x(Dyn::kPxIdx)};
130 inline std::vector<float> TwoPlayerReachabilityExample::Ys(
131 const VectorXf& x)
const {
132 return {x(Dyn::kPyIdx)};
135 inline std::vector<float> TwoPlayerReachabilityExample::Thetas(
136 const VectorXf& x)
const {
137 return {x(Dyn::kThetaIdx)};