36 CartpoleDynamicsSolver::CartpoleDynamicsSolver()
41 has_second_order_derivatives_ =
true;
44 void CartpoleDynamicsSolver::AssignScene(
ScenePtr scene_in)
46 const int num_positions_in = scene_in->GetKinematicTree().GetNumControlledJoints();
48 if (num_positions_in != 2)
54 const double&
theta = x(1);
55 const double&
xdot = x(2);
56 const double& thetadot = x(3);
60 auto theta_dot_squared = thetadot * thetadot;
63 x_dot <<
xdot, thetadot,
64 (
u(0) +
m_p_ * sin_theta * (
l_ * theta_dot_squared +
g_ * cos_theta)) /
65 (
m_c_ +
m_p_ * sin_theta * sin_theta),
66 -(
l_ *
m_p_ * cos_theta * sin_theta * theta_dot_squared +
u(0) * cos_theta +
76 const double&
theta = x(1);
77 const double&
tdot = x(3);
87 -2 *
m_p_ * (
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * sin_theta +
u(0)) * sin_theta * cos_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2) + (-
g_ *
m_p_ * sin_theta * sin_theta +
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * cos_theta) / (
m_c_ +
m_p_ * sin_theta * sin_theta),
89 2 *
l_ *
m_p_ * tdot * sin_theta / (
m_c_ +
m_p_ * sin_theta * sin_theta),
92 -2 *
l_ *
m_p_ * (-
g_ * (
m_c_ +
m_p_) * sin_theta -
l_ *
m_p_ * tdot * tdot * sin_theta * cos_theta -
u(0) * cos_theta) * sin_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) + (-
g_ * (
m_c_ +
m_p_) * cos_theta +
l_ *
m_p_ * tdot * tdot * sin_theta * sin_theta -
l_ *
m_p_ * tdot * tdot * cos_theta * cos_theta +
u(0) * sin_theta) / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta),
94 -2 *
l_ *
m_p_ * tdot * sin_theta * cos_theta / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta);
102 const double&
theta = x(1);
108 fu << 0, 0, 1 / (
m_c_ +
m_p_ * sin_theta * sin_theta), -cos_theta / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta);
119 const double&
theta = x(1);
120 const double&
tdot = x(3);
125 Eigen::Tensor<double, 3>
fxx(num_positions_ + num_velocities_, num_positions_ + num_velocities_, num_positions_ + num_velocities_);
126 fxx.setValues({{{0, 0, 0, 0},
133 8 *
m_p_ *
m_p_ * (
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * sin_theta +
u(0)) * sin_theta * sin_theta * cos_theta * cos_theta /
134 std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 3) -
135 4 *
m_p_ * (-
g_ *
m_p_ * sin_theta * sin_theta +
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * cos_theta) * sin_theta * cos_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2) +
136 2 *
m_p_ * (
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * sin_theta +
u(0)) * sin_theta * sin_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2) - 2 *
m_p_ * (
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * sin_theta +
u(0)) * cos_theta * cos_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2) + (-3 *
g_ *
m_p_ * sin_theta * cos_theta -
m_p_ * (
g_ * cos_theta +
l_ * tdot *
tdot) * sin_theta) / (
m_c_ +
m_p_ * sin_theta * sin_theta),
138 -4 *
l_ *
m_p_ *
m_p_ * tdot * sin_theta * sin_theta * cos_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2) + 2 *
l_ *
m_p_ * tdot * cos_theta / (
m_c_ +
m_p_ * sin_theta * sin_theta)},
140 8 *
l_ *
l_ *
m_p_ *
m_p_ * (-
g_ * (
m_c_ +
m_p_) * sin_theta -
l_ *
m_p_ * tdot * tdot * sin_theta * cos_theta -
u(0) * cos_theta) * sin_theta * sin_theta * cos_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 3) + 2 *
l_ *
m_p_ * (-
g_ * (
m_c_ +
m_p_) * sin_theta -
l_ *
m_p_ * tdot * tdot * sin_theta * cos_theta -
u(0) * cos_theta) * sin_theta * sin_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) - 2 *
l_ *
m_p_ * (-
g_ * (
m_c_ +
m_p_) * sin_theta -
l_ *
m_p_ * tdot * tdot * sin_theta * cos_theta -
u(0) * cos_theta) * cos_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) - 4 *
l_ *
m_p_ * (-
g_ * (
m_c_ +
m_p_) * cos_theta +
l_ *
m_p_ * tdot * tdot * sin_theta * sin_theta -
l_ *
m_p_ * tdot * tdot * cos_theta * cos_theta +
u(0) * sin_theta) * sin_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) + (
g_ * (
m_c_ +
m_p_) * sin_theta + 4 *
l_ *
m_p_ * tdot * tdot * sin_theta * cos_theta +
u(0) * cos_theta) / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta),
142 4 *
l_ *
l_ *
m_p_ *
m_p_ * tdot * sin_theta * sin_theta * cos_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) + 2 *
l_ *
m_p_ * tdot * sin_theta * sin_theta / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta) - 2 *
l_ *
m_p_ * tdot * cos_theta * cos_theta / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta)}},
150 -4 *
l_ *
m_p_ *
m_p_ * tdot * sin_theta * sin_theta * cos_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2) + 2 *
l_ *
m_p_ * tdot * cos_theta / (
m_c_ +
m_p_ * sin_theta * sin_theta),
151 0, 2 *
l_ *
m_p_ * sin_theta / (
m_c_ +
m_p_ * sin_theta * sin_theta)},
153 4 *
l_ *
l_ *
m_p_ *
m_p_ * tdot * sin_theta * sin_theta * cos_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) +
154 (2 *
l_ *
m_p_ * tdot * sin_theta * sin_theta - 2 *
l_ *
m_p_ * tdot * cos_theta * cos_theta) / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta),
155 0, -2 *
l_ *
m_p_ * sin_theta * cos_theta / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta)}}});
161 const double&
theta = x(1);
166 Eigen::Tensor<double, 3>
fxu(num_positions_ + num_velocities_, num_positions_ + num_velocities_, num_controls_);
167 fxu.setValues({{{0, 0, 0, 0},
169 {0, -2 *
m_p_ * sin_theta * cos_theta / std::pow(
m_c_ +
m_p_ * sin_theta * sin_theta, 2), 0, 0},
170 {0, 2 *
l_ *
m_p_ * sin_theta * cos_theta * cos_theta / std::pow(
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta, 2) + sin_theta / (
l_ *
m_c_ +
l_ *
m_p_ * sin_theta * sin_theta),
#define REGISTER_DYNAMICS_SOLVER_TYPE(TYPE, DERIV)
std::shared_ptr< Scene > ScenePtr
Eigen::Matrix< T, NU, 1 > ControlVector
Eigen::Matrix< T, NX, 1 > StateVector