Drake
cascade3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
8 
9 namespace drake {
10 namespace systems {
11 
19 template <typename T>
20 class Cascade3 : public Diagram3<T> {
21  public:
29  Cascade3(const std::string& name, std::unique_ptr<System3<T>> first,
30  std::unique_ptr<System3<T>> second)
31  : Diagram3<T>(name) {
32  if (!first || !second)
33  throw std::logic_error("Cascade: empty Systems not allowed.");
34 
35  const int out1 = first->get_num_output_ports();
36  const int in2 = second->get_num_input_ports();
37 
38  if (in2 != out1) {
39  throw std::logic_error(
40  "Cascade3: first System has "
41  + std::to_string(out1) + " output ports but second System has "
42  + std::to_string(in2) + " input ports. They must match.");
43  }
44 
45  auto first_system = this->AddSubsystem(std::move(first));
46  auto second_system = this->AddSubsystem(std::move(second));
47 
48  // Input port numbers for Cascade match first system's.
49  for (int port = 0; port < first_system->get_num_input_ports(); ++port) {
50  const int port_num = this->InheritInputPort(first_system, port);
51  DRAKE_ABORT_UNLESS(port_num == port);
52  }
53 
54  // Connect up the interior ports.
55  for (int port = 0; port < out1; ++port)
56  this->Connect(first_system, port, second_system, port);
57 
58  // Output port numbers for Cascade match second system's.
59  for (int port = 0; port < second_system->get_num_output_ports(); ++port) {
60  const int port_num = this->InheritOutputPort(second_system, port);
61  DRAKE_ABORT_UNLESS(port_num == port);
62  }
63  }
64 };
65 
66 } // namespace systems
67 } // namespace drake
A superclass template for systems that use a specified scalar type T for numerical values...
Definition: system3.h:481
void Connect(AbstractSystem3 *source_subsystem, int output_port_num, AbstractSystem3 *sink_subsystem, int input_port_num)
Connect the given output port of subsystem 1 into the given input port of subsystem 2...
Definition: system3.h:224
Definition: constants.h:3
int InheritInputPort(AbstractSystem3 *child_subsystem, int input_port_num)
The given subsystem&#39;s InputPort3 becomes the next InputPort3 of this system diagram.
Definition: system3.h:194
ConcreteSystem * AddSubsystem(std::unique_ptr< ConcreteSystem > subsystem)
Takes ownership of the given system and returns an unowned, raw pointer to the concrete type for conv...
Definition: system3.h:183
Cascade3(const std::string &name, std::unique_ptr< System3< T >> first, std::unique_ptr< System3< T >> second)
Takes over ownership of the two System objects and connects the outputs of first to the inputs of sec...
Definition: cascade3.h:29
#define DRAKE_ABORT_UNLESS(condition)
Evaluates condition and iff the value is false will ::abort() the program with a message showing at l...
Definition: drake_assert.h:39
A Diagram is a concrete System that contains other System objects as subsystems and wires them togeth...
Definition: diagram3.h:23
std::string to_string(const Eigen::MatrixBase< Derived > &a)
Definition: testUtil.h:29
int InheritOutputPort(AbstractSystem3 *child_subsystem, int output_port_num)
The given subsystem&#39;s OutputPort3 becomes the next OutputPort3 of this system diagram.
Definition: system3.h:208
A Cascade is a concrete SystemDiagram containing exactly two compatible subsystems with the output of...
Definition: cascade3.h:20