Drake
dynamic_constraint.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 
5 #include <Eigen/Core>
6 
7 #include <drake/drakeDynamicConstraint_export.h>
8 #include <drake/core/Gradient.h>
10 #include <drake/systems/System.h>
11 
12 namespace drake {
13 namespace systems {
14 
23 class DRAKEDYNAMICCONSTRAINT_EXPORT DynamicConstraint :
24  public solvers::Constraint {
25  public:
36  DynamicConstraint(int num_states, int num_inputs);
37  virtual ~DynamicConstraint();
38 
39  void eval(const Eigen::Ref<const Eigen::VectorXd>& x,
40  Eigen::VectorXd& y) const override;
41  void eval(const Eigen::Ref<const Drake::TaylorVecXd>& x,
42  Drake::TaylorVecXd& y) const override;
43 
44  protected:
45  virtual void dynamics(const Drake::TaylorVecXd& state,
46  const Drake::TaylorVecXd& input,
47  Drake::TaylorVecXd* xdot) const = 0;
48 
49  private:
50  int num_states_;
51  int num_inputs_;
52 };
53 
56 template <typename System>
58  public:
59  // TODO(sam.creasey) Should this be a const bare ptr?
60  explicit SystemDynamicConstraint(std::shared_ptr<System> system)
62  Drake::getNumInputs(*system)),
63  system_(system) {}
64 
65  private:
66  void dynamics(const Drake::TaylorVecXd& state,
67  const Drake::TaylorVecXd& input,
68  Drake::TaylorVecXd* xdot) const override {
69  typename System::template StateVector<Drake::TaylorVarXd> x = state;
70  typename System::template InputVector<Drake::TaylorVarXd> u = input;
72  t = 0;
73  *xdot = toEigen(system_->dynamics(t, x, u));
74  }
75 
76  std::shared_ptr<System> system_;
77 };
78 
79 } // systems
80 } // drake
std::vector< Number > x
Definition: IpoptSolver.cpp:169
Definition: constants.h:3
StateVector is an abstract base class template for vector quantities within the state of a System...
Definition: state_vector.h:20
NOTE: The contents of this class are for the most part direct ports of drake/systems/plants//inverseK...
Definition: Function.h:14
SystemDynamicConstraint(std::shared_ptr< System > system)
Definition: dynamic_constraint.h:60
static double * t
Definition: inverseKinSnoptBackend.cpp:62
TaylorVecd< Eigen::Dynamic, Eigen::Dynamic > TaylorVecXd
Definition: Gradient.h:26
Provides a base implementation and interface for a dynamic constraint (which is intended to be used w...
Definition: dynamic_constraint.h:23
std::size_t getNumStates(const System &sys)
getNumStates()
Definition: System.h:108
Implements a dynamic constraint which uses the dynamics function of a system.
Definition: dynamic_constraint.h:57
std::size_t getNumInputs(const System &sys)
getNumInputs()
Definition: System.h:135
TaylorVard< Eigen::Dynamic > TaylorVarXd
Definition: Gradient.h:25
A constraint is a function + lower and upper bounds.
Definition: Constraint.h:27
THIS FILE IS DEPRECATED.
TestContinuousSystem system_
Definition: continuous_system_test.cc:50
const Eigen::Matrix< ScalarType, Rows, 1 > & toEigen(const Eigen::Matrix< ScalarType, Rows, 1 > &vec)
Definition: Vector.h:61