55 #ifndef ILQGAMES_DYNAMICS_AIR_3D_H 56 #define ILQGAMES_DYNAMICS_AIR_3D_H 58 #include <ilqgames/dynamics/multi_player_dynamical_system.h> 59 #include <ilqgames/utils/types.h> 61 #include <glog/logging.h> 68 Air3D(
float evader_speed,
float pursuer_speed)
69 : evader_speed_(evader_speed),
70 pursuer_speed_(pursuer_speed),
74 VectorXf Evaluate(Time t,
const VectorXf& x,
75 const std::vector<VectorXf>& us)
const;
79 const std::vector<VectorXf>& us)
const;
82 float DistanceBetween(
const VectorXf& x0,
const VectorXf& x1)
const;
85 Dimension UDim(PlayerIndex player_idx)
const {
86 DCHECK(player_idx == 0 || player_idx == 1);
87 return (player_idx == 0) ? kNumU1Dims : kNumU2Dims;
89 PlayerIndex NumPlayers()
const {
return kNumPlayers; }
90 std::vector<Dimension> PositionDimensions()
const {
return {kRxIdx, kRyIdx}; }
93 const float evader_speed_;
94 const float pursuer_speed_;
97 static const Dimension kNumXDims;
98 static const Dimension kRxIdx;
99 static const Dimension kRyIdx;
100 static const Dimension kRThetaIdx;
103 static const PlayerIndex kNumPlayers;
105 static const Dimension kNumU1Dims;
106 static const Dimension kOmega1Idx;
108 static const Dimension kNumU2Dims;
109 static const Dimension kOmega2Idx;
114 inline VectorXf Air3D::Evaluate(Time t,
const VectorXf& x,
115 const std::vector<VectorXf>& us)
const {
116 CHECK_EQ(us.size(), NumPlayers());
119 VectorXf xdot(xdim_);
120 xdot(kRxIdx) = -evader_speed_ + pursuer_speed_ * std::cos(x(kRThetaIdx)) +
121 us[0](kOmega1Idx) * x(kRyIdx);
123 pursuer_speed_ * std::sin(x(kRThetaIdx)) - us[0](kOmega1Idx) * x(kRxIdx);
124 xdot(kRThetaIdx) = us[1](kOmega2Idx) - us[0](kOmega1Idx);
130 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const {
133 const float ctheta = std::cos(x(kRThetaIdx)) * time::kTimeStep;
134 const float stheta = std::sin(x(kRThetaIdx)) * time::kTimeStep;
136 linearization.A(kRxIdx, kRyIdx) += us[0](kOmega1Idx) * time::kTimeStep;
137 linearization.A(kRxIdx, kRThetaIdx) -= pursuer_speed_ * stheta;
139 linearization.A(kRyIdx, kRxIdx) -= us[0](kOmega1Idx) * time::kTimeStep;
140 linearization.A(kRyIdx, kRThetaIdx) += pursuer_speed_ * ctheta;
142 linearization.Bs[0](kRxIdx, kOmega1Idx) = x(kRyIdx) * time::kTimeStep;
143 linearization.Bs[0](kRyIdx, kOmega1Idx) = -x(kRxIdx) * time::kTimeStep;
144 linearization.Bs[0](kRThetaIdx, kOmega1Idx) = -time::kTimeStep;
146 linearization.Bs[1](kRThetaIdx, kOmega2Idx) = time::kTimeStep;
148 return linearization;
151 inline float Air3D::DistanceBetween(
const VectorXf& x0,
152 const VectorXf& x1)
const {
155 LOG(ERROR) <<
"Trying to compute distance between to relative states.";
156 return (x0.head(2) - x1.head(2)).squaredNorm();