ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
lq_oc_single_shooting.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 #include <adore/mad/adoremath.h>
18 #include <vector>
19 #include <qpOASES.hpp>
20 
21 namespace adore
22 {
23  namespace mad
24  {
31  template<typename T,int d>//degree
32  void define_integrator_chain(dlib::matrix<T,d,d>& Ad,dlib::matrix<T,d,1>& Bd,T dt)
33  {
34  Ad = dlib::zeros_matrix(Ad);
35  T q[d+1]; q[0]=(T)1;
36  T pow_dt[d+1]; pow_dt[0]=(T)1;
37  for(int i=1;i<=d;i++)
38  {
39  q[i] = q[i-1]/(T)i;
40  pow_dt[i] = pow_dt[i-1] * dt;
41  }
42  for(int i=0;i<d;i++)
43  {
44  for(int j=i;j<d;j++)
45  {
46  Ad(i,j) = q[j-i]*pow_dt[j-i];
47  }
48  Bd(i) = q[d-i]*pow_dt[d-i];
49  }
50  }
51 
52 
59  template<int N, int R, int K,int P>//real_t=float/double,#x=N,#u=R,#T=K,#Tint=K*P
61  {
62  public:
63  typedef qpOASES::real_t real_t;
64  static const int nV = R*K + N;
65  static const int nC = 2*N*K;
66  typedef dlib::matrix<real_t,N,N> t_Ad;
67  typedef dlib::matrix<real_t,N,R> t_Bd;
69  //weights for cost function
70  typedef dlib::matrix<real_t,N,1> t_wx;
71  typedef dlib::matrix<real_t,N,1> t_wx_end;
72  typedef dlib::matrix<real_t,R,1> t_wu;
73  typedef dlib::matrix<real_t,R,1> t_wu_end;
74  typedef dlib::matrix<real_t,N,1> t_weps;
75  typedef dlib::matrix<real_t,N,1> t_geps;
76  //online data: bounds
77  typedef dlib::matrix<real_t,N,K> t_lbx;
78  typedef dlib::matrix<real_t,N,K> t_ubx;
79  typedef dlib::matrix<real_t,R,K> t_lbu;
80  typedef dlib::matrix<real_t,R,K> t_ubu;
81  typedef dlib::matrix<real_t,R,K> t_lbu_hard;
82  typedef dlib::matrix<real_t,R,K> t_ubu_hard;
83  typedef dlib::matrix<real_t,N,1> t_ubeps;
84  //state and reference
85  typedef dlib::matrix<real_t,N,1> t_x0;
86  typedef dlib::matrix<real_t,N,K> t_y;
87  typedef dlib::matrix<real_t,N*K,1> t_y_flat;
88  typedef dlib::matrix<real_t,R,K> t_uset;
89  typedef dlib::matrix<real_t,R*K,1> t_uset_flat;
90  //output
91  typedef dlib::matrix<real_t,R,K> t_U;
92  typedef dlib::matrix<real_t,R*K,1> t_U_flat;
93  typedef dlib::matrix<real_t,N,K+1> t_X;
94  typedef dlib::matrix<real_t,N*(K+1),1> t_X_flat;
95  typedef dlib::matrix<real_t,N,1> t_eps;
96 
97  private://state of this object
99  private://data, which must be provided by user
100  //discrete time system matrices
105  std::vector<t_Ad*> m_Ad_powers;
107  //weights for cost function
114  //online data: bounds
120  //online data: x0, y
124  //output
132 
133  private://intermediate matrices
134  dlib::matrix<real_t,N*K,1> m_E;
135  dlib::matrix<real_t,N*K,R*K> m_F;
136  dlib::matrix<real_t,N*K,N*K> m_Hx;
137  dlib::matrix<real_t,R*K,R*K> m_Hu;
138  dlib::matrix<real_t,N,N> m_Heps;
139  dlib::matrix<real_t,R*K,1> m_g1;
140  dlib::matrix<real_t,R*K,R*K> m_H11;
141 
142  dlib::matrix<real_t,N*K,nV> m_A1;
143  dlib::matrix<real_t,N*K,nV> m_A2;
144  private://variables for qpOASES interfacing
145  qpOASES::QProblem* m_qproblem;
154  qpOASES::int_t m_qpnWSR_in;
155  qpOASES::int_t m_qpnWSR_out;
158  private://methods for intermediate matrix setup
160  {
161  m_Ad = dlib::identity_matrix<real_t>(N);
162  m_Bd = dlib::zeros_matrix(m_Bd);
163  m_wx = dlib::ones_matrix(m_wx);
164  m_wu = dlib::ones_matrix(m_wu);
165  m_wx_end = dlib::ones_matrix(m_wx_end);
166  m_wu_end = dlib::ones_matrix(m_wu_end);
167  m_weps = dlib::zeros_matrix(m_weps);
168  m_geps = dlib::ones_matrix(m_geps);
169  m_lbx = -dlib::ones_matrix(m_lbx);
170  m_ubx = dlib::ones_matrix(m_ubx);
171  m_lbu_hard = -dlib::ones_matrix(m_lbu_hard);
172  m_ubu_hard = dlib::ones_matrix(m_ubu_hard);
173  m_ubeps = ((real_t)1e-6) * dlib::ones_matrix(m_ubeps);
174  m_x0 = dlib::zeros_matrix(m_x0);
175  m_y = dlib::zeros_matrix(m_y);
176  m_X = dlib::zeros_matrix(m_X);
177  m_X_flat = dlib::zeros_matrix(m_X_flat);
178  m_U = dlib::zeros_matrix(m_U);
179  m_U_flat = dlib::zeros_matrix(m_U_flat);
180  m_uset = dlib::zeros_matrix(m_uset);
181  m_uset_flat = dlib::zeros_matrix(m_uset_flat);
182  }
184  {
185  m_Ad_powers.clear();
186  for(int i=0;i<=K;i++)
187  {
188  auto M = new dlib::matrix<real_t,N,N>();
189  *M = dlib::identity_matrix<real_t>(N);
190  m_Ad_powers.push_back(M);
191  }
192  m_qproblem = new qpOASES::QProblem(nV,nC);
193  }
195  {
196  for(auto it = m_Ad_powers.begin();it!=m_Ad_powers.end();it++)
197  {
198  delete *it;
199  }
200  m_Ad_powers.clear();
201  delete m_qproblem;
202  }
204  {
205  for(int i=0;i<nV*nV;i++)m_qpH[i]=(real_t)0.0;
206  for(int i=0;i<nC*nV;i++)m_qpA[i]=(real_t)0.0;
207  for(int i=0;i<nV;i++)m_qplb[i]=(real_t)0.0;
208  }
209 
214  {
215  m_F = dlib::zeros_matrix(m_F);
216  m_Hx = dlib::zeros_matrix(m_Hx);
217  m_Hu = dlib::zeros_matrix(m_Hu);
218  m_Heps = dlib::zeros_matrix(m_Heps);
222  m_A1 = dlib::zeros_matrix(m_A1);
223  for(int i=0;i<K;i++)
224  {
225  for(int j=0;j<N;j++)
226  {
227  m_A1(i*N+j,R*K + j) = (real_t)-1;
228  }
229  }
233  m_A2 = dlib::zeros_matrix(m_A2);
234  for(int i=0;i<K;i++)
235  {
236  for(int j=0;j<N;j++)
237  {
238  m_A2(i*N+j,R*K + j) = (real_t)1;
239  }
240  }
241 
242  }
243 
244  void updateAd()
245  {
246  for(int i=1;i<=K;i++)
247  {
248  (*m_Ad_powers[i]) = (*m_Ad_powers[i-1])*m_Ad;
249  }
250  }
251 
258  void updateE()
259  {
260  for(int i=0;i<K;i++)
261  {
262  dlib::set_rowm(m_E,dlib::range(i*N,i*N+N-1)) = (*m_Ad_powers[i+1]) * m_x0;
263  }
264  }
273  void updateF()
274  {
275  for(int i=0;i<K;i++)
276  {
277  auto Ad_pow_i_Bd = (*m_Ad_powers[i])*m_Bd;//block to be repeated through (sub)-diagonal
278  for(int j=0;j+i<K;j++)
279  {
280 
281  auto rows = dlib::range((i+j)*N,(i+j)*N+N-1);
282  auto cols = dlib::range(j*R,j*R+R-1);
283  dlib::set_subm(m_F,rows,cols) = Ad_pow_i_Bd;
284  }
285  }
286  }
288  void updateHx()
289  {
290  for(int i=0;i<K;i++)
291  {
292  for(int j=0;j<N;j++)
293  {
294  m_Hx(i*N+j,i*N+j) = m_wx(j);
295  }
296  }
297  //endpoint
298  for(int j=0;j<N;j++)
299  {
300  m_Hx((K-1)*N+j,(K-1)*N+j) = m_wx_end(j);
301  }
302 
303  }
305  void updateHu()
306  {
307  for(int i=0;i<K;i++)
308  {
309  for(int j=0;j<R;j++)
310  {
311  m_Hu(i*R+j,i*R+j) = m_wu(j);
312  }
313  }
314  //endpoint
315  for(int j=0;j<R;j++)
316  {
317  m_Hu((K-1)*R+j,(K-1)*R+j) = m_wu(j);
318  }
319  }
321  void updateHeps()
322  {
323  for(int i=0;i<N;i++)
324  {
325  m_Heps(i,i) = m_weps(i);
326  }
327  }
331  void updateg1()
332  {
333  //copy m_y to m_y_flat
334  for(int i=0;i<N;i++)
335  {
336  for(int j=0;j<K;j++)
337  {
338  m_y_flat(j*N+i) = m_y(i,j);
339  }
340  }
341  //copy m_uset to m_uset_flat
342  for(int i=0;i<R;i++)
343  {
344  for(int j=0;j<K;j++)
345  {
346  m_uset_flat(j*R+i) = m_uset(i,j);
347  }
348  }
349  //set first part of g
350  m_g1 = dlib::trans(m_F)*m_Hx*m_E
351  -dlib::trans(m_F)*m_Hx*m_y_flat
352  -m_Hu*m_uset_flat;
353  }
357  void updateH11()
358  {
359  m_H11 = m_Hu + dlib::trans(m_F)*m_Hx*m_F;
360  }
365  void updateA1()
366  {
367  set_colm(m_A1,dlib::range(0,R*K-1)) = m_F;
368  }
373  void updateA2()
374  {
375  set_colm(m_A2,dlib::range(0,R*K-1)) = m_F;
376  }
377  private://methods for qpOASES interface matrix setup
378  inline int idx(int row,int col,int nrows,int ncols) const
379  {
380  return row*ncols+col;
381  //return col*nrows+row;
382  }
383  void updateqpH()
384  {
385  for(int i=0;i<R*K;i++)
386  {
387  for(int j=0;j<R*K;j++)
388  {
389  m_qpH[idx(i,j,nV,nV)] = m_H11(i,j);
390  }
391  }
392  for(int i=0;i<N;i++)
393  {
394  for(int j=0;j<N;j++)
395  {
396  m_qpH[idx(i+R*K,j+R*K,nV,nV)] = m_Heps(i,j);
397  }
398  }
399  }
400  void updateqpg()
401  {
402  for(int i=0;i<R*K;i++)
403  {
404  m_qpg[i] = m_g1(i);
405  }
406  for(int i=0;i<N;i++)
407  {
408  m_qpg[i+R*K] = m_geps(i);
409  }
410  }
411  void updateqpA()
412  {
413  for(int i=0;i<N*K;i++)
414  {
415  for(int j=0;j<nV;j++)
416  {
417  m_qpA[idx(i,j,nC,nV)] = m_A1(i,j);
418  }
419  }
420  for(int i=0;i<N*K;i++)
421  {
422  for(int j=0;j<nV;j++)
423  {
424  m_qpA[idx(i+N*K,j,nC,nV)] = -m_A2(i,j);
425  }
426  }
427  }
428  void updateqplb()
429  {
430  for(int i=0;i<R;i++)
431  {
432  for(int j=0;j<K;j++)
433  {
434  m_qplb[j*R+i] = m_lbu_hard(i,j);
435  }
436  }
437  //lower bound for eps is 0
438  }
439  void updateqpub()
440  {
441  for(int i=0;i<R;i++)
442  {
443  for(int j=0;j<K;j++)
444  {
445  m_qpub[j*R+i] = m_ubu_hard(i,j);
446  }
447  }
448  for(int i=0;i<N;i++)
449  {
450  m_qpub[R*K+i] = m_ubeps(i);
451  }
452  }
453  void updateqpubA()
454  {
455  int row;
456  // state constraints
457  for(int i=0;i<N;i++)
458  {
459  for(int j=0;j<K;j++)
460  {
461  row = j*N+i;
462  //upper bound F*u - 1*epsx <= ubx - E
463  m_qpubA[row] = m_ubx(i,j) - m_E(row);
464  //lower bound -F*u - 1*epsx <=-lbx + E
465  m_qpubA[row+N*K] = -m_lbx(i,j) + m_E(row);
466  }
467  }
468  }
469  private://methods for execution of optimization
474  {
475  //prepare intermediate matrices
476  updateAd();
477  updateE();
478  updateF();
479  updateHx();
480  updateHu();
481  updateHeps();
482  updateg1();
483  updateH11();
484  updateA1();
485  updateA2();
486 
487  //copy intermediate matrices into arrays//@TODO: find out, whether dlib matrix data arrays can be used directly
488  updateqpH();
489  updateqpg();
490  updateqpA();
491  updateqplb();
492  updateqpub();
493  updateqpubA();
494 
495  //call init method
499  }
506  {
507  //prepare intemediate matrices
508  updateE();
509  updateg1();
510 
511  //copy intermediate matrices into arrays
512  updateqpg();
513  updateqplb();
514  updateqpub();
515  updateqpubA();
516 
517  //call hotstart method
521  }
526  {
527  m_qproblem->getPrimalSolution( m_qpxOpt );
528  for(int i=0;i<R*K;i++)
529  {
530  m_U_flat(i) = m_qpxOpt[i];
531  }
532  set_rowm(m_X_flat,dlib::range(0,N-1)) = m_x0;
533  set_rowm(m_X_flat,dlib::range(N,N*(K+1)-1)) = m_E + m_F * m_U_flat;
534  for(int i=0;i<N;i++)
535  {
536  for(int j=0;j<=K;j++)
537  {
538  m_X(i,j) = m_X_flat(j*N+i);
539  }
540  }
541  for(int i=0;i<R;i++)
542  {
543  for(int j=0;j<K;j++)
544  {
545  m_U(i,j) = m_U_flat(j*R+i);
546  }
547  }
548  for(int i=0;i<N;i++)
549  {
550  m_eps(i) = m_qpxOpt[R*K+i];
551  }
552  }
557  {
558  dlib::matrix<double,N,1> x;
559  dlib::matrix<double,R,1> u;
560  for(int i=0;i<K;i++)
561  {
562  x = dlib::colm(m_X,i);
563  u = dlib::colm(m_U,i);
564  dlib::set_subm(m_resultfun.getData(),dlib::range(1,N),dlib::range(i*P,i*P)) = x;
565  dlib::set_subm(m_resultfun.getData(),dlib::range(N+1,N+R),dlib::range(i*P,i*P)) = u;
566  for(int j=1;j<P;j++)
567  {
568  x = m_Ad_p*x+m_Bd_p*u;
569  dlib::set_subm(m_resultfun.getData(),dlib::range(1,N),dlib::range(i*P+j,i*P+j)) = x;
570  dlib::set_subm(m_resultfun.getData(),dlib::range(N+1,N+R),dlib::range(i*P+j,i*P+j)) = u;
571  }
572  }
573  x = dlib::colm(m_X,K);
574  u = dlib::colm(m_U,K-1);
575  dlib::set_subm(m_resultfun.getData(),dlib::range(1,N),dlib::range(K*P,K*P)) = x;
576  dlib::set_subm(m_resultfun.getData(),dlib::range(N+1,N+R),dlib::range(K*P,K*P)) = u;
577  }
578 
579  public:
584  :m_resultfun(K*P+1,0.0)
585  {
590  m_system_changed = true;
591  m_qpnWSR_in = 1e7;
592  m_qpcputime_in = 1.0e7;
593  }
594 
599  {
600  delete_memory();
601  }
602 
606  void compute()
607  {
608  if(m_system_changed)
609  {
610  compute_init();
611  m_system_changed = false;
612  std::cout<<"reinitialized qp";
613  }
614  else
615  {
617  if(!isFeasible() || !isSolved())
618  {
619  m_system_changed = true;
620  }
621  }
624  }
628  bool isFeasible()const
629  {
630  return m_qproblem->isInfeasible()==qpOASES::BT_FALSE;
631  }
635  bool isSolved()const
636  {
637  return m_qproblem->isSolved()==qpOASES::BT_TRUE;
638  }
642  void updateSystem(const t_Ad& Ad,const t_Bd& Bd,const t_wx& wx,const t_wu& wu)
643  {
644  m_Ad = Ad; m_Bd = Bd; m_wx = wx; m_wu = wu;
645  setSystemChanged(true);
646  }
650  void updateSystem(const t_Ad& Ad,const t_Bd& Bd,const t_wx& wx,const t_wu& wu,const t_weps& weps)
651  {
652  m_Ad = Ad; m_Bd = Bd; m_wx = wx; m_wu = wu; m_weps = weps;
653  setSystemChanged(true);
654  }
658  void updateSystem(const t_Ad& Ad,const t_Bd& Bd,const t_wx& wx,const t_wu& wu,const t_weps& weps,const t_geps& geps)
659  {
660  m_Ad = Ad; m_Bd = Bd; m_wx = wx; m_wu = wu; m_weps = weps; m_geps = geps;
661  setSystemChanged(true);
662  }
666  void update(const t_x0& x0,const t_y& y,const t_lbx& lbx,const t_ubx& ubx,const t_lbu_hard& lbu_hard,const t_ubu_hard& ubu_hard,const t_ubeps& ubeps)
667  {
669  }
673  void update(const t_x0& x0,const t_y& y,const t_lbx& lbx,const t_ubx& ubx)
674  {
675  m_x0 = x0; m_y = y; m_lbx = lbx; m_ubx = ubx;
676  }
680  void setSystemChanged(bool value){m_system_changed = value;}
684  void setEndTime(double Tend)
685  {
686  double T[K+1];
687  adore::mad::linspace(0.0,Tend,T,K+1);
688  double dt_int = Tend/(K*P);
689  for(int i=0;i<K;i++)
690  {
691  for(int j=0;j<P;j++)
692  {
693  m_resultfun.getData()(0,i*P+j) = T[i]+j*dt_int;
694  }
695  }
696  m_resultfun.getData()(0,K*P) = T[K];
697  }
698 
699  public://getter methods
700  t_Ad& Ad(){return m_Ad;}//discrete time system matrix.
701  t_Bd& Bd(){return m_Bd;}//discrete time input matrix
702  t_Ad& Ad_p(){return m_Ad_p;}//discrete time system matrix for interpolation
703  t_Bd& Bd_p(){return m_Bd_p;}//discrete time input matrix for interpolation
704  t_resultfun& result_fun(){return m_resultfun;}//returns a function with linear interpolation of result
705  //weights for cost function
706  t_wx& wx(){return m_wx;}//weights for states (will be put on main diagonal of Hx)
707  t_wu& wu(){return m_wu;}//weights for inputs (will be put on main diagonal of Hu)
708  t_wx_end& wx_end(){return m_wx_end;}//weights for states (will be put on main diagonal of Hx)
709  t_wu_end& wu_end(){return m_wu_end;}//weights for inputs (will be put on main diagonal of Hu)
710  t_weps& weps(){return m_weps;}//quadratic weights for slack (will be put in Heps)
711  t_geps& geps(){return m_geps;}//linear weights for slack
712  //online data: bounds
713  t_lbx& lbx(){return m_lbx;}//lower bound on state trace
714  t_ubx& ubx(){return m_ubx;}//upper bound on state trace
715  t_lbu_hard& lbu_hard(){return m_lbu_hard;}//lower bound on input trace, hard constraint going to lb
716  t_ubu_hard& ubu_hard(){return m_ubu_hard;}//upper bound on input trace, hard constraint going to ub
717  t_ubeps& ubeps(){return m_ubeps;}//lbeps==0, softconstraints for x and/or u if ubeps>0
718  //online data: x0, y
719  t_x0& x0(){return m_x0;}//initial state
720  t_y& y(){return m_y;}//desired states (reference) y=[y_0(t_1);y_1(t_1);y_2(t_1);y_0(t_2);y_1(t_2);y_2(t_2);...;y_0(t_K);y_1(t_K);y_2(t_K)] (for N=3)
721  t_uset& uset(){return m_uset;}//set points (reference for controls)
722  //output
723  t_X& X(){return m_X;}
724  t_U& U(){return m_U;}
725  t_eps& eps(){return m_eps;}
727  int getnWSR(){return m_qpnWSR_out;}
728  qpOASES::QProblem* getQProblem(){return m_qproblem;}
729  void setMaxCPUTime(real_t value){m_qpcputime_in = value;}
730  void setMaxnWSR(int value){m_qpnWSR_in=value;}
731  int getnV(){return nV;}
732  int getnC(){return nC;}
733  };
734  }
735 }
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
Definition: lq_oc_single_shooting.h:61
LQ_OC_single_shooting()
Definition: lq_oc_single_shooting.h:583
bool isSolved() const
Definition: lq_oc_single_shooting.h:635
t_uset_flat m_uset_flat
set point
Definition: lq_oc_single_shooting.h:131
qpOASES::int_t m_qpnWSR_in
Definition: lq_oc_single_shooting.h:154
t_lbu_hard m_lbu_hard
upper bound on state trace
Definition: lq_oc_single_shooting.h:117
t_y m_y
initial state
Definition: lq_oc_single_shooting.h:122
real_t m_qpA[nC *nV]
Definition: lq_oc_single_shooting.h:148
void update(const t_x0 &x0, const t_y &y, const t_lbx &lbx, const t_ubx &ubx, const t_lbu_hard &lbu_hard, const t_ubu_hard &ubu_hard, const t_ubeps &ubeps)
Definition: lq_oc_single_shooting.h:666
t_geps m_geps
quadratic weights for slack (will be put in Heps)
Definition: lq_oc_single_shooting.h:113
t_uset m_uset
Definition: lq_oc_single_shooting.h:130
t_wu_end m_wu_end
weights for inputs (will be put on main diagonal of Hu)
Definition: lq_oc_single_shooting.h:111
void compute_init()
Definition: lq_oc_single_shooting.h:473
dlib::matrix< real_t, N, N > t_Ad
number of linear system constraints in QP: upper and lower bounds for x and u separately due to slack
Definition: lq_oc_single_shooting.h:66
dlib::matrix< real_t, N, 1 > t_ubeps
upper bound on input trace, hard constraint going to ub
Definition: lq_oc_single_shooting.h:83
t_weps & weps()
Definition: lq_oc_single_shooting.h:710
void updateA2()
Definition: lq_oc_single_shooting.h:373
int getnV()
Definition: lq_oc_single_shooting.h:731
dlib::matrix< real_t, N, 1 > t_eps
the computed states [x(t_1),..., x(t_K)]
Definition: lq_oc_single_shooting.h:95
void updateE()
Definition: lq_oc_single_shooting.h:258
t_wu m_wu
weights for states at endpoint
Definition: lq_oc_single_shooting.h:110
real_t m_qpcputime_in
qpOASES: "The integer argument nWSR speci es the maximum number of working set recalculations to be p...
Definition: lq_oc_single_shooting.h:156
dlib::matrix< real_t, N *K, 1 > t_y_flat
desired states (reference) y=[y_0(t_1);y_1(t_1);y_2(t_1);y_0(t_2);y_1(t_2);y_2(t_2);....
Definition: lq_oc_single_shooting.h:87
real_t m_qplbA[nC]
Definition: lq_oc_single_shooting.h:151
dlib::matrix< real_t, N, K+1 > t_X
the computed control [u(t_0),...,u(t_K-1)]
Definition: lq_oc_single_shooting.h:93
t_Ad m_Ad_p
discrete time input matrix
Definition: lq_oc_single_shooting.h:103
void updateqplb()
Definition: lq_oc_single_shooting.h:428
t_eps & eps()
Definition: lq_oc_single_shooting.h:725
void initialize_userdata_matrices()
qpOASES: "If cputime is not the null pointer, it contains the maximum allowed CPU time in seconds for...
Definition: lq_oc_single_shooting.h:159
void setMaxCPUTime(real_t value)
Definition: lq_oc_single_shooting.h:729
dlib::matrix< real_t, N, K > t_ubx
lower bound on state trace
Definition: lq_oc_single_shooting.h:78
static const int nC
number of variables in the QP: var=[u;eps]
Definition: lq_oc_single_shooting.h:65
void delete_memory()
Definition: lq_oc_single_shooting.h:194
dlib::matrix< real_t, R *K, R *K > m_H11
first part of overall linear cost term, g=[F^T Hx E - F^T Hx y; geps]=[g1;geps]
Definition: lq_oc_single_shooting.h:140
void updateH11()
Definition: lq_oc_single_shooting.h:357
t_wx & wx()
Definition: lq_oc_single_shooting.h:706
t_resultfun m_resultfun
powers of Ad, so these don't have to be recomputed online
Definition: lq_oc_single_shooting.h:106
dlib::matrix< real_t, R, K > t_lbu
upper bound on state trace
Definition: lq_oc_single_shooting.h:79
dlib::matrix< real_t, R *K, 1 > m_g1
Definition: lq_oc_single_shooting.h:139
int idx(int row, int col, int nrows, int ncols) const
Definition: lq_oc_single_shooting.h:378
bool m_system_changed
the slack
Definition: lq_oc_single_shooting.h:98
dlib::matrix< real_t, R, K > t_lbu_hard
upper bound on input trace
Definition: lq_oc_single_shooting.h:81
t_Bd & Bd_p()
Definition: lq_oc_single_shooting.h:703
virtual ~LQ_OC_single_shooting()
Definition: lq_oc_single_shooting.h:598
void updateg1()
Definition: lq_oc_single_shooting.h:331
t_Ad & Ad()
Definition: lq_oc_single_shooting.h:700
real_t m_qpH[nV *nV]
Definition: lq_oc_single_shooting.h:146
static const int nV
Definition: lq_oc_single_shooting.h:64
dlib::matrix< real_t, N, 1 > t_weps
weights for inputs at endpoint
Definition: lq_oc_single_shooting.h:74
void updateHeps()
Heps:=diag(weps);.
Definition: lq_oc_single_shooting.h:321
dlib::matrix< real_t, N, K > t_y
initial state
Definition: lq_oc_single_shooting.h:86
qpOASES::int_t m_qpnWSR_out
qpOASES: "The integer argument nWSR speci es the maximum number of working set recalculations to be p...
Definition: lq_oc_single_shooting.h:155
int getnWSR()
Definition: lq_oc_single_shooting.h:727
dlib::matrix< real_t, R *K, 1 > t_uset_flat
set point
Definition: lq_oc_single_shooting.h:89
qpOASES::QProblem * getQProblem()
Definition: lq_oc_single_shooting.h:728
t_ubx m_ubx
lower bound on state trace
Definition: lq_oc_single_shooting.h:116
void updateqpg()
Definition: lq_oc_single_shooting.h:400
t_lbx & lbx()
Definition: lq_oc_single_shooting.h:713
t_ubeps m_ubeps
upper bound on input trace, hard constraint going to ub
Definition: lq_oc_single_shooting.h:119
t_y & y()
Definition: lq_oc_single_shooting.h:720
real_t m_qpub[nV]
Definition: lq_oc_single_shooting.h:150
void updateSystem(const t_Ad &Ad, const t_Bd &Bd, const t_wx &wx, const t_wu &wu)
Definition: lq_oc_single_shooting.h:642
void setSystemChanged(bool value)
Definition: lq_oc_single_shooting.h:680
void retrieveSolution()
Definition: lq_oc_single_shooting.h:525
t_ubu_hard & ubu_hard()
Definition: lq_oc_single_shooting.h:716
dlib::matrix< real_t, N, 1 > t_geps
quadratic weights for slack (will be put in Heps)
Definition: lq_oc_single_shooting.h:75
adore::mad::LLinearPiecewiseFunctionM< double, N+R > t_resultfun
discrete time input matrix
Definition: lq_oc_single_shooting.h:68
dlib::matrix< real_t, N *(K+1), 1 > t_X_flat
the computed states [x(t_1),..., x(t_K)]
Definition: lq_oc_single_shooting.h:94
t_lbx m_lbx
linear weights for slack
Definition: lq_oc_single_shooting.h:115
t_uset & uset()
Definition: lq_oc_single_shooting.h:721
dlib::matrix< real_t, R, K > t_ubu_hard
lower bound on input trace, hard constraint going to lb
Definition: lq_oc_single_shooting.h:82
dlib::matrix< real_t, R *K, R *K > m_Hu
Definition: lq_oc_single_shooting.h:137
t_Bd & Bd()
Definition: lq_oc_single_shooting.h:701
t_lbu_hard & lbu_hard()
Definition: lq_oc_single_shooting.h:715
real_t m_qpg[nV]
Definition: lq_oc_single_shooting.h:147
void compute()
Definition: lq_oc_single_shooting.h:606
t_Bd m_Bd_p
system matrix for interpolation
Definition: lq_oc_single_shooting.h:104
t_ubx & ubx()
Definition: lq_oc_single_shooting.h:714
t_wx_end & wx_end()
Definition: lq_oc_single_shooting.h:708
qpOASES::QProblem * m_qproblem
state soft constraints equation lower bound
Definition: lq_oc_single_shooting.h:145
void updateA1()
Definition: lq_oc_single_shooting.h:365
t_wu_end & wu_end()
Definition: lq_oc_single_shooting.h:709
dlib::matrix< real_t, N, R > t_Bd
discrete time system matrix future version: one Ad,Bd per time step
Definition: lq_oc_single_shooting.h:67
dlib::matrix< real_t, R *K, 1 > t_U_flat
the computed control [u(t_0),...,u(t_K-1)]
Definition: lq_oc_single_shooting.h:92
std::vector< t_Ad * > m_Ad_powers
input matrix for interpolation
Definition: lq_oc_single_shooting.h:105
void updateF()
Definition: lq_oc_single_shooting.h:273
dlib::matrix< real_t, N *K, R *K > m_F
[pow(Ad,1);pow(Ad,2);...;pow(Ad,k)]*x0
Definition: lq_oc_single_shooting.h:135
t_U m_U
desired states (reference) y=[y_0(t_1);y_1(t_1);y_2(t_1);y_0(t_2);y_1(t_2);y_2(t_2);....
Definition: lq_oc_single_shooting.h:125
void updateqpub()
Definition: lq_oc_single_shooting.h:439
dlib::matrix< real_t, N, 1 > t_x0
lbeps==0, softconstraints for x and/or u if ubeps>0
Definition: lq_oc_single_shooting.h:85
dlib::matrix< real_t, R, K > t_U
set point
Definition: lq_oc_single_shooting.h:91
void setMaxnWSR(int value)
Definition: lq_oc_single_shooting.h:730
t_geps & geps()
Definition: lq_oc_single_shooting.h:711
dlib::matrix< real_t, R, K > t_ubu
lower bound on input trace
Definition: lq_oc_single_shooting.h:80
t_wx m_wx
Definition: lq_oc_single_shooting.h:108
qpOASES::real_t real_t
Definition: lq_oc_single_shooting.h:63
t_y_flat m_y_flat
desired states (reference) y=[y_0(t_1);y_1(t_1);y_2(t_1);y_0(t_2);y_1(t_2);y_2(t_2);....
Definition: lq_oc_single_shooting.h:123
t_x0 m_x0
lbeps==0, softconstraints for x and/or u if ubeps>0
Definition: lq_oc_single_shooting.h:121
t_Ad & Ad_p()
Definition: lq_oc_single_shooting.h:702
real_t m_qpxOpt[nV]
Definition: lq_oc_single_shooting.h:153
dlib::matrix< real_t, N, 1 > t_wx_end
weights for states (will be put on main diagonal of Hx)
Definition: lq_oc_single_shooting.h:71
t_X m_X
Definition: lq_oc_single_shooting.h:127
void updateqpH()
Definition: lq_oc_single_shooting.h:383
void updateqpubA()
Definition: lq_oc_single_shooting.h:453
int getnC()
Definition: lq_oc_single_shooting.h:732
void updateHx()
Hx:=diag(wx)
Definition: lq_oc_single_shooting.h:288
t_wx_end m_wx_end
weights for states (will be put on main diagonal of Hx)
Definition: lq_oc_single_shooting.h:109
t_ubeps & ubeps()
Definition: lq_oc_single_shooting.h:717
void updateSystem(const t_Ad &Ad, const t_Bd &Bd, const t_wx &wx, const t_wu &wu, const t_weps &weps)
Definition: lq_oc_single_shooting.h:650
real_t m_qpubA[nC]
Definition: lq_oc_single_shooting.h:152
t_resultfun & result_fun()
Definition: lq_oc_single_shooting.h:704
void updateAd()
Definition: lq_oc_single_shooting.h:244
dlib::matrix< real_t, N, 1 > t_wx
function for result interpolation
Definition: lq_oc_single_shooting.h:70
t_weps m_weps
weights for inputs at endpoint
Definition: lq_oc_single_shooting.h:112
void initialize_interface_variables()
Definition: lq_oc_single_shooting.h:203
t_eps m_eps
Definition: lq_oc_single_shooting.h:129
dlib::matrix< real_t, N, K > t_lbx
linear weights for slack
Definition: lq_oc_single_shooting.h:77
dlib::matrix< real_t, N *K, 1 > m_E
set point
Definition: lq_oc_single_shooting.h:134
void updateqpA()
Definition: lq_oc_single_shooting.h:411
t_x0 & x0()
Definition: lq_oc_single_shooting.h:719
void interpolateSolution()
Definition: lq_oc_single_shooting.h:556
void initialize_intermediate_matrices()
Definition: lq_oc_single_shooting.h:213
void compute_hotstart()
Definition: lq_oc_single_shooting.h:505
dlib::matrix< real_t, R, K > t_uset
desired states (reference) y=[y_0(t_1);y_1(t_1);y_2(t_1);y_0(t_2);y_1(t_2);y_2(t_2);....
Definition: lq_oc_single_shooting.h:88
dlib::matrix< real_t, R, 1 > t_wu_end
weights for inputs (will be put on main diagonal of Hu)
Definition: lq_oc_single_shooting.h:73
real_t getCPUTime()
Definition: lq_oc_single_shooting.h:726
dlib::matrix< real_t, R, 1 > t_wu
weights for states at endpoint
Definition: lq_oc_single_shooting.h:72
t_Ad m_Ad
Definition: lq_oc_single_shooting.h:101
real_t m_qpcputime_out
qpOASES: "If cputime is not the null pointer, it contains the maximum allowed CPU time in seconds for...
Definition: lq_oc_single_shooting.h:157
void updateHu()
Hu:=diag(wu)
Definition: lq_oc_single_shooting.h:305
real_t m_qplb[nV]
Definition: lq_oc_single_shooting.h:149
void updateSystem(const t_Ad &Ad, const t_Bd &Bd, const t_wx &wx, const t_wu &wu, const t_weps &weps, const t_geps &geps)
Definition: lq_oc_single_shooting.h:658
void initialize_memory()
Definition: lq_oc_single_shooting.h:183
t_Bd m_Bd
discrete time system matrix future version: one Ad,Bd per time step
Definition: lq_oc_single_shooting.h:102
t_X_flat m_X_flat
the computed states [x(t_1),..., x(t_K)]
Definition: lq_oc_single_shooting.h:128
dlib::matrix< real_t, N *K, nV > m_A2
state soft constraints equation upper bound
Definition: lq_oc_single_shooting.h:143
t_U & U()
Definition: lq_oc_single_shooting.h:724
t_U_flat m_U_flat
the computed control [u(t_0),...,u(t_K-1)]
Definition: lq_oc_single_shooting.h:126
dlib::matrix< real_t, N, N > m_Heps
Definition: lq_oc_single_shooting.h:138
void setEndTime(double Tend)
Definition: lq_oc_single_shooting.h:684
t_wu & wu()
Definition: lq_oc_single_shooting.h:707
dlib::matrix< real_t, N *K, N *K > m_Hx
[B,0,0,..0;AB,B,0,...0;AAB,AB,B,...,0;...;pow(A,k-1)B,pow(A,k-2)B,pow(A,k-3),B,......
Definition: lq_oc_single_shooting.h:136
void update(const t_x0 &x0, const t_y &y, const t_lbx &lbx, const t_ubx &ubx)
Definition: lq_oc_single_shooting.h:673
dlib::matrix< real_t, N *K, nV > m_A1
upper left part of overal quadratic cost term H=[Hu + F^T Hx F, 0; 0, Heps]=[H11,0;0,...
Definition: lq_oc_single_shooting.h:142
t_X & X()
Definition: lq_oc_single_shooting.h:723
bool isFeasible() const
Definition: lq_oc_single_shooting.h:628
t_ubu_hard m_ubu_hard
lower bound on input trace, hard constraint going to lb
Definition: lq_oc_single_shooting.h:118
adoreMatrix< T, 1, n > linspace(T x0, T x1)
Definition: adoremath.h:91
void define_integrator_chain(dlib::matrix< T, d, d > &Ad, dlib::matrix< T, d, 1 > &Bd, T dt)
Definition: lq_oc_single_shooting.h:32
x
Definition: adore_set_goal.py:30
Definition: areaofeffectconverter.h:20