35 const Duration& expected_dt,
const Time& t, ReferenceTrajectoryInterface* sref)
39 PRINT_ERROR(
"PredictiveController::initialize(): no ocp specified or ocp initialization failed.");
48 SignalTargetInterface* signal_target, ReferenceTrajectoryInterface* sref, ReferenceTrajectoryInterface* xinit,
49 ReferenceTrajectoryInterface* uinit,
const std::string& ns)
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);
106 signal_target.sendTimeSeries(ns +
"prediction/x",
_x_ts);
111 _u_ts->setTimeFromStart(t);
112 signal_target.sendTimeSeries(ns +
"prediction/u",
_u_ts);
115 signal_target.sendMeasurement(ns +
"prediction/n", t, {(double)
_ocp->getN()});
116 signal_target.sendMeasurement(ns +
"prediction/first_dt", t, {
_ocp->getFirstDt()});
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";