Drake
pendulum.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Dense>
4 
5 namespace drake {
6 namespace core {
7 namespace test {
8 
10 template <typename ScalarType = double>
11 class PendulumState { // models the Drake::Vector concept
12  public:
13  PendulumState(void) : theta(0), thetadot(0) {}
14 
15  template <typename Derived>
16  PendulumState( // NOLINT(runtime/explicit) per Drake::Vector.
17  const Eigen::MatrixBase<Derived>& x)
18  : theta(x(0)), thetadot(x(1)) {}
19 
20  template <typename Derived>
21  PendulumState& operator=(const Eigen::MatrixBase<Derived>& x) {
22  theta = x(0);
23  thetadot = x(1);
24  return *this;
25  }
26 
27  friend Eigen::Matrix<ScalarType, 2, 1> toEigen(
28  const PendulumState<ScalarType>& vec) {
29  Eigen::Matrix<ScalarType, 2, 1> x;
30  x << vec.theta, vec.thetadot;
31  return x;
32  }
33 
34  static const int RowsAtCompileTime = 2;
35 
36  ScalarType theta;
37  ScalarType thetadot;
38 };
39 
41 template <typename ScalarType = double>
43  public:
44  PendulumInput(void) : tau(0) {}
45 
46  template <typename Derived>
47  explicit PendulumInput( // NOLINT(runtime/explicit) per Drake::Vector.
48  const Eigen::MatrixBase<Derived>& x)
49  : tau(x(0)) {}
50 
51  template <typename Derived>
52  PendulumInput& operator=(const Eigen::MatrixBase<Derived>& x) {
53  tau = x(0);
54  return *this;
55  }
56 
57  static const int RowsAtCompileTime = 1;
58 
59  ScalarType tau;
60 };
61 
62 } // namespace test
63 } // namespace core
64 } // namespace drake
A simple Drake input for unit testing.
Definition: pendulum.h:42
PendulumState & operator=(const Eigen::MatrixBase< Derived > &x)
Definition: pendulum.h:21
PendulumInput(const Eigen::MatrixBase< Derived > &x)
Definition: pendulum.h:47
std::vector< Number > x
Definition: IpoptSolver.cpp:169
Definition: constants.h:3
PendulumState(const Eigen::MatrixBase< Derived > &x)
Definition: pendulum.h:16
static const int RowsAtCompileTime
Definition: pendulum.h:34
ScalarType thetadot
Definition: pendulum.h:37
ScalarType theta
Definition: pendulum.h:36
friend Eigen::Matrix< ScalarType, 2, 1 > toEigen(const PendulumState< ScalarType > &vec)
Definition: pendulum.h:27
A simple Drake state for unit testing.
Definition: pendulum.h:11
PendulumInput(void)
Definition: pendulum.h:44
PendulumInput & operator=(const Eigen::MatrixBase< Derived > &x)
Definition: pendulum.h:52
ScalarType tau
Definition: pendulum.h:59
PendulumState(void)
Definition: pendulum.h:13