48 #ifndef ILQGAMES_DYNAMICS_TWO_PLAYER_UNICYCLE_4D_H 49 #define ILQGAMES_DYNAMICS_TWO_PLAYER_UNICYCLE_4D_H 51 #include <ilqgames/dynamics/multi_player_dynamical_system.h> 52 #include <ilqgames/utils/types.h> 54 #include <glog/logging.h> 64 VectorXf Evaluate(Time t,
const VectorXf& x,
65 const std::vector<VectorXf>& us)
const;
69 const std::vector<VectorXf>& us)
const;
72 float DistanceBetween(
const VectorXf& x0,
const VectorXf& x1)
const;
75 std::vector<Dimension> PositionDimensions()
const {
return {kPxIdx, kPyIdx}; }
78 Dimension UDim(PlayerIndex player_idx)
const {
79 DCHECK(player_idx == 0 || player_idx == 1);
80 return (player_idx == 0) ? kNumU1Dims : kNumU2Dims;
82 PlayerIndex NumPlayers()
const {
return kNumPlayers; }
85 static const Dimension kNumXDims;
86 static const Dimension kPxIdx;
87 static const Dimension kPyIdx;
88 static const Dimension kThetaIdx;
89 static const Dimension kVIdx;
92 static const PlayerIndex kNumPlayers;
94 static const Dimension kNumU1Dims;
95 static const Dimension kOmegaIdx;
96 static const Dimension kAIdx;
98 static const Dimension kNumU2Dims;
99 static const Dimension kDxIdx;
100 static const Dimension kDyIdx;
105 inline VectorXf TwoPlayerUnicycle4D::Evaluate(
106 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const {
107 CHECK_EQ(us.size(), NumPlayers());
110 VectorXf xdot(xdim_);
111 xdot(kPxIdx) = x(kVIdx) * std::cos(x(kThetaIdx)) + us[1](kDxIdx);
112 xdot(kPyIdx) = x(kVIdx) * std::sin(x(kThetaIdx)) + us[1](kDyIdx);
113 xdot(kThetaIdx) = us[0](kOmegaIdx);
114 xdot(kVIdx) = us[0](kAIdx);
120 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const {
123 const float ctheta = std::cos(x(kThetaIdx)) * time::kTimeStep;
124 const float stheta = std::sin(x(kThetaIdx)) * time::kTimeStep;
126 linearization.A(kPxIdx, kThetaIdx) += -x(kVIdx) * stheta;
127 linearization.A(kPxIdx, kVIdx) += ctheta;
129 linearization.A(kPyIdx, kThetaIdx) += x(kVIdx) * ctheta;
130 linearization.A(kPyIdx, kVIdx) += stheta;
132 linearization.Bs[0](kThetaIdx, kOmegaIdx) = time::kTimeStep;
133 linearization.Bs[0](kVIdx, kAIdx) = time::kTimeStep;
135 linearization.Bs[1](kPxIdx, kDxIdx) = time::kTimeStep;
136 linearization.Bs[1](kPyIdx, kDyIdx) = time::kTimeStep;
138 return linearization;
141 inline float TwoPlayerUnicycle4D::DistanceBetween(
const VectorXf& x0,
142 const VectorXf& x1)
const {
144 const float dx = x0(kPxIdx) - x1(kPxIdx);
145 const float dy = x0(kPyIdx) - x1(kPyIdx);
146 return dx * dx + dy * dy;