11 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
16 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
21 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
23 const SCALAR& newTimeHorizon,
32 int currentSize = FeedForwardTraj.
size();
35 int Kn_new = std::max(1, (
int)std::lround(newTimeHorizon / dt_));
39 num_di = std::min(num_di, currentSize - 1);
42 #ifdef DEBUG_POLICYHANDLER 43 std::cout <<
"DEBUG_POLICYHANDLER: Controller shifting: " << std::endl
44 <<
"delay: " << delay <<
" newT: " << newTimeHorizon << std::endl
45 <<
" new Discrete Controller has: " << std::endl
46 << Kn_new <<
" control elements, shifted about " << num_di <<
" elements." << std::endl
47 << Kn_new + 1 <<
" state elements, shifted about " << num_di <<
" elements." << std::endl;
54 FeedForwardTraj.
eraseFront(num_di, num_di * dt_);
57 currentSize -= num_di;
62 if (Kn_new > currentSize)
65 bool timeIsRelative =
true;
66 for (
int i = 0;
i < Kn_new - currentSize;
i++)
68 FeedbackTraj.
push_back(FeedbackTraj.
back(), dt_, timeIsRelative);
69 FeedForwardTraj.
push_back(FeedForwardTraj.
back(), dt_, timeIsRelative);
70 StateRefTraj.
push_back(StateRefTraj.
back(), dt_, timeIsRelative);
73 else if (Kn_new < currentSize)
76 for (
int i = 0;
i < currentSize - Kn_new;
i++)
85 if (FeedForwardTraj.
size() == 0)
87 throw std::runtime_error(
"ERROR in StateFeedbackPolicyHandler.h: new policy should not have size 0.");
91 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
94 SCALAR& effectivelyTruncated)
97 size_t currentSize = policy.getFeedforwardTrajectory().size();
99 size_t num_di = policy.getFeedforwardTrajectory().getIndexFromTime(delay);
100 num_di = std::min(num_di, currentSize - 1);
102 effectivelyTruncated = num_di * dt_;
104 #ifdef DEBUG_POLICYHANDLER 105 std::cout <<
"DEBUG_WARMSTART: Current Controller Size: " << currentSize <<
" elements." << std::endl;
106 std::cout <<
"DEBUG_WARMSTART: Controller truncation: truncation about " << num_di <<
" elements." << std::endl;
107 std::cout <<
"DEBUG_WARMSTART: Controller new size: " << currentSize - num_di <<
" elements." << std::endl;
111 if (num_di > 0 && num_di < currentSize)
113 policy.getFeedbackTrajectory().eraseFront(num_di, effectivelyTruncated);
114 policy.getFeedforwardTrajectory().eraseFront(num_di, effectivelyTruncated);
115 policy.getReferenceStateTrajectory().eraseFront(num_di, effectivelyTruncated);
StateFeedbackPolicyHandler(const SCALAR &dt)
Definition: StateFeedbackPolicyHandler-impl.h:12
virtual void truncateSolutionFront(const SCALAR &delay, StateFeedbackController_t &policy, SCALAR &effectivelyTruncated) override
Definition: StateFeedbackPolicyHandler-impl.h:92
const double dt
Definition: LQOCSolverTiming.cpp:18
CppAD::AD< CppAD::cg::CG< double > > SCALAR
for i
Definition: mpc_unittest_plotting.m:14
void eraseFront(const size_t &N, const SCALAR &dt=0.0)
void push_back(const T &data, const SCALAR &time, const bool timeIsAbsolute)
virtual ~StateFeedbackPolicyHandler()
Definition: StateFeedbackPolicyHandler-impl.h:17
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef core::StateFeedbackController< STATE_DIM, CONTROL_DIM, SCALAR > StateFeedbackController_t
Definition: StateFeedbackPolicyHandler.h:21
virtual void designWarmStartingPolicy(const SCALAR &delay, const SCALAR &newTimeHorizon, StateFeedbackController_t &policy) override
Definition: StateFeedbackPolicyHandler-impl.h:22
size_t getIndexFromTime(const SCALAR &t)