39 PRINT_ERROR(
"PredictiveController::initialize(): no ocp specified or ocp initialization failed.");
53 if (!
initialize(x, xref, uref, dt, t, sref))
return false;
58 if (!
_ocp)
return false;
66 for (
int i = 0; i <
_num_ocp_iterations; ++i) success =
_ocp->compute(x, xref, uref, sref, t, i == 0, signal_target, xinit, uinit, ns);
70 success = success &&
_ocp->getFirstControlInput(u);
74 _ocp->getTimeSeries(x_sequence, u_sequence);
105 _x_ts->setTimeFromStart(t);
111 _u_ts->setTimeFromStart(t);
117 signal_target.
sendMeasurement(ns +
"prediction/objective", t, {
_ocp->getCurrentObjectiveValue()});
122 #ifdef MESSAGE_SUPPORT 123 void PredictiveController::toMessage(corbo::messages::PredictiveController& message)
const 125 if (
_ocp)
_ocp->toMessage(*message.mutable_optimal_control_problem());
130 void PredictiveController::fromMessage(
const corbo::messages::PredictiveController& message, std::stringstream* issues)
133 if (!message.has_optimal_control_problem())
135 if (issues) *issues <<
"PredictiveController: no optimal control problem specified.\n";
145 util::get_oneof_field_type(message.optimal_control_problem(),
"optimal_control_problem", type,
false);
150 ocp->fromMessage(message.optimal_control_problem(), issues);
155 if (issues) *issues <<
"PredictiveController: unknown optimal control problem specified.\n";
Eigen::VectorXd ControlVector
static Time now()
Retrieve current system time.
ControllerStatistics _statistics
std::shared_ptr< OptimalControlProblemInterface > Ptr
virtual void sendMeasurement(Measurement::ConstPtr measurement)=0
Send a measurement to the target.
Interface class for signal targets.
Representation of time stamps.
void getAvailableSignals(SignalTargetInterface &signal_target, const std::string &ns="") const override
Retrieve available signals from the controller.
OptimalControlProblemInterface::Ptr _ocp
virtual void registerMeasurement(const std::string &unique_name, int value_dimension, const std::vector< std::string > &value_labels={}, bool zero_order_hold=false)=0
Register a measurement type at current target.
virtual void sendTimeSeries(TimeSeriesSignal::Ptr time_series)=0
Send a time series to the target.
void reset() override
Reset internal controller state and caches.
static Factory & instance()
< Retrieve static instance of the factory
bool step(const StateVector &x, ReferenceTrajectoryInterface &xref, ReferenceTrajectoryInterface &uref, const Duration &dt, const Time &t, TimeSeries::Ptr u_sequence, TimeSeries::Ptr x_sequence, SignalTargetInterface *signal_target=nullptr, ReferenceTrajectoryInterface *sref=nullptr, ReferenceTrajectoryInterface *xinit=nullptr, ReferenceTrajectoryInterface *uinit=nullptr, const std::string &ns="") override
double toSec() const
Return duration in seconds.
void setOptimalControlProblem(OptimalControlProblemInterface::Ptr ocp)
Interface class for reference trajectories.
Eigen::VectorXd StateVector
std::shared_ptr< TimeSeries > Ptr
bool _auto_update_prev_control
std::shared_ptr< Derived > create(const std::string &name, bool print_error=true) const
Create a shared instance of the desired object.
Representation of time durations.
void sendSignals(double t, SignalTargetInterface &signal_target, const std::string &ns="") const override
bool initialize(const StateVector &x, ReferenceTrajectoryInterface &expected_xref, ReferenceTrajectoryInterface &expected_uref, const Duration &expected_dt, const Time &t, ReferenceTrajectoryInterface *sref=nullptr) override
Initialize the controller.
virtual void registerTimeSeries(const std::string &unique_name, int value_dimension, bool zero_order_hold=false)=0
Register a time series type at current target.
#define PRINT_ERROR(msg)
Print msg-stream as error msg.