59 #include <ilqgames/constraint/polyline2_signed_distance_constraint.h> 60 #include <ilqgames/constraint/single_dimension_constraint.h> 61 #include <ilqgames/cost/extreme_value_cost.h> 62 #include <ilqgames/cost/proximity_cost.h> 63 #include <ilqgames/cost/quadratic_cost.h> 64 #include <ilqgames/cost/quadratic_polyline2_cost.h> 65 #include <ilqgames/dynamics/concatenated_dynamical_system.h> 66 #include <ilqgames/dynamics/single_player_car_5d.h> 67 #include <ilqgames/examples/skeleton_example.h> 68 #include <ilqgames/geometry/draw_shapes.h> 69 #include <ilqgames/geometry/polyline2.h> 70 #include <ilqgames/solver/ilq_solver.h> 71 #include <ilqgames/solver/problem.h> 72 #include <ilqgames/solver/solver_params.h> 73 #include <ilqgames/utils/types.h> 84 static constexpr
float kOmegaMax = 1.5;
85 static constexpr
float kAMax = 4.0;
89 static constexpr
float kOmegaCostWeight = 25.0;
90 static constexpr
float kACostWeight = 15.0;
91 static constexpr
float kNominalVCostWeight = 10.0;
92 static constexpr
float kLaneCostWeight = 25.0;
93 static constexpr
float kProximityCostWeight = 100.0;
97 static constexpr
float kP1NominalV = 8.0;
98 static constexpr
float kP2NominalV = 8.0;
101 static constexpr
float kP1InitialX = 0.0;
102 static constexpr
float kP1InitialY = -30.0;
104 static constexpr
float kP2InitialX = -5.0;
105 static constexpr
float kP2InitialY = 30.0;
107 static constexpr
float kP1InitialTheta = M_PI_2;
108 static constexpr
float kP2InitialTheta = -M_PI_2;
110 static constexpr
float kP1InitialV = 4.0;
111 static constexpr
float kP2InitialV = 3.0;
114 using P1 = SinglePlayerCar5D;
115 using P2 = SinglePlayerCar5D;
117 static const Dimension kP1XIdx = P1::kPxIdx;
118 static const Dimension kP1YIdx = P1::kPyIdx;
119 static const Dimension kP1ThetaIdx = P1::kThetaIdx;
120 static const Dimension kP1VIdx = P1::kVIdx;
122 static const Dimension kP2XIdx = P1::kNumXDims + P2::kPxIdx;
123 static const Dimension kP2YIdx = P1::kNumXDims + P2::kPyIdx;
124 static const Dimension kP2ThetaIdx = P1::kNumXDims + P2::kThetaIdx;
125 static const Dimension kP2VIdx = P1::kNumXDims + P2::kVIdx;
129 void SkeletonExample::ConstructDynamics() {
135 static constexpr
float kInterAxleDistance = 4.0;
136 dynamics_.reset(
new ConcatenatedDynamicalSystem(
137 {std::make_shared<P1>(kInterAxleDistance),
138 std::make_shared<P2>(kInterAxleDistance)}));
141 void SkeletonExample::ConstructInitialState() {
144 x0_ = VectorXf::Zero(dynamics_->XDim());
145 x0_(kP1XIdx) = kP1InitialX;
146 x0_(kP1YIdx) = kP1InitialY;
147 x0_(kP1ThetaIdx) = kP1InitialTheta;
148 x0_(kP1VIdx) = kP1InitialV;
149 x0_(kP2XIdx) = kP2InitialX;
150 x0_(kP2YIdx) = kP2InitialY;
151 x0_(kP2ThetaIdx) = kP2InitialTheta;
152 x0_(kP2VIdx) = kP2InitialV;
155 void SkeletonExample::ConstructPlayerCosts() {
162 player_costs_.emplace_back(
"P1");
163 player_costs_.emplace_back(
"P2");
164 auto& p1_cost = player_costs_[0];
165 auto& p2_cost = player_costs_[1];
168 const auto p1_omega_cost = std::make_shared<QuadraticCost>(
169 kOmegaCostWeight, P1::kOmegaIdx, 0.0,
"OmegaCost");
170 const auto p1_a_cost = std::make_shared<QuadraticCost>(
171 kACostWeight, P1::kAIdx, 0.0,
"AccelerationCost");
172 p1_cost.AddControlCost(0, p1_omega_cost);
173 p1_cost.AddControlCost(0, p1_a_cost);
175 const auto p2_omega_cost = std::make_shared<QuadraticCost>(
176 kOmegaCostWeight, P2::kOmegaIdx, 0.0,
"OmegaCost");
177 const auto p2_a_cost = std::make_shared<QuadraticCost>(
178 kACostWeight, P2::kAIdx, 0.0,
"AccelerationCost");
179 p2_cost.AddControlCost(1, p2_omega_cost);
180 p2_cost.AddControlCost(1, p2_a_cost);
225 const auto p1_nominal_v_cost = std::make_shared<QuadraticCost>(
226 kNominalVCostWeight, kP1VIdx, kP1NominalV,
"NominalV");
227 p1_cost.AddStateCost(p1_nominal_v_cost);
229 const auto p2_nominal_v_cost = std::make_shared<QuadraticCost>(
230 kNominalVCostWeight, kP2VIdx, kP2NominalV,
"NominalV");
231 p2_cost.AddStateCost(p2_nominal_v_cost);
235 const Polyline2 lane1(
236 {Point2(kP1InitialX, -1000.0), Point2(kP1InitialX, 1000.0)});
237 const Polyline2 lane2({Point2(kP2InitialX, 1000.0), Point2(kP2InitialX, 5.0),
238 Point2(kP2InitialX + 5.0, 0.0),
239 Point2(kP2InitialX + 1000.0, 0.0)});
241 const std::shared_ptr<QuadraticPolyline2Cost> p1_lane_cost(
242 new QuadraticPolyline2Cost(kLaneCostWeight, lane1, {kP1XIdx, kP1YIdx},
244 p1_cost.AddStateCost(p1_lane_cost);
246 const std::shared_ptr<QuadraticPolyline2Cost> p2_lane_cost(
247 new QuadraticPolyline2Cost(kLaneCostWeight, lane2, {kP2XIdx, kP2YIdx},
249 p2_cost.AddStateCost(p2_lane_cost);
252 constexpr
float kMinProximity = 6.0;
253 const std::shared_ptr<ProximityCost> p1p2_proximity_cost(
254 new ProximityCost(kProximityCostWeight, {kP1XIdx, kP1YIdx},
255 {kP2XIdx, kP2YIdx}, kMinProximity,
"Proximity"));
256 p1_cost.AddStateCost(p1p2_proximity_cost);
257 p2_cost.AddStateCost(p1p2_proximity_cost);
260 inline std::vector<float> SkeletonExample::Xs(
const VectorXf& x)
const {
261 return {x(kP1XIdx), x(kP2XIdx)};
264 inline std::vector<float> SkeletonExample::Ys(
const VectorXf& x)
const {
265 return {x(kP1YIdx), x(kP2YIdx)};
268 inline std::vector<float> SkeletonExample::Thetas(
const VectorXf& x)
const {
269 return {x(kP1ThetaIdx), x(kP2ThetaIdx)};