44 #include <ilqgames/constraint/single_dimension_constraint.h> 45 #include <ilqgames/cost/polyline2_signed_distance_cost.h> 46 #include <ilqgames/cost/quadratic_cost.h> 47 #include <ilqgames/dynamics/concatenated_dynamical_system.h> 48 #include <ilqgames/dynamics/single_player_dubins_car.h> 49 #include <ilqgames/examples/one_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, 1.75,
"Initial x-position (m).");
64 DEFINE_double(py0, 1.75,
"Initial y-position (m).");
65 DEFINE_double(theta0, 0.0,
"Initial heading (rad).");
72 static constexpr
bool kAvoid =
true;
75 static constexpr
float kTargetRadius = 2.0;
78 static constexpr
float kOmegaMax = 1.0;
79 static constexpr
float kOmegaCostWeight = 0.1;
82 static constexpr
float kSpeed = 1.0;
85 static constexpr
float kP1TargetX = 0.0;
86 static constexpr
float kP1TargetY = 0.0;
89 using P1 = SinglePlayerDubinsCar;
91 static const Dimension kP1XIdx = P1::kPxIdx;
92 static const Dimension kP1YIdx = P1::kPyIdx;
93 static const Dimension kP1ThetaIdx = P1::kThetaIdx;
96 static const Dimension kP1OmegaIdx = 0;
100 void OnePlayerReachabilityExample::ConstructDynamics() {
102 new ConcatenatedDynamicalSystem({std::make_shared<P1>(kSpeed)}));
105 void OnePlayerReachabilityExample::ConstructInitialState() {
107 x0_ = VectorXf::Zero(dynamics_->XDim());
108 x0_(kP1XIdx) = FLAGS_px0;
109 x0_(kP1YIdx) = FLAGS_py0;
110 x0_(kP1ThetaIdx) = FLAGS_theta0;
113 void OnePlayerReachabilityExample::ConstructPlayerCosts() {
115 player_costs_.emplace_back(
"P1");
116 auto& p1_cost = player_costs_[0];
118 const auto control_cost =
119 std::make_shared<QuadraticCost>(kOmegaCostWeight, -1, 0.0,
"ControlCost");
120 p1_cost.AddControlCost(0, control_cost);
123 const auto p1_omega_max_constraint =
124 std::make_shared<SingleDimensionConstraint>(kP1OmegaIdx, kOmegaMax,
true,
125 "Input Constraint (Max)");
126 const auto p1_omega_min_constraint =
127 std::make_shared<SingleDimensionConstraint>(
128 kP1OmegaIdx, -kOmegaMax,
false,
"Input Constraint (Min)");
129 p1_cost.AddControlConstraint(0, p1_omega_max_constraint);
130 p1_cost.AddControlConstraint(0, p1_omega_min_constraint);
133 const Polyline2 circle =
134 DrawCircle(Point2(kP1TargetX, kP1TargetY), kTargetRadius, 10);
135 const std::shared_ptr<Polyline2SignedDistanceCost> p1_target_cost(
136 new Polyline2SignedDistanceCost(circle, {kP1XIdx, kP1YIdx}, kAvoid,
139 p1_cost.AddStateCost(p1_target_cost);
142 p1_cost.SetMaxOverTime();
145 inline std::vector<float> OnePlayerReachabilityExample::Xs(
146 const VectorXf& x)
const {
150 inline std::vector<float> OnePlayerReachabilityExample::Ys(
151 const VectorXf& x)
const {
155 inline std::vector<float> OnePlayerReachabilityExample::Thetas(
156 const VectorXf& x)
const {
157 return {x(kP1ThetaIdx)};