humoto
mpc_mg.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @author Jan Michalczyk
5  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7  @brief
8 */
9 
10 #pragma once
11 
12 namespace humoto
13 {
14  namespace pepper_mpc
15  {
16  /**
17  * @brief Model Predictive Control problem for walking pattern generation [determine_solution_structure.m,
18  * form_rotation_matrices.m, form_foot_pos_matrices.m, form_condensing_matrices.m]
19  */
21  {
22  private:
24 
25 
26  private:
27  /**
28  * @brief Create the rotation matrices of the MPC problem
29  */
31  {
32  R_.setZero(preview_horizon_.intervals_.size());
33 
34  for(std::size_t i=0; i < preview_horizon_.intervals_.size(); ++i)
35  {
36  R_(i) = preview_horizon_.getRotationMatrix(i).transpose();
37  }
38  }
39 
40 
41 
42  /**
43  * @brief Initialize next model state
44  *
45  * @param[in] model model
46  *
47  * @return next model state.
48  */
50  const humoto::pepper_mpc::Model &model) const
51  {
53 
54 
55  double T = preview_horizon_.intervals_[0].T_;
56  double base_height = preview_horizon_.intervals_[0].base_height_;
57  double body_height = preview_horizon_.intervals_[0].body_height_;
58  double theta = preview_horizon_.intervals_[0].theta_;
59 
60 
61  model.getNextState( model_state,
62  T,
63  T,
64  base_controls_.head(2),
65  body_controls_.head(2),
66  base_height,
67  body_height,
68  theta);
69 
70 
71  return(model_state);
72  }
73 
74 
75  /**
76  * @brief Condense and recompute all dependent matrices.
77  *
78  * @param[in] model
79  */
80  void updateMatrices(const Model &model)
81  {
82  // decision variables
83  sol_structure_.reset();
84  sol_structure_.addSolutionPart(BASE_VEL_VARIABLES_ID, mpc_parameters_.preview_horizon_length_ * 2);
85  sol_structure_.addSolutionPart(BODY_JERK_VARIABLES_ID, mpc_parameters_.preview_horizon_length_ * 2);
86 
87 
88  // Initialize matrices
89  formRotationMatrices();
90 
91 
92 
93  // condensing
94  std::vector< etools::Matrix3 > As_matrices;
95  std::vector< etools::Vector3 > Bs_matrices;
96 
97  std::vector< etools::Matrix3 > Ad_matrices;
98  std::vector< etools::Vector3 > Bd_matrices;
99 
100  std::vector< etools::Matrix1x3 > Djs_matrices;
101  std::vector< double > Ejs_matrices;
102 
105 
106 
107  As_matrices.resize(mpc_parameters_.preview_horizon_length_);
108  Bs_matrices.resize(mpc_parameters_.preview_horizon_length_);
109 
110  Ad_matrices.resize(mpc_parameters_.preview_horizon_length_);
111  Bd_matrices.resize(mpc_parameters_.preview_horizon_length_);
112 
113  Djs_matrices.resize(mpc_parameters_.preview_horizon_length_);
114  Ejs_matrices.resize(mpc_parameters_.preview_horizon_length_);
115 
116  Dps.setZero(mpc_parameters_.preview_horizon_length_);
117  Dpd.setZero(mpc_parameters_.preview_horizon_length_);
118 
119 
120  for (std::size_t i = 0; i < mpc_parameters_.preview_horizon_length_; ++i)
121  {
122  double T = preview_horizon_.intervals_[i].T_;
123  double base_height = preview_horizon_.intervals_[i].base_height_;
124  double body_height = preview_horizon_.intervals_[i].body_height_;
125  double base_mass = preview_horizon_.intervals_[i].base_mass_;
126  double body_mass = preview_horizon_.intervals_[i].body_mass_;
127 
128 
129  As_matrices[i] = model.getAs3(T);
130  Bs_matrices[i] = model.getBs3(T);
131 
132  Ad_matrices[i] = model.getAd3(T);
133  Bd_matrices[i] = model.getBd3(T);
134 
135  Djs_matrices[i] = model.getDjs3(T);
136  Ejs_matrices[i] = model.getEjs3(T);
137 
138  Dps(i) = model.getDps3(base_height, base_mass, body_mass);
139  Dpd(i) = model.getDpd3(body_height, base_mass, body_mass);
140  }
141 
144 
147 
148  condense(Uxs, Uus, As_matrices, Bs_matrices);
149  condense(Uxd, Uud, Ad_matrices, Bd_matrices);
150 
153 
154  condenseOutput(Ojxs, Ojus, Djs_matrices, Ejs_matrices, Uxs, Uus);
155 
156 
157  etools::Vector6 mpc_base_state = model.getMPCBaseState();
158  etools::Vector6 mpc_body_state = model.getMPCBodyState();
159 
160 
161  // -----
162 
163  std::size_t number_of_state_variables = model.Ns_ * mpc_parameters_.preview_horizon_length_;
164 
168  number_of_state_variables/2,
169  sol_structure_.getNumberOfVariables()/2);
170  S_bmi.resize(2, 2);
171 
172  /*
173  // slower
174  S_bmi(0,0) = Uus.getBlockKroneckerProduct(2).evaluate();
175  S_bmi(0,1).setZero();
176  S_bmi(1,0).setZero();
177  S_bmi(1,1) = Uud.getBlockKroneckerProduct(2).evaluate();
178  */
179 
180  Uus.getBlockKroneckerProduct(2).evaluate(S_bmi(0,0));
181  S_bmi(0,1).setZero();
182  S_bmi(1,0).setZero();
183  Uud.getBlockKroneckerProduct(2).evaluate(S_bmi(1,1));
184 
185 
186  s_.resize(number_of_state_variables);
187  s_ << Uxs.getBlockKroneckerProduct(2) * mpc_base_state,
188  Uxd.getBlockKroneckerProduct(2) * mpc_body_state;
189 
190 
191  // -----
192 
193  sp_.noalias() = etools::GenericBlockKroneckerProduct<1,3>(Dps*Uxs, 2) * mpc_base_state
194  +
195  etools::GenericBlockKroneckerProduct<1,3>(Dpd*Uxd, 2) * mpc_body_state;
196 
197  Ap_.resize(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables ());
198  /*
199  // slower
200  Ap_ << etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Dps*Uus, 2).evaluate(),
201  etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Dpd*Uud, 2).evaluate();
202  */
203  etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Dps*Uus, 2).evaluate(Ap_.leftCols(sol_structure_.getNumberOfVariables()/2));
204  etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Dpd*Uud, 2).evaluate(Ap_.rightCols(sol_structure_.getNumberOfVariables()/2));
205 
206 
207  // -----
208 
209  /*
210  // slower
211  sas_.noalias() = etools::GenericBlockKroneckerProduct<1,3>(Uxs.selectRowInBlocksAsMatrix(2), 2) * mpc_base_state;
212  Aas_.resize(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables ());
213  Aas_ << etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Uus.selectRowInBlocksAsMatrix(2), 2).evaluate(),
214  Eigen::MatrixXd::Zero(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables()/2);
215  //etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Uus.selectRowInBlocksAsMatrix(2), 2).evaluate(Aas_);
216  */
217  sas_.noalias() = Uxs.selectRowInBlocks(2).getBlockKroneckerProduct(2) * mpc_base_state;
218  Uus.selectRowInBlocks(2).getBlockKroneckerProduct(2).evaluate(Aas_);
219 
220  // -----
221 
222  /*
223  // slower
224  sps_.noalias() = etools::GenericBlockKroneckerProduct<1,3>(Uxs.selectRowInBlocksAsMatrix(0), 2) * mpc_base_state;
225  Aps_.resize(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables ());
226  Aps_ << etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Uus.selectRowInBlocksAsMatrix(0), 2).evaluate(),
227  Eigen::MatrixXd::Zero(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables()/2);
228  //etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Uus.selectRowInBlocksAsMatrix(0), 2).evaluate(Aps_);
229  */
230  sps_.noalias() = Uxs.selectRowInBlocks(0).getBlockKroneckerProduct(2) * mpc_base_state;
231  Uus.selectRowInBlocks(0).getBlockKroneckerProduct(2).evaluate(Aps_);
232 
233  // -----
234  /*
235  // slower
236  spd_.noalias() =
237  R_ * ( etools::GenericBlockKroneckerProduct<1,3>(Uxs.selectRowInBlocksAsMatrix(0), 2) * mpc_base_state
238  -
239  etools::GenericBlockKroneckerProduct<1,3>(Uxd.selectRowInBlocksAsMatrix(0), 2) * mpc_body_state);
240  Apd_.resize(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables ());
241  Apd_ << R_ * etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Uus.selectRowInBlocksAsMatrix(0), 2),
242  - (R_ * etools::LeftLowerTriangularBlockKroneckerProduct<1,1>(Uud.selectRowInBlocksAsMatrix(0), 2));
243  */
244  spd_.noalias() =
245  R_ * ( Uxs.selectRowInBlocks(0).getBlockKroneckerProduct(2) * mpc_base_state
246  -
247  Uxd.selectRowInBlocks(0).getBlockKroneckerProduct(2) * mpc_body_state);
248  Apd_.resize(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables ());
249  Apd_ << R_ * Uus.selectRowInBlocks(0).getBlockKroneckerProduct(2),
250  - (R_ * Uud.selectRowInBlocks(0).getBlockKroneckerProduct(2));
251 
252  // -----
253 
254  sjs_.noalias() = Ojxs.getBlockKroneckerProduct(2) * mpc_base_state;
255 
256  /*
257  // slower
258  Ajs_.resize(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables ());
259  Ajs_ << Ojus.getBlockKroneckerProduct(2).evaluate(),
260  Eigen::MatrixXd::Zero(2*mpc_parameters_.preview_horizon_length_, sol_structure_.getNumberOfVariables()/2);
261  */
262  Ojus.getBlockKroneckerProduct(2).evaluate(Ajs_);
263  }
264 
265 
266  /**
267  * @brief Computes model state at the given time instant
268  *
269  * @param[in] model model
270  * @param[in] interval_index index of an interval in the preview horizon
271  * @param[in] interval_offset offset from the start of the given interval
272  *
273  * @return model state.
274  */
276  const std::size_t interval_index,
277  const double interval_offset)
278  {
279  double base_height = preview_horizon_.intervals_[interval_index].base_height_;
280  double body_height = preview_horizon_.intervals_[interval_index].body_height_;
281 
282  double theta_prev;
283  if (0 == interval_index)
284  {
285  theta_prev = model.getTheta();
286  }
287  else
288  {
289  theta_prev = preview_horizon_.intervals_[interval_index-1].theta_;
290  }
291  double theta = theta_prev
292  + (preview_horizon_.intervals_[interval_index].theta_ - theta_prev)
293  * interval_offset / preview_horizon_.intervals_[interval_index].T_;
294 
295 
296  EIGENTOOLS_CONSTANT_SIZE_VECTOR(12) preceding_cstate;
297  etools::Vector2 base_control;
298  etools::Vector2 body_control;
299 
300 
301  if (interval_index == 0)
302  {
303  preceding_cstate = model.getMPCState();
304  }
305  else
306  {
307  preceding_cstate << cstate_profile_.segment((interval_index - 1)*model.Ns_/2, model.Ns_/2),
308  cstate_profile_.segment(getPreviewHorizonLength()*model.Ns_/2
309  + (interval_index - 1)*model.Ns_/2, model.Ns_/2);
310  }
311  base_control = base_controls_.segment(interval_index*2, 2);
312  body_control = body_controls_.segment(interval_index*2, 2);
313 
314 
315  humoto::pepper_mpc::ModelState model_state;
316 
317  model.getNextState( model_state,
318  preview_horizon_.intervals_[interval_index].T_,
319  interval_offset,
320  preceding_cstate,
321  base_controls_.head(2),
322  body_controls_.head(2),
323  base_height,
324  body_height,
325  theta);
326 
327  return (model_state);
328  }
329 
330 
331  public:
332  static const std::ptrdiff_t DEFAULT_PREVIEW_HORIZON_SHIFT = -1;
333 
335 
336 
338 
339 
340  Eigen::MatrixXd S_;
341  Eigen::VectorXd s_;
342 
343  // CoP
344  Eigen::VectorXd sp_;
345  Eigen::MatrixXd Ap_;
346 
347  // base acceleration
348  Eigen::VectorXd sas_;
349  Eigen::MatrixXd Aas_;
350 
351  // base position
352  Eigen::VectorXd sps_;
353  Eigen::MatrixXd Aps_;
354 
355  // body position
356  Eigen::VectorXd spd_;
357  Eigen::MatrixXd Apd_;
358 
359  // base jerk
360  Eigen::VectorXd sjs_;
361  Eigen::MatrixXd Ajs_;
362 
363 
364  // state and output profiles
365  Eigen::VectorXd cstate_profile_;
366  Eigen::VectorXd cop_profile_;
367  Eigen::VectorXd base_jerk_profile_;
368 
369  // controls
370  Eigen::VectorXd base_controls_;
371  Eigen::VectorXd body_controls_;
372 
374 
375 
376  public:
377  /**
378  * @brief Constructor
379  */
381  {
382  solution_is_parsed_ = false;
383  }
384 
385 
386  /**
387  * @brief Constructor
388  *
389  * @param[in] mpc_parameters parameters of the MPC
390  */
391  explicit MPCforMG(const humoto::pepper_mpc::MPCParameters &mpc_parameters)
392  {
393  solution_is_parsed_ = false;
394  setParameters(mpc_parameters);
395  }
396 
397 
398  /**
399  * @brief Set parameters
400  *
401  * @param[in] mpc_parameters
402  */
404  {
405  mpc_parameters_ = mpc_parameters;
406  }
407 
408 
409  /**
410  * @brief Update control problem
411  *
412  * @tparam t_MotionParameters MotionParameters or deque<MotionParameters>
413  *
414  * @param[in] motion_parameters
415  * @param[in] model model of the system
416  *
417  * @return ControlProblemStatus::OK/ControlProblemStatus::STOPPED
418  */
419  template <class t_MotionParameters>
421  update( const t_MotionParameters &motion_parameters,
422  const Model &model)
423  {
425  solution_is_parsed_ = false;
426 
427  if (preview_horizon_.form( mpc_parameters_,
428  model,
429  motion_parameters))
430  {
431  updateMatrices(model);
432  control_status = ControlProblemStatus::OK;
433  }
434  else
435  {
436  control_status = ControlProblemStatus::STOPPED;
437  }
438 
439  return (control_status);
440  }
441 
442 
443 
444  /**
445  * @brief Shift preview horizon
446  *
447  * @param[in,out] motion_parameters duration_ms parameter is reduced by time_shift_ms
448  * @param[in] time_shift_ms shift of the preview horizon on the next iteration
449  */
450  void shift( MotionParameters &motion_parameters,
451  const std::ptrdiff_t time_shift_ms = DEFAULT_PREVIEW_HORIZON_SHIFT)
452  {
453  if (motion_parameters.duration_ms_ != MotionParameters::UNLIMITED_DURATION)
454  {
455  if (time_shift_ms == DEFAULT_PREVIEW_HORIZON_SHIFT)
456  {
457  motion_parameters.duration_ms_ -= mpc_parameters_.sampling_time_ms_;
458  }
459  else
460  {
461  motion_parameters.duration_ms_ -= time_shift_ms;
462  }
463 
464  if (motion_parameters.duration_ms_ < 0)
465  {
466  motion_parameters.duration_ms_ = 0;
467  }
468  }
469  }
470 
471 
472  /**
473  * @brief Update control problem
474  *
475  * @param[in,out] motion_parameters_deque duration_ms parameter is reduced by time_shift_ms
476  * @param[in] time_shift_ms shift of the preview horizon on the next iteration
477  */
478  void shift( std::deque<MotionParameters> &motion_parameters_deque,
479  const std::ptrdiff_t time_shift_ms = DEFAULT_PREVIEW_HORIZON_SHIFT)
480  {
481  std::ptrdiff_t tmp_time_shift_ms = time_shift_ms;
482  if (time_shift_ms == DEFAULT_PREVIEW_HORIZON_SHIFT)
483  {
484  tmp_time_shift_ms = mpc_parameters_.sampling_time_ms_;
485  }
486 
487  for(;;)
488  {
489  if (motion_parameters_deque.size() > 0)
490  {
491  if (motion_parameters_deque.front().duration_ms_ == MotionParameters::UNLIMITED_DURATION)
492  {
493  // no need to shift
494  break;
495  }
496  else
497  {
498  if (motion_parameters_deque.front().duration_ms_ <= tmp_time_shift_ms)
499  {
500  tmp_time_shift_ms -= motion_parameters_deque.front().duration_ms_;
501  motion_parameters_deque.pop_front();
502  }
503  else
504  {
505  motion_parameters_deque.front().duration_ms_ -= tmp_time_shift_ms;
506 
507  if (motion_parameters_deque.front().duration_ms_ < 0)
508  {
509  motion_parameters_deque.front().duration_ms_ = 0;
510  }
511 
512  // successfully shifted
513  break;
514  }
515  }
516  }
517  else
518  {
519  // deque reduced to zero
520  break;
521  }
522  }
523  }
524 
525 
526  /**
527  * @brief Update control problem & shift preview horizon
528  *
529  * @tparam t_MotionParameters MotionParameters or deque<MotionParameters>
530  *
531  * @param[in,out] motion_parameters duration_ms parameter is reduced by time_shift_ms
532  * @param[in] model model of the system
533  * @param[in] time_shift_ms shift of the preview horizon on the next iteration
534  *
535  * @return ControlProblemStatus::OK/ControlProblemStatus::STOPPED
536  */
537  template <class t_MotionParameters>
539  updateAndShift( t_MotionParameters &motion_parameters,
540  const Model &model,
541  const std::ptrdiff_t time_shift_ms = DEFAULT_PREVIEW_HORIZON_SHIFT)
542  {
543  ControlProblemStatus::Status status = update(motion_parameters, model);
544 
545  if (status == ControlProblemStatus::OK)
546  {
547  shift(motion_parameters, time_shift_ms);
548  }
549  return (status);
550  }
551 
552 
553 
554  /**
555  * @brief Process solution
556  *
557  * @param[in] solution solution
558  */
559  void parseSolution(const humoto::Solution &solution)
560  {
561  cstate_profile_.noalias() = S_ * solution.get_x() + s_;
562  cop_profile_.noalias() = Ap_ * solution.get_x() + sp_;
563  base_jerk_profile_.noalias() = Ajs_ * solution.get_x().segment(0, sol_structure_.getNumberOfVariables()/2)
564  + sjs_;
565 
566  base_controls_ = solution.getSolutionPart(BASE_VEL_VARIABLES_ID);
567  body_controls_ = solution.getSolutionPart(BODY_JERK_VARIABLES_ID);
568 
569  solution_is_parsed_ = true;
570  }
571 
572 
573  /**
574  * @brief Get next model state.
575  *
576  * @param[in] solution solution
577  * @param[in] model model
578  *
579  * @return next model state.
580  */
582  const humoto::Solution &solution,
583  const humoto::pepper_mpc::Model &model)
584  {
585  HUMOTO_ASSERT(solution_is_parsed_ == false, "The solution is parsed.");
586  parseSolution(solution);
587  return(initializeNextModelState(model));
588  }
589 
590 
591  /**
592  * @brief Get next model state.
593  *
594  * @param[in] model model
595  *
596  * @return next model state.
597  */
599  const humoto::pepper_mpc::Model &model) const
600  {
601  HUMOTO_ASSERT(solution_is_parsed_ == true, "This function can be called only after the solution is parsed.");
602  return(initializeNextModelState(model));
603  }
604 
605 
606 
607  /**
608  * @brief Guess solution
609  *
610  * @param[in] old_solution old solution
611  * @param[out] solution_guess solution guess
612  */
613  void guessSolution( Solution &solution_guess,
614  const Solution &old_solution) const
615  {
616  solution_guess.initialize(sol_structure_, 0.0);
617 
618 
619  if ( (old_solution.isNonEmpty()) && (old_solution.getNumberOfVariables() != 0) )
620  {
621  Location old_part;
622  Location guess_part;
623 
624  // base
625  old_part = old_solution.getSolutionPartLocation(BASE_VEL_VARIABLES_ID);
626  guess_part = solution_guess.getSolutionPartLocation(BASE_VEL_VARIABLES_ID);
627 
628  guess_part.length_ -= 2;
629 
630  old_part.offset_ +=2;
631  old_part.length_ -=2;
632 
633  solution_guess.getData(guess_part) = old_solution.getData(old_part);
634 
635 
636  // body
637  old_part = old_solution.getSolutionPartLocation(BODY_JERK_VARIABLES_ID);
638  guess_part = solution_guess.getSolutionPartLocation(BODY_JERK_VARIABLES_ID);
639 
640  guess_part.length_ -= 2;
641 
642  old_part.offset_ +=2;
643  old_part.length_ -=2;
644 
645  solution_guess.getData(guess_part) = old_solution.getData(old_part);
646  }
647  }
648 
649 
650 
651  /**
652  * @brief Computes model state at the given time instant
653  *
654  * @param[in] model model
655  * @param[in] time_instant_ms time instant
656  *
657  * @return model state.
658  */
660  const std::size_t time_instant_ms)
661  {
662  HUMOTO_ASSERT(solution_is_parsed_ == true, "This function can be called only after the solution is parsed.");
663 
664 
665  std::size_t time_offset_ms = time_instant_ms;
666  std::size_t interval_index = preview_horizon_.getIntervalIndexByTimeOffset(time_offset_ms);
667 
668  return(getModelState(model, interval_index, convertMillisecondToSecond(time_offset_ms)));
669  }
670 
671 
672  /**
673  * @brief Computes model state at the given time instant
674  *
675  * @param[in] model model
676  * @param[in] time_instant double time instant
677  *
678  * @return model state.
679  */
681  const double time_instant)
682  {
683  HUMOTO_ASSERT(solution_is_parsed_ == true, "This function can be called only after the solution is parsed.");
684 
685 
686  double time_offset = time_instant;
687  std::size_t interval_index = preview_horizon_.getIntervalIndexByTimeOffset(time_offset);
688 
689  return(getModelState(model, interval_index, time_offset));
690  }
691 
692 
693 
694  /**
695  * @brief Returns length of the preview horizon
696  *
697  * @return length of preview horizon
698  */
699  std::size_t getPreviewHorizonLength() const
700  {
701  return (mpc_parameters_.preview_horizon_length_);
702  }
703 
704 
705 
706  /**
707  * @brief Log
708  *
709  * @param[in,out] logger logger
710  * @param[in] parent parent
711  * @param[in] name name
712  */
714  const LogEntryName &parent = LogEntryName(),
715  const std::string & name = "mpcmg") const
716  {
717  LogEntryName subname = parent; subname.add(name);
718 
719  preview_horizon_.log(logger, subname);
720 
721 
722  logger.log(LogEntryName(subname).add("R"), R_.getRaw());
723 
724  logger.log(LogEntryName(subname).add("S") , S_);
725  logger.log(LogEntryName(subname).add("s") , s_);
726 
727  logger.log(LogEntryName(subname).add("sp") , sp_);
728  logger.log(LogEntryName(subname).add("Ap") , Ap_);
729 
730  logger.log(LogEntryName(subname).add("sas") , sas_);
731  logger.log(LogEntryName(subname).add("Aas") , Aas_);
732 
733  logger.log(LogEntryName(subname).add("sps") , sps_);
734  logger.log(LogEntryName(subname).add("Aps") , Aps_);
735 
736  logger.log(LogEntryName(subname).add("sjs") , sjs_);
737  logger.log(LogEntryName(subname).add("Ajs") , Ajs_);
738 
739  logger.log(LogEntryName(subname).add("base_controls"), base_controls_);
740  logger.log(LogEntryName(subname).add("body_controls"), body_controls_);
741 
742  logger.log(LogEntryName(subname).add("cstate_profile"), cstate_profile_);
743  logger.log(LogEntryName(subname).add("jerk_profile"), base_jerk_profile_);
744  logger.log(LogEntryName(subname).add("cop_profile"), cop_profile_);
745  }
746  };
747  }
748 }
749 
Eigen::MatrixXd S_
Definition: mpc_mg.h:340
BlockKroneckerProductBase< const DecayedRawMatrix &, t_block_rows_num, t_block_cols_num, t_sparsity_type > getBlockKroneckerProduct(const std::ptrdiff_t identity_size) const
Get block Kronecker product of this matrix.
Definition: blockmatrix.h:223
std::size_t getNumberOfVariables() const
Get total number of variables in the solution vector.
Definition: solution.h:109
static const char * BODY_JERK_VARIABLES_ID
Definition: common.h:18
Eigen::VectorXd base_controls_
Definition: mpc_mg.h:370
ControlProblemStatus::Status update(const t_MotionParameters &motion_parameters, const Model &model)
Update control problem.
Definition: mpc_mg.h:421
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:270
Eigen::VectorXd base_jerk_profile_
Definition: mpc_mg.h:367
void getNextState(humoto::pepper_mpc::ModelState &model_state, const double T, const double Ts, const etools::Vector2 &base_control, const etools::Vector2 &body_control, const double base_height, const double body_height, const double theta) const
Get next state from the current state.
Definition: model.h:214
std::size_t preview_horizon_length_
Length of the preview horizon (N)
Definition: common.h:313
Eigen::VectorXd cstate_profile_
Definition: mpc_mg.h:365
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:90
#define HUMOTO_LOCAL
Definition: export_import.h:26
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:268
etools::Matrix3 getAd3(const double T) const
Create intermediate Ad3 matrix.
static const char * BASE_VEL_VARIABLES_ID
Definition: common.h:17
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="preview_horizon") const
Log.
etools::Matrix1x3 getDps3(const double base_height, const double base_mass, const double body_mass) const
Create Dps3 matrix.
Eigen::VectorBlock< Eigen::VectorXd > getSolutionPart(const std::string &id)
Get part of the solution by its id.
Definition: solution.h:281
std::size_t getIntervalIndexByTimeOffset(std::size_t &offset_ms) const
Finds interval which contains the time instant with the given offset from the beginning of the previe...
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Definition: logger.h:997
#define HUMOTO_ASSERT(condition, message)
Eigen::VectorBlock< Eigen::VectorXd > getData(const Location &location)
Get data from solution vector.
Definition: solution.h:294
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:86
double HUMOTO_LOCAL convertMillisecondToSecond(const std::size_t milliseconds)
Converts milliseconds to seconds.
Definition: time.h:22
void setZero(const std::ptrdiff_t num_blocks_vert, const std::ptrdiff_t num_blocks_hor)
Resize matrix and initialize it with zeros.
Container of the solution.
Definition: solution.h:176
Represents log entry name.
Definition: logger.h:169
bool isNonEmpty() const
Checks if the structure is empty or not.
Definition: solution.h:88
Eigen::VectorXd s_
Definition: mpc_mg.h:341
std::size_t length_
Definition: utility.h:150
Eigen::VectorXd body_controls_
Definition: mpc_mg.h:371
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:266
ControlProblemStatus::Status updateAndShift(t_MotionParameters &motion_parameters, const Model &model, const std::ptrdiff_t time_shift_ms=DEFAULT_PREVIEW_HORIZON_SHIFT)
Update control problem & shift preview horizon.
Definition: mpc_mg.h:539
void resize(const std::ptrdiff_t num_blocks_vert, const std::ptrdiff_t num_blocks_hor)
Resize matrix.
humoto::pepper_mpc::ModelState initializeNextModelState(const humoto::pepper_mpc::Model &model) const
Initialize next model state.
Definition: mpc_mg.h:49
Eigen::MatrixXd Aas_
Definition: mpc_mg.h:349
etools::Matrix1x3 getDpd3(const double body_height, const double base_mass, const double body_mass) const
Create Dpd3 matrix.
MPCforMG(const humoto::pepper_mpc::MPCParameters &mpc_parameters)
Constructor.
Definition: mpc_mg.h:391
void setParameters(const humoto::pepper_mpc::MPCParameters &mpc_parameters)
Set parameters.
Definition: mpc_mg.h:403
etools::Vector3 getBd3(const double T) const
Create intermediate Bd3 matrix.
MPCforMG()
Constructor.
Definition: mpc_mg.h:380
Parameters of the motion.
Definition: common.h:176
Eigen::MatrixXd Apd_
Definition: mpc_mg.h:357
double getTheta() const
Get theta angle of the current state.
Definition: model.h:276
const DecayedRawMatrix & getRaw() const
Get raw matrix.
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
Definition: logger.h:555
void initialize(const SolutionStructure &sol_structure)
Initialize the solution vector.
Definition: solution.h:214
std::size_t sampling_time_ms_
Sampling time in milliseconds (T_ms)
Definition: common.h:316
etools::Vector6 getMPCBodyState() const
Get body state.
Definition: model.h:124
Eigen::MatrixXd Ap_
Definition: mpc_mg.h:345
Parameters of the MPC problem.
Definition: common.h:279
etools::DiagonalBlockMatrix< 2, 2 > R_
Definition: mpc_mg.h:337
Eigen::VectorXd sas_
Definition: mpc_mg.h:348
Location getSolutionPartLocation(const std::string &id) const
Get location of a data in the solution vector.
Definition: solution.h:122
void shift(MotionParameters &motion_parameters, const std::ptrdiff_t time_shift_ms=DEFAULT_PREVIEW_HORIZON_SHIFT)
Shift preview horizon.
Definition: mpc_mg.h:450
etools::Vector3 getBs3(const double T) const
Create intermediate Bs3 matrix.
humoto::pepper_mpc::MPCParameters mpc_parameters_
Definition: mpc_mg.h:373
Eigen::VectorXd spd_
Definition: mpc_mg.h:356
Eigen::VectorXd cop_profile_
Definition: mpc_mg.h:366
void shift(std::deque< MotionParameters > &motion_parameters_deque, const std::ptrdiff_t time_shift_ms=DEFAULT_PREVIEW_HORIZON_SHIFT)
Update control problem.
Definition: mpc_mg.h:478
etools::Matrix3 getAs3(const double T) const
Create intermediate As3 matrix.
The root namespace of HuMoTo.
Definition: config.h:12
const Eigen::VectorXd & get_x() const
Returns solution vector.
Definition: solution.h:337
bool form(const MPCParameters &mpc_params, const Model &model, const MotionParameters &motion_parameters)
Form the preview horizon object.
humoto::pepper_mpc::ModelState getModelState(const humoto::pepper_mpc::Model &model, const double time_instant)
Computes model state at the given time instant.
Definition: mpc_mg.h:680
etools::Vector6 getMPCBaseState() const
Get base state.
Definition: model.h:113
static const std::ptrdiff_t UNLIMITED_DURATION
Definition: common.h:190
double getEjs3(const double T) const
Create intermediate Esc6 matrix of final model.
humoto::pepper_mpc::ModelState getModelState(const humoto::pepper_mpc::Model &model, const std::size_t time_instant_ms)
Computes model state at the given time instant.
Definition: mpc_mg.h:659
Eigen::VectorXd sp_
Definition: mpc_mg.h:344
void formRotationMatrices()
Create the rotation matrices of the MPC problem.
Definition: mpc_mg.h:30
Preview horizon of an MPC [form_preview_horizon.m].
humoto::pepper_mpc::ModelState getNextModelState(const humoto::pepper_mpc::Model &model) const
Get next model state.
Definition: mpc_mg.h:598
humoto::pepper_mpc::ModelState getModelState(const humoto::pepper_mpc::Model &model, const std::size_t interval_index, const double interval_offset)
Computes model state at the given time instant.
Definition: mpc_mg.h:275
Model Predictive Control problem for walking pattern generation [determine_solution_structure.m, form_rotation_matrices.m, form_foot_pos_matrices.m, form_condensing_matrices.m].
Definition: mpc_mg.h:20
void guessSolution(Solution &solution_guess, const Solution &old_solution) const
Guess solution.
Definition: mpc_mg.h:613
LogEntryName & add(const char *name)
extends entry name with a subname
Definition: logger.h:232
std::size_t getPreviewHorizonLength() const
Returns length of the preview horizon.
Definition: mpc_mg.h:699
Location of a data chunk (offset + length).
Definition: utility.h:146
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="mpcmg") const
Log.
Definition: mpc_mg.h:713
void parseSolution(const humoto::Solution &solution)
Process solution.
Definition: mpc_mg.h:559
#define EIGENTOOLS_CONSTANT_SIZE_VECTOR(rows)
Definition: eigentools.h:58
etools::Matrix1x3 getDjs3(const double T) const
Create intermediate Dc6 matrix of final model.
Abstract base class for Model Predictive Control problems.
Eigen::MatrixXd Ajs_
Definition: mpc_mg.h:361
std::size_t offset_
Definition: utility.h:149
Eigen::VectorXd sjs_
Definition: mpc_mg.h:360
Provides block interface for arbitrary Matrix without copying it.
Definition: blockmatrix.h:49
Eigen::VectorXd sps_
Definition: mpc_mg.h:352
Eigen::MatrixXd Aps_
Definition: mpc_mg.h:353
void updateMatrices(const Model &model)
Condense and recompute all dependent matrices.
Definition: mpc_mg.h:80
humoto::pepper_mpc::ModelState getNextModelState(const humoto::Solution &solution, const humoto::pepper_mpc::Model &model)
Get next model state.
Definition: mpc_mg.h:581
humoto::pepper_mpc::PreviewHorizon preview_horizon_
Definition: mpc_mg.h:334