simulated_plant.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_PLANTS_INCLUDE_CORBO_PLANTS_SIMULATED_PLANT_H_
26 #define SRC_PLANTS_INCLUDE_CORBO_PLANTS_SIMULATED_PLANT_H_
27 
29 
35 
36 #include <memory>
37 
38 namespace corbo {
39 
56 class SimulatedPlant : public PlantInterface
57 {
58  public:
59  using StateVector = Eigen::VectorXd;
60 
65 
66  // implements interface method
67  Ptr getInstance() const override { return std::make_shared<SimulatedPlant>(); }
68  // implements interface method
69  int getInputDimension() const override { return _dynamics ? _dynamics->getInputDimension() : 0; }
70  // implements interface method
71  int getOutputDimension() const override;
72  // implements interface method
73  bool requiresFutureControls() const override { return false; }
74  // implements interface method
75  bool requiresFutureStates() const override { return false; }
76 
77  // implements interface method
78  // bool control(const ControlVector& u, const Duration& dt, const Time& t, SignalTargetInterface* signal_target = nullptr) override;
79 
80  // implements interface method
81  bool control(const TimeSeries::ConstPtr& u_sequence, const TimeSeries::ConstPtr& x_sequence, const Duration& dt, const Time& t,
82  SignalTargetInterface* signal_target = nullptr, const std::string& ns = "") override;
83 
84  // implements interface method
85  bool output(OutputVector& output, const Time& t, SignalTargetInterface* signal_target = nullptr, const std::string& ns = "") override;
86 
87  // implements interface method
88  void reset() override;
89 
90  // implements interface method
91  bool setState(const Eigen::Ref<const Eigen::VectorXd>& state) override { return setInitialState(state); }
92 
105 
107  bool setInitialState(const StateVector& x_init);
108 
109  // implements interface method
110  void getAvailableSignals(SignalTargetInterface& signal_target, const std::string& ns = "") const override;
111 
112 #ifdef MESSAGE_SUPPORT
113  void toMessage(messages::SimulatedPlant& message) const;
116  void fromMessage(const messages::SimulatedPlant& message, std::stringstream* issues = nullptr);
117 
118  // implements interface method
119  void toMessage(messages::Plant& message) const override { toMessage(*message.mutable_simulated_plant()); }
120  // implements interface method
121  void fromMessage(const messages::Plant& message, std::stringstream* issues = nullptr) override { fromMessage(message.simulated_plant(), issues); }
122 #endif
123 
124  protected:
127 
129 
133 
134  TimeValueBuffer _time_value_buffer;
135 
136  StateVector _initial_state; // just a cache to allow resetting
139 };
140 
142 
143 } // namespace corbo
144 
145 #endif // SRC_PLANTS_INCLUDE_CORBO_PLANTS_SIMULATED_PLANT_H_
corbo::PlantInterface::OutputVector
Eigen::VectorXd OutputVector
Definition: plant_interface.h:104
corbo::SimulatedPlant::reset
void reset() override
Definition: simulated_plant.cpp:219
corbo::SimulatedPlant::setOutputFunction
void setOutputFunction(SystemOutputInterface::Ptr output)
Set the output function of the simulated plant.
Definition: simulated_plant.cpp:192
corbo::SimulatedPlant::setState
bool setState(const Eigen::Ref< const Eigen::VectorXd > &state) override
Set/move plant to a desired state (if possible)
Definition: simulated_plant.h:135
corbo::SimulatedPlant::getInputDimension
int getInputDimension() const override
Return the plant input dimension (u)
Definition: simulated_plant.h:113
corbo::SignalTargetInterface
Interface class for signal targets.
Definition: signal_target_interface.h:84
system_dynamics_interface.h
output_function_interface.h
corbo::SimulatedPlant::control
bool control(const TimeSeries::ConstPtr &u_sequence, const TimeSeries::ConstPtr &x_sequence, const Duration &dt, const Time &t, SignalTargetInterface *signal_target=nullptr, const std::string &ns="") override
Send commands to plant.
Definition: simulated_plant.cpp:113
FACTORY_REGISTER_PLANT
#define FACTORY_REGISTER_PLANT(type)
Definition: plant_interface.h:175
integrator_interface.h
corbo
Definition: communication/include/corbo-communication/utilities.h:37
corbo::NumericalIntegratorExplicitInterface::Ptr
std::shared_ptr< NumericalIntegratorExplicitInterface > Ptr
Definition: integrator_interface.h:205
corbo::SimulatedPlant::getInstance
Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
Definition: simulated_plant.h:111
corbo::SimulatedPlant::_state_disturbance
DisturbanceInterface::Ptr _state_disturbance
Definition: simulated_plant.h:176
corbo::SimulatedPlant::_output
SystemOutputInterface::Ptr _output
Definition: simulated_plant.h:170
corbo::TimeSeries::ConstPtr
std::shared_ptr< const TimeSeries > ConstPtr
Definition: time_series.h:109
corbo::SimulatedPlant::_current_state
StateVector _current_state
Definition: simulated_plant.h:181
corbo::SimulatedPlant::_integrator
NumericalIntegratorExplicitInterface::Ptr _integrator
Definition: simulated_plant.h:172
corbo::PlantInterface::StateVector
Eigen::VectorXd StateVector
Definition: plant_interface.h:103
corbo::PlantInterface::ControlVector
Eigen::VectorXd ControlVector
Definition: plant_interface.h:102
corbo::SimulatedPlant::setSystemDynamics
void setSystemDynamics(SystemDynamicsInterface::Ptr dynamics)
Set the system dynamics of the simulated plant.
Definition: simulated_plant.cpp:184
corbo::SimulatedPlant::setIntegrator
void setIntegrator(NumericalIntegratorExplicitInterface::Ptr integrator)
Set a numerical integrator for continuous-time dynamics.
Definition: simulated_plant.cpp:194
corbo::SimulatedPlant::setStateDisturbance
void setStateDisturbance(DisturbanceInterface::Ptr disturbance)
Set plant state disturbance model.
Definition: simulated_plant.cpp:200
corbo::DisturbanceInterface::Ptr
std::shared_ptr< DisturbanceInterface > Ptr
Definition: disturbance_interface.h:87
corbo::SimulatedPlant::requiresFutureControls
bool requiresFutureControls() const override
Definition: simulated_plant.h:117
corbo::Duration
Representation of time durations.
Definition: time.h:128
corbo::SimulatedPlant::_dynamics
SystemDynamicsInterface::Ptr _dynamics
Definition: simulated_plant.h:169
corbo::SimulatedPlant::_initial_state
StateVector _initial_state
Definition: simulated_plant.h:180
time_value_buffer.h
corbo::SimulatedPlant::_output_disturbance
DisturbanceInterface::Ptr _output_disturbance
Definition: simulated_plant.h:175
corbo::SystemDynamicsInterface::Ptr
std::shared_ptr< SystemDynamicsInterface > Ptr
Definition: system_dynamics_interface.h:91
corbo::SimulatedPlant::_input_disturbance
DisturbanceInterface::Ptr _input_disturbance
Definition: simulated_plant.h:174
corbo::SimulatedPlant::getAvailableSignals
void getAvailableSignals(SignalTargetInterface &signal_target, const std::string &ns="") const override
Retrieve available signals from the plant.
Definition: simulated_plant.cpp:214
corbo::SimulatedPlant::output
bool output(OutputVector &output, const Time &t, SignalTargetInterface *signal_target=nullptr, const std::string &ns="") override
Retrieve current plant output (measurements)
Definition: simulated_plant.cpp:172
plant_interface.h
corbo::SimulatedPlant::requiresFutureStates
bool requiresFutureStates() const override
Definition: simulated_plant.h:119
corbo::SimulatedPlant::_time_value_buffer
TimeValueBuffer _time_value_buffer
Definition: simulated_plant.h:178
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:192
corbo::SimulatedPlant::getOutputDimension
int getOutputDimension() const override
Return the plant output dimension (y)
Definition: simulated_plant.cpp:70
corbo::Time
Representation of time stamps.
Definition: time.h:273
corbo::SimulatedPlant::setInputDisturbance
void setInputDisturbance(DisturbanceInterface::Ptr disturbance)
Set plant input disturbance model.
Definition: simulated_plant.cpp:196
corbo::SimulatedPlant::_current_control
ControlVector _current_control
Definition: simulated_plant.h:182
corbo::SimulatedPlant::SimulatedPlant
SimulatedPlant()
Default constructor.
Definition: simulated_plant.cpp:55
disturbance_interface.h
corbo::SystemOutputInterface::Ptr
std::shared_ptr< SystemOutputInterface > Ptr
Definition: output_function_interface.h:109
corbo::SimulatedPlant::setOutputDisturbance
void setOutputDisturbance(DisturbanceInterface::Ptr disturbance)
Set plant output disturbance model.
Definition: simulated_plant.cpp:198
corbo::SimulatedPlant::setInitialState
bool setInitialState(const StateVector &x_init)
Specify an initial state x0 [SystemDynamicsInterface::getStateDimension() x 1].
Definition: simulated_plant.cpp:202
corbo::SimulatedPlant
Adapter class for plant simulation.
Definition: simulated_plant.h:78
corbo::PlantInterface::Ptr
std::shared_ptr< PlantInterface > Ptr
Definition: plant_interface.h:101
corbo::SimulatedPlant::StateVector
Eigen::VectorXd StateVector
Definition: simulated_plant.h:103


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:14