87 std::vector<std::pair<double, ControlVector>> delayed_u_seq;
111 delayed_u_seq.clear();
116 for (
int i = 0; i < delayed_u_seq.size(); ++i)
118 double cur_dt = delayed_u_seq[i].first;
129 _dynamics->dynamics(
x, delayed_u_seq[i].second, next_state);
143 if (!sim_rate.
sleep())
146 <<
"ms). Simulation results are probably useless. You might reduce sim_rate.");
154 if (u_sequence->getTimeDimension() < 1)
162 _control = u_sequence->getValuesMap(0);
192 #ifdef MESSAGE_SUPPORT 193 void SimulatedPlantThreaded::toMessage(corbo::messages::SimulatedPlantThreaded& message)
const 195 SimulatedPlant::toMessage(*message.mutable_simulated_plant());
200 void SimulatedPlantThreaded::fromMessage(
const corbo::messages::SimulatedPlantThreaded& message, std::stringstream* issues)
202 SimulatedPlant::fromMessage(message.simulated_plant(), issues);
207 if (issues) *issues <<
"SimulatedPlantThreaded:: sim_rate must be positive" << std::endl;
#define PRINT_ERROR_NAMED(msg)
bool setInitialState(const StateVector &x_init)
Specify an initial state x0 [SystemDynamicsInterface::getStateDimension() x 1].
void appendValues(double t, const Eigen::Ref< const Eigen::VectorXd > &u)
#define PRINT_WARNING_NAMED(msg)
std::mutex _control_mutex
Duration lastCycleTime() const
Return actual execution time of the last cycle.
std::mutex _current_state_mutex
virtual void sendMeasurement(Measurement::ConstPtr measurement)=0
Send a measurement to the target.
StateVector _current_state
SystemOutputInterface::Ptr _output
bool setState(const Eigen::Ref< const Eigen::VectorXd > &state) override
Set/move plant to a desired state (if possible)
NumericalIntegratorExplicitInterface::Ptr _integrator
Interface class for signal targets.
Representation of time stamps.
Adapter class for plant simulation.
std::shared_ptr< SystemOutputInterface > Ptr
bool output(OutputVector &output, const Time &t, SignalTargetInterface *signal_target=nullptr, const std::string &ns="") override
Retrieve current plant output (measurements)
DisturbanceInterface::Ptr _output_disturbance
Rate objects can be used to run loops at a desired rate.
#define PRINT_WARNING_COND(cond, msg)
Print msg-stream only if cond == true.
Eigen::VectorXd StateVector
TimeValueBuffer _time_value_buffer
bool sleep()
Sleep for the remaining duration to met the desired frequency (w.r.t previous sleep call) ...
Eigen::VectorXd ControlVector
A matrix or vector expression mapping an existing expression.
double toSec() const
Return duration in seconds.
SystemDynamicsInterface::Ptr _dynamics
SimulatedPlantThreaded()
Default constructor.
bool initialize() override
Initialize plant.
double toSec() const
Cast time stamp to seconds.
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.
DisturbanceInterface::Ptr _input_disturbance
Eigen::VectorXd OutputVector
bool ok()
global method to check whether to proceed or cancel the current action
void stop() override
Stop plant (you might probably use this to set the plant into a safe setpoint)
std::thread _worker_thread
void getValues(double ts, double dt, std::vector< std::pair< double, Eigen::VectorXd >> &useq_out)
Compute the delayed values.
std::shared_ptr< const TimeSeries > ConstPtr
int getInputDimension() const override
Return the plant input dimension (u)
Representation of time durations.
void setInitialValue(const Eigen::Ref< const Eigen::VectorXd > &uinit)
Specify initial value.
virtual ~SimulatedPlantThreaded()
std::shared_ptr< SystemDynamicsInterface > Ptr