Drake
system3_output.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <stdexcept>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 
9 #include "drake/drakeSystemFramework_export.h"
14 
15 namespace drake {
16 namespace systems {
17 
18 class AbstractSystem3;
19 
35 class OutputPort3 {
36  public:
37  virtual ~OutputPort3() = default;
38 
41 
44  explicit OutputPort3(std::unique_ptr<AbstractValue> model_value)
45  : OutputPort3() {
46  set_model_value(std::move(model_value));
47  }
48 
51  void set_model_value(std::unique_ptr<AbstractValue> model_value) {
52  model_value_ = std::move(model_value);
53  }
54 
57  const AbstractValue& get_model_value() const { return *model_value_; }
58 
61  AbstractValue* get_mutable_model_value() { return model_value_.get(); }
62 
66  std::pair<const AbstractSystem3*, int> get_owner_system() const {
67  return std::pair<const AbstractSystem3*, int>(system_, output_port_num_);
68  }
69 
70  private:
71  // OutputPort3 objects are neither copyable nor moveable.
72  OutputPort3(const OutputPort3& other) = delete;
73  OutputPort3& operator=(const OutputPort3& other) = delete;
74  OutputPort3(OutputPort3&& other) = delete;
75  OutputPort3& operator=(OutputPort3&& other) = delete;
76 
77  friend class AbstractSystem3; // Allow call to set_owner().
78 
79  // Set backpointer; no ownership implied.
80  void set_owner(AbstractSystem3* system, int output_port_num) {
81  system_ = system;
82  output_port_num_ = output_port_num;
83  }
84 
85  // This AbstractSystem is the owner of this OutputPort3, where it has this
86  // port
87  // number.
89  int output_port_num_{-1};
90 
91  std::unique_ptr<AbstractValue> model_value_;
92 
93  // The rate at which this port produces output, in seconds.
94  // If zero, the port is continuous.
95  double sample_time_sec_{0.};
96 };
97 
109 template <typename T>
111  public:
114  explicit VectorOutputPort3(std::unique_ptr<VectorInterface<T>> model_value)
115  : OutputPort3(std::make_unique<Value<VectorObject<T>>>(
116  VectorObject<T>(std::move(model_value)))) {}
117 
120  explicit VectorOutputPort3(int length)
121  : VectorOutputPort3(std::make_unique<BasicVector<T>>(length)) {}
122 
126  const auto& vector_object =
127  get_model_value().template GetValue<VectorObject<T>>();
128  return vector_object.get_vector();
129  }
130 
134  auto vector_object =
135  get_mutable_model_value()->template GetMutableValue<VectorObject<T>>();
136  return vector_object->get_mutable_vector();
137  }
138 
139  private:
140  // VectorOutputPort3 objects are neither copyable nor moveable.
141  VectorOutputPort3(const VectorOutputPort3& other) = delete;
142  VectorOutputPort3& operator=(const VectorOutputPort3& other) = delete;
143  VectorOutputPort3(VectorOutputPort3&& other) = delete;
144  VectorOutputPort3& operator=(VectorOutputPort3&& other) = delete;
145 };
146 
147 } // namespace systems
148 } // namespace drake
VectorInterface is a pure abstract interface that real-valued signals between Systems must satisfy...
Definition: vector_interface.h:25
An OutputPort3 represents a data output from a System.
Definition: system3_output.h:35
std::pair< const AbstractSystem3 *, int > get_owner_system() const
If this OutputPort3 is owned by a system, return that system and the output port number by which that...
Definition: system3_output.h:66
Definition: constants.h:3
AbstractValue * get_mutable_model_value()
Returns a mutable pointer to a value of the type that this OutputPort3 will present at run time...
Definition: system3_output.h:61
STL namespace.
const VectorInterface< T > & get_model_vector() const
Returns the model value of this port as a const reference to VectorInterface<T>.
Definition: system3_output.h:125
Extends OutputPort3 for cases where the OutputPort3 is known to be vector-valued, with scalar element...
Definition: system3_output.h:110
OutputPort3(std::unique_ptr< AbstractValue > model_value)
Create an OutputPort3 with the indicated model value, taking over ownership of the model value...
Definition: system3_output.h:44
OutputPort3()
Create an OutputPort3 that has no model value.
Definition: system3_output.h:40
VectorOutputPort3(int length)
If you supply just a length this port will use a BasicVector of that length as its model value...
Definition: system3_output.h:120
An abstract superclass for dynamical systems, encapsulating functionality that is independent of the ...
Definition: system3.h:68
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
VectorInterface< T > * get_mutable_model_vector()
Returns the model value of this port as a mutable pointer to VectorInterface<T>.
Definition: system3_output.h:133
BasicVector is a semantics-free wrapper around an Eigen vector that satisfies VectorInterface.
Definition: basic_vector.h:23
This concrete class provides object semantics to an abstract VectorInterface by implementing a copy c...
Definition: vector_interface.h:70
A fully type-erased container class.
Definition: value.h:22
VectorOutputPort3(std::unique_ptr< VectorInterface< T >> model_value)
Takes over ownership of the supplied concrete VectorInterface object to serve as the model value for ...
Definition: system3_output.h:114
void set_model_value(std::unique_ptr< AbstractValue > model_value)
Set the model value for this OutputPort3.
Definition: system3_output.h:51
A container class for an arbitrary type T.
Definition: value.h:15
TestContinuousSystem system_
Definition: continuous_system_test.cc:50
virtual ~OutputPort3()=default