52 #ifndef ILQGAMES_DYNAMICS_SINGLE_PLAYER_CAR_5D_H 53 #define ILQGAMES_DYNAMICS_SINGLE_PLAYER_CAR_5D_H 55 #include <ilqgames/dynamics/single_player_dynamical_system.h> 56 #include <ilqgames/utils/types.h> 65 inter_axle_distance_(inter_axle_distance) {}
68 VectorXf Evaluate(Time t,
const VectorXf& x,
const VectorXf& u)
const;
71 void Linearize(Time t,
const VectorXf& x,
const VectorXf& u,
72 Eigen::Ref<MatrixXf> A, Eigen::Ref<MatrixXf> B)
const;
75 float DistanceBetween(
const VectorXf& x0,
const VectorXf& x1)
const;
78 std::vector<Dimension> PositionDimensions()
const {
return {kPxIdx, kPyIdx}; }
81 static const Dimension kNumXDims;
82 static const Dimension kPxIdx;
83 static const Dimension kPyIdx;
84 static const Dimension kThetaIdx;
85 static const Dimension kPhiIdx;
86 static const Dimension kVIdx;
89 static const Dimension kNumUDims;
90 static const Dimension kOmegaIdx;
91 static const Dimension kAIdx;
95 const float inter_axle_distance_;
100 inline VectorXf SinglePlayerCar5D::Evaluate(Time t,
const VectorXf& x,
101 const VectorXf& u)
const {
102 VectorXf xdot(xdim_);
103 xdot(kPxIdx) = x(kVIdx) * std::cos(x(kThetaIdx));
104 xdot(kPyIdx) = x(kVIdx) * std::sin(x(kThetaIdx));
105 xdot(kThetaIdx) = (x(kVIdx) / inter_axle_distance_) * std::tan(x(kPhiIdx));
106 xdot(kPhiIdx) = u(kOmegaIdx);
107 xdot(kVIdx) = u(kAIdx);
112 inline void SinglePlayerCar5D::Linearize(Time t,
113 const VectorXf& x,
const VectorXf& u,
114 Eigen::Ref<MatrixXf> A,
115 Eigen::Ref<MatrixXf> B)
const {
116 const float ctheta = std::cos(x(kThetaIdx)) * time::kTimeStep;
117 const float stheta = std::sin(x(kThetaIdx)) * time::kTimeStep;
118 const float cphi = std::cos(x(kPhiIdx));
119 const float tphi = std::tan(x(kPhiIdx));
121 A(kPxIdx, kThetaIdx) += -x(kVIdx) * stheta;
122 A(kPxIdx, kVIdx) += ctheta;
124 A(kPyIdx, kThetaIdx) += x(kVIdx) * ctheta;
125 A(kPyIdx, kVIdx) += stheta;
127 A(kThetaIdx, kPhiIdx) +=
128 x(kVIdx) * time::kTimeStep / (inter_axle_distance_ * cphi * cphi);
129 A(kThetaIdx, kVIdx) += tphi * time::kTimeStep / inter_axle_distance_;
131 B(kPhiIdx, kOmegaIdx) = time::kTimeStep;
132 B(kVIdx, kAIdx) = time::kTimeStep;
135 inline float SinglePlayerCar5D::DistanceBetween(
const VectorXf& x0,
136 const VectorXf& x1)
const {
138 const float dx = x0(kPxIdx) - x1(kPxIdx);
139 const float dy = x0(kPyIdx) - x1(kPyIdx);
140 return dx * dx + dy * dy;