Drake
vector_constant3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 #include <memory>
5 
12 
13 namespace drake {
14 namespace systems {
15 
20 template <typename T>
21 class VectorConstant3 : public System3<T> {
22  public:
25  VectorConstant3(const std::string& name,
26  std::unique_ptr<VectorInterface<T>> value)
27  : System3<T>(name) {
28  // Provide this as the "model value" for the output port.
29  auto port = std::make_unique<VectorOutputPort3<T>>(std::move(value));
30  this->AddOutputPort(std::move(port));
31  }
32 
35  VectorConstant3(const std::string& name,
36  const Eigen::Ref<const VectorX<T>>& vector)
37  : VectorConstant3(name, MakeBasicVector(vector)) {}
38 
41  VectorConstant3(const std::string& name,
42  const T& scalar_value)
43  : VectorConstant3(name, Vector1<T>::Constant(scalar_value)) {}
44 
45  private:
46  static std::unique_ptr<BasicVector<T>> MakeBasicVector(
47  const Eigen::Ref<const VectorX<T>>& vector) {
48  auto basic_vector = std::make_unique<BasicVector<T>>((int)vector.rows());
49  basic_vector->get_mutable_value() = vector;
50  return basic_vector;
51  }
52 
53  // Implement System<T> interface.
54 
55  std::unique_ptr<AbstractContext3> DoCreateEmptyContext() const override {
56  return std::make_unique<Context3<T>>();
57  }
58 
59  // Don't need any additional resources.
60 
61  // Calculation consists just of copying the model value to the output.
62  void DoCalcOutputPort(const AbstractContext3& /*context*/,
63  int port_num, AbstractValue* result) const override {
64  *result = this->get_output_port(port_num).get_model_value();
65  }
66 };
67 
68 } // namespace systems
69 } // namespace drake
VectorInterface is a pure abstract interface that real-valued signals between Systems must satisfy...
Definition: vector_interface.h:25
An abstract superclass for the Context3 objects for dynamical systems, encapsulating functionality th...
Definition: context3.h:87
A superclass template for systems that use a specified scalar type T for numerical values...
Definition: system3.h:481
Definition: constants.h:3
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorX
A column vector of any size, templated on scalar type.
Definition: eigen_types.h:36
Eigen::Matrix< Scalar, 1, 1 > Vector1
A column vector of size 1 (a scalar), templated on scalar type.
Definition: eigen_types.h:16
VectorConstant3(const std::string &name, const Eigen::Ref< const VectorX< T >> &vector)
Given an Eigen vector value, create a BasicVector containing that value as the output of this system...
Definition: vector_constant3.h:35
VectorConstant3(const std::string &name, std::unique_ptr< VectorInterface< T >> value)
Takes over ownership of the given VectorInterface, which will be regurgitated as the value of the Out...
Definition: vector_constant3.h:25
int AddOutputPort(std::unique_ptr< OutputPort3 > port)
Add an output port that is to be owned by this System.
Definition: system3.h:99
const AbstractValue & get_model_value() const
Returns a const reference to a value of the type that this OutputPort3 will present at run time...
Definition: system3_output.h:57
std::vector< Number > result
Definition: IpoptSolver.cpp:170
const OutputPort3 & get_output_port(int port_num) const
Returns a const reference to the OutputPort3 with the given port number.
Definition: system3.h:130
A fully type-erased container class.
Definition: value.h:22
VectorConstant3(const std::string &name, const T &scalar_value)
Given a scalar, create a one-element BasicVector containing that value as the output of this system...
Definition: vector_constant3.h:41
This System produces a constant VectorInterface value on its single OutputPort.
Definition: vector_constant3.h:21