46 #include <ilqgames/cost/quadratic_cost.h> 47 #include <ilqgames/cost/quadratic_difference_cost.h> 48 #include <ilqgames/dynamics/concatenated_dynamical_system.h> 49 #include <ilqgames/dynamics/single_player_dubins_car.h> 50 #include <ilqgames/examples/dubins_origin_example.h> 51 #include <ilqgames/solver/ilq_solver.h> 52 #include <ilqgames/solver/problem.h> 53 #include <ilqgames/solver/solver_params.h> 54 #include <ilqgames/utils/types.h> 65 static constexpr
float kOmegaCostWeight = 100.0;
66 static constexpr
float kAttractionCostWeight = 10.0;
67 static constexpr
float kGoalCostWeight = 10.0;
70 static constexpr
float kP1InitialX = 0.0;
71 static constexpr
float kP1InitialY = -10.0;
72 static constexpr
float kP1InitialHeading = M_PI - 0.01;
74 static constexpr
float kP2InitialX = 0.0;
75 static constexpr
float kP2InitialY = 10.0;
76 static constexpr
float kP2InitialHeading = 1.5 * M_PI;
78 static constexpr
float kSpeed = 1.0;
81 static constexpr
float kP2GoalX = 0.0;
82 static constexpr
float kP2GoalY = 0.0;
85 using P1 = SinglePlayerDubinsCar;
86 using P2 = SinglePlayerDubinsCar;
88 static const Dimension kP1XIdx = P1::kPxIdx;
89 static const Dimension kP1YIdx = P1::kPyIdx;
90 static const Dimension kP1HeadingIdx = P1::kThetaIdx;
92 static const Dimension kP2XIdx = P1::kNumXDims + P2::kPxIdx;
93 static const Dimension kP2YIdx = P1::kNumXDims + P2::kPyIdx;
94 static const Dimension kP2HeadingIdx = P1::kNumXDims + P2::kThetaIdx;
97 static const Dimension kP1OmegaIdx = 0;
98 static const Dimension kP2OmegaIdx = 0;
101 void DubinsOriginExample::ConstructDynamics() {
102 dynamics_.reset(
new ConcatenatedDynamicalSystem(
103 {std::make_shared<P1>(kSpeed), std::make_shared<P2>(kSpeed)}));
106 void DubinsOriginExample::ConstructInitialState() {
108 x0_ = VectorXf::Zero(dynamics_->XDim());
109 x0_(kP1XIdx) = kP1InitialX;
110 x0_(kP1YIdx) = kP1InitialY;
111 x0_(kP1HeadingIdx) = kP1InitialHeading;
112 x0_(kP2XIdx) = kP2InitialX;
113 x0_(kP2YIdx) = kP2InitialY;
114 x0_(kP2HeadingIdx) = kP2InitialHeading;
117 void DubinsOriginExample::ConstructPlayerCosts() {
119 player_costs_.emplace_back(
"P1");
120 player_costs_.emplace_back(
"P2");
121 auto& p1_cost = player_costs_[0];
122 auto& p2_cost = player_costs_[1];
125 const std::shared_ptr<QuadraticDifferenceCost> p2_attraction_cost =
126 std::shared_ptr<QuadraticDifferenceCost>(
127 new QuadraticDifferenceCost(kAttractionCostWeight, {kP1XIdx, kP1YIdx},
128 {kP2XIdx, kP2YIdx},
"AttractionCost"));
129 p2_cost.AddStateCost(p2_attraction_cost);
132 const auto p1_omega_cost = std::make_shared<QuadraticCost>(
133 kOmegaCostWeight, kP1OmegaIdx, 0.0,
"Steering");
134 p1_cost.AddControlCost(0, p1_omega_cost);
136 const auto p2_omega_cost = std::make_shared<QuadraticCost>(
137 kOmegaCostWeight, kP2OmegaIdx, 0.0,
"Steering");
138 p2_cost.AddControlCost(1, p2_omega_cost);
141 const auto p1_goalx_cost = std::make_shared<QuadraticCost>(
142 kGoalCostWeight, kP2XIdx, kP2GoalX,
"GoalX");
143 const auto p1_goaly_cost = std::make_shared<QuadraticCost>(
144 kGoalCostWeight, kP2YIdx, kP2GoalY,
"GoalY");
145 p1_cost.AddStateCost(p1_goalx_cost);
146 p1_cost.AddStateCost(p1_goaly_cost);
149 inline std::vector<float> DubinsOriginExample::Xs(
const VectorXf& x)
const {
150 return {x(kP1XIdx), x(kP2XIdx)};
153 inline std::vector<float> DubinsOriginExample::Ys(
const VectorXf& x)
const {
154 return {x(kP1YIdx), x(kP2YIdx)};
157 inline std::vector<float> DubinsOriginExample::Thetas(
const VectorXf& x)
const {
158 return {x(kP1HeadingIdx), x(kP2HeadingIdx)};