47 #include <ilqgames/constraint/single_dimension_constraint.h> 48 #include <ilqgames/cost/quadratic_cost.h> 49 #include <ilqgames/cost/quadratic_difference_cost.h> 50 #include <ilqgames/cost/relative_distance_cost.h> 51 #include <ilqgames/dynamics/concatenated_dynamical_system.h> 52 #include <ilqgames/dynamics/single_player_dubins_car.h> 53 #include <ilqgames/dynamics/single_player_point_mass_2d.h> 54 #include <ilqgames/examples/modified_air_3d_example.h> 55 #include <ilqgames/geometry/draw_shapes.h> 56 #include <ilqgames/geometry/polyline2.h> 57 #include <ilqgames/solver/ilq_solver.h> 58 #include <ilqgames/solver/problem.h> 59 #include <ilqgames/solver/solver_params.h> 60 #include <ilqgames/utils/types.h> 62 #include <gflags/gflags.h> 68 DEFINE_double(rx0, 4.0,
"Initial x-position (m).");
69 DEFINE_double(ry0, 3.0,
"Initial y-position (m).");
70 DEFINE_double(rtheta0, M_PI / 4.0,
"Initial heading (rad).");
71 DEFINE_double(ve, 1.0,
"Evader speed (m/s).");
72 DEFINE_double(vp, 1.0,
"Pursuer speed (m/s).");
79 static constexpr
float kOmegaMax = 1.0;
80 static constexpr
float kOmegaCostWeight = 0.1;
84 using Dyn = SinglePlayerPointMass2D;
86 static const Dimension kP1PxIdx = Dyn::kPxIdx;
87 static const Dimension kP1PyIdx = Dyn::kPyIdx;
89 static const Dimension kP1VxIdx = Dyn::kVxIdx;
90 static const Dimension kP1VyIdx = Dyn::kVyIdx;
92 static const Dimension kP2PxIdx = Dyn::kNumXDims + Dyn::kPxIdx;
93 static const Dimension kP2PyIdx = Dyn::kNumXDims + Dyn::kPyIdx;
95 static const Dimension kP2VxIdx = Dyn::kNumXDims + Dyn::kVxIdx;
96 static const Dimension kP2VyIdx = Dyn::kNumXDims + Dyn::kVyIdx;
100 void ModifiedAir3DExample::ConstructDynamics() {
101 dynamics_.reset(
new ConcatenatedDynamicalSystem(
102 {std::make_shared<Dyn>(), std::make_shared<Dyn>()}));
105 void ModifiedAir3DExample::ConstructInitialState() {
107 x0_ = VectorXf::Zero(dynamics_->XDim());
108 x0_(kP1VxIdx) = FLAGS_ve;
109 x0_(kP2PxIdx) = FLAGS_rx0;
110 x0_(kP2PyIdx) = FLAGS_ry0;
111 x0_(kP2VxIdx) = FLAGS_vp * std::cos(FLAGS_rtheta0);
112 x0_(kP2VyIdx) = FLAGS_vp * std::sin(FLAGS_rtheta0);
115 void ModifiedAir3DExample::ConstructPlayerCosts() {
117 player_costs_.emplace_back(
"P1", 1.0, 0.0);
118 player_costs_.emplace_back(
"P2", 1.0, 0.0);
119 auto& p1_cost = player_costs_[0];
120 auto& p2_cost = player_costs_[1];
122 const auto control_cost =
123 std::make_shared<QuadraticCost>(kOmegaCostWeight, -1, 0.0,
"ControlCost");
124 p1_cost.AddControlCost(0, control_cost);
125 p2_cost.AddControlCost(1, control_cost);
142 constexpr
float kEvaderWeight = -1e6;
143 constexpr
float kPursuerWeight = 1e6;
150 const std::shared_ptr<QuadraticDifferenceCost> p1_target_cost(
151 new QuadraticDifferenceCost(kEvaderWeight, {kP1PxIdx, kP1PyIdx},
152 {kP2PxIdx, kP2PyIdx},
"Target"));
153 const std::shared_ptr<QuadraticDifferenceCost> p2_target_cost(
154 new QuadraticDifferenceCost(kPursuerWeight, {kP1PxIdx, kP1PyIdx},
155 {kP2PxIdx, kP2PyIdx},
"Target"));
156 p1_cost.AddStateCost(p1_target_cost);
157 p2_cost.AddStateCost(p2_target_cost);
165 inline std::vector<float> ModifiedAir3DExample::Xs(
const VectorXf& x)
const {
166 return {x(kP1PxIdx), x(kP2PxIdx)};
169 inline std::vector<float> ModifiedAir3DExample::Ys(
const VectorXf& x)
const {
170 return {x(kP1PyIdx), x(kP2PyIdx)};
173 inline std::vector<float> ModifiedAir3DExample::Thetas(
174 const VectorXf& x)
const {
176 return {std::atan2(x(kP1VyIdx), x(kP1VxIdx)),
177 std::atan2(x(kP2VyIdx), x(kP2VxIdx))};