pendulum_dynamics_solver.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019, Traiko Dinev
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
31 
33 
34 namespace exotica
35 {
36 PendulumDynamicsSolver::PendulumDynamicsSolver()
37 {
38  num_positions_ = 1;
39  num_velocities_ = 1;
40  num_controls_ = 1;
41 }
42 
43 void PendulumDynamicsSolver::AssignScene(ScenePtr scene_in)
44 {
45  const int num_positions_in = scene_in->GetKinematicTree().GetNumControlledJoints();
46  // TODO: This is a terrible check (not against name etc.), but can stop _some_ mismatches between URDF/model and dynamics
47  if (num_positions_in != 1)
48  ThrowPretty("Robot model may not be a Pendulum.");
49 
50  if (parameters_.FrictionCoefficient < 0)
51  ThrowPretty("Coefficient of friction is less than 0 (" << parameters_.FrictionCoefficient << ").");
52  if (parameters_.FrictionCoefficient > 1.5)
53  WARNING_NAMED("PendulumDynamicsSolver", "Coefficient of friction " << parameters_.FrictionCoefficient << " might be too high!");
54  b_ = parameters_.FrictionCoefficient;
55 }
56 
57 Eigen::VectorXd PendulumDynamicsSolver::f(const StateVector& x, const ControlVector& u)
58 {
59  auto theta = x(0);
60  auto thetadot = x(1);
61 
62  auto x_dot = StateVector(2);
63  x_dot << thetadot,
64  (u(0) - m_ * g_ * l_ * std::sin(theta) - b_ * thetadot) / (m_ * l_ * l_);
65 
66  return x_dot;
67 }
68 
69 // NOTE: tested in test/test_pendulum_diff.py in this package
70 Eigen::MatrixXd PendulumDynamicsSolver::fx(const StateVector& x, const ControlVector& u)
71 {
72  auto theta = x(0);
73 
74  Eigen::Matrix2d fx;
75  fx << 0, 1,
76  -g_ * std::cos(theta) / l_, -b_ / (l_ * l_ * m_);
77 
78  return fx;
79 }
80 
81 // NOTE: tested in test/test_pendulum_diff.py in this package
82 Eigen::MatrixXd PendulumDynamicsSolver::fu(const StateVector& x, const ControlVector& u)
83 {
84  Eigen::Vector2d fu;
85  fu << 0, 1.0 / (l_ * l_ * m_);
86  return fu;
87 }
88 } // namespace exotica
#define REGISTER_DYNAMICS_SOLVER_TYPE(TYPE, DERIV)
#define WARNING_NAMED(name, x)
#define ThrowPretty(m)
std::shared_ptr< Scene > ScenePtr
Eigen::Matrix< T, NU, 1 > ControlVector
Eigen::Matrix< T, NX, 1 > StateVector


exotica_pendulum_dynamics_solver
Author(s): Traiko Dinev
autogenerated on Sat Apr 10 2021 02:35:47