34 R_.setZero(preview_horizon_.getNumberOfVariableSteps());
35 Rh_.setZero(preview_horizon_.intervals_.size());
37 std::size_t index = 0;
38 for(std::size_t i=0; i < (preview_horizon_.walk_states_.size() - 1); ++i)
43 R_(index) = preview_horizon_.walk_states_.at(i).rotation_;
49 for(std::size_t i=0; i < preview_horizon_.intervals_.size(); ++i)
51 Rh_(i) = preview_horizon_.getRotationMatrix(i);
67 Ir_.setZero(preview_horizon_.intervals_.size(), preview_horizon_.getNumberOfVariableSteps());
69 for(std::size_t i=0; i < preview_horizon_.variable_steps_indices_.size(); ++i)
71 EigenIndex row_size = preview_horizon_.intervals_.size() - preview_horizon_.variable_steps_indices_[i];
72 Ir_.block(preview_horizon_.variable_steps_indices_[i], i, row_size, 1).setConstant(1);
79 Vfp_.noalias() = Eigen::Matrix2d::Identity().replicate(
80 preview_horizon_.getNumberOfVariableSteps(),
81 preview_horizon_.getNumberOfVariableSteps()).triangularView<Eigen::Lower>() * R_.
getRaw();
101 double T = preview_horizon_.intervals_[0].T_;
103 double com_height = preview_horizon_.intervals_[0].com_height_;
110 cop_profile.segment(0, model.
Nu_));
148 getFootLandingState(model_state.
feet_[landing_foot], model, landing_foot);
185 std::size_t interval_index = preview_horizon_.variable_steps_indices_[0];
186 const WalkState & walk_state = preview_horizon_.getWalkState(interval_index);
190 etools::Vector2 position_xy;
195 switch (walk_state.
type_)
199 position_xy = footpos_profile.segment(0, 2);
208 footpos_profile.segment(0, 2));
212 HUMOTO_THROW_MSG(
"Double support cannot be followed by another double support.");
217 HUMOTO_THROW_MSG(
"Transitional double support cannot have variable position.");
221 foot_state.
position_ << position_xy, position_z;
223 foot_state.
rpy_.setZero();
263 solution_is_parsed_ =
false;
273 : velocity_selector_(3,1)
275 solution_is_parsed_ =
false;
276 setParameters(mpc_parameters);
287 mpc_parameters_ = mpc_parameters;
306 solution_is_parsed_ =
false;
308 if (preview_horizon_.
form( mpc_parameters_,
314 sol_structure_.reset();
322 formRotationMatrices();
323 formFootPosMatrices(model);
327 std::vector<etools::Matrix3> A_matrices;
328 std::vector<etools::Vector3> B_matrices;
330 std::vector<etools::Matrix1x3> D_matrices;
331 std::vector<double> E_matrices;
342 double omega = preview_horizon_.
intervals_[i].omega_;
344 A_matrices[i] = model.
getA3(T, omega);
345 B_matrices[i] = model.
getB3(T, omega);
347 D_matrices[i] = model.
getD3(T, omega);
348 E_matrices[i] = model.
getE3(T);
354 condense(Ux, Uu, A_matrices, B_matrices);
358 condenseOutput(Ox, Ou, D_matrices, E_matrices, Ux, Uu);
369 S_.
resize (number_of_state_variables, sol_structure_.getNumberOfVariables ());
391 return (control_status);
402 Eigen::VectorXd mpc_variables;
403 Eigen::VectorXd cop_local;
404 Eigen::VectorXd footpos_local;
409 mpc_variables.resize(cop_local.rows() + footpos_local.rows());
410 mpc_variables << cop_local, footpos_local;
412 cop_profile.noalias() = Rh_ * cop_local + V_ * footpos_local + V0_;
413 dcop_profile.noalias() = Sdz_ * mpc_variables + sdz_;
414 cstate_profile.noalias() = S_ * mpc_variables + s_;
416 footpos_profile.noalias() = Vfp_ * footpos_local + vfp_;
418 solution_is_parsed_ =
true;
436 HUMOTO_ASSERT(solution_is_parsed_ ==
false,
"The solution is parsed.");
437 parseSolution(solution);
438 return(initializeNextModelState(stance_fsm, model));
454 HUMOTO_ASSERT(solution_is_parsed_ ==
true,
"This function can be called only after the solution is parsed.");
455 return(initializeNextModelState(stance_fsm, model));
469 HUMOTO_ASSERT(solution_is_parsed_ ==
true,
"This function can be called only after the solution is parsed.");
472 "This function can be executed in a single support only.");
505 solution_guess.
initialize(sol_structure_, 0.0);
518 solution_guess.
getData(guess_part) = old_solution.
getData(old_part);
527 solution_guess.
getData(guess_part) = old_solution.
getData(old_part);
535 solution_guess.
getData(guess_part) = old_solution.
getData(old_part);
540 solution_guess.
getData(guess_part) = old_solution.
getData(old_part);
556 const std::size_t time_instant_ms)
558 HUMOTO_ASSERT(solution_is_parsed_ ==
true,
"This function can be called only after the solution is parsed.");
559 std::size_t interval_index;
560 std::size_t time_offset_ms = time_instant_ms;
561 std::size_t interval_duration_ms;
564 for (interval_index = 0; interval_index < preview_horizon_.
intervals_.size(); ++interval_index)
566 interval_duration_ms = preview_horizon_.
intervals_[interval_index].T_ms_;
567 if (time_offset_ms > interval_duration_ms)
569 time_offset_ms -= interval_duration_ms;
573 com_height = preview_horizon_.
intervals_[interval_index].com_height_;
579 "Given time instant is not included in the preview horizon.");
582 etools::Vector6 preceding_cstate;
583 etools::Vector2 control;
586 if (interval_index == 0)
592 preceding_cstate = cstate_profile.segment((interval_index - 1)*model.
Ns_, model.
Ns_);
594 control = cop_profile.segment(interval_index*2, 2);
628 const std::string &name =
"mpcwpg")
const 632 preview_horizon_.
log(logger, subname);
651 logger.log(
LogEntryName(subname).add(
"cop_profile") , cop_profile);
652 logger.log(
LogEntryName(subname).add(
"dcop_profile") , dcop_profile);
653 logger.log(
LogEntryName(subname).add(
"cstate_profile") , cstate_profile);
654 logger.log(
LogEntryName(subname).add(
"footpos_profile"), footpos_profile);
void setParameters(const humoto::wpg04::MPCParameters &mpc_parameters)
Set parameters.
humoto::rigidbody::RigidBodyState getFootState(const humoto::LeftOrRight::Type left_or_right) const
Returns current foot state.
static double getE3(const double T)
Create E matrix of final model.
std::size_t getNumberOfVariables() const
Get total number of variables in the solution vector.
etools::DiagonalBlockMatrix< 2, 2 > Rh_
humoto::rigidbody::PointMassState com_state_
State of the CoM.
static const char * COP_VARIABLES_ID
Class that groups together parameters related to a robot foot.
std::size_t preview_horizon_length_
Length of the preview horizon (N)
Preview horizon of an MPC [form_preview_horizon.m].
etools::Vector2 current_support_position_
2d position of the current support (center of a foot or ADS)
const int Nu_
Number of control variables.
Eigen::VectorXd footpos_profile
Eigen::VectorBlock< Eigen::VectorXd > getSolutionPart(const std::string &id)
Get part of the solution by its id.
const std::size_t Ns_
Number of state variables.
double getSubsamplingTime() const
getSubsamplingTime
etools::Vector3 position_
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
#define HUMOTO_ASSERT(condition, message)
Eigen::VectorBlock< Eigen::VectorXd > getData(const Location &location)
Get data from solution vector.
Parameters of an MPC problem. [set_parameters_mpc.m].
double HUMOTO_LOCAL convertMillisecondToSecond(const std::size_t milliseconds)
Converts milliseconds to seconds.
walking::StanceType::Type next_stance_type_
next stance type
Container of the solution.
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
Represents log entry name.
void setRight(const t_Data &data)
Get/set/copy left or right object.
bool isNonEmpty() const
Checks if the structure is empty or not.
EIGEN_DEFAULT_DENSE_INDEX_TYPE EigenIndex
humoto::wpg04::ModelState getNextModelState(const humoto::Solution &solution, const humoto::walking::StanceFiniteStateMachine &stance_fsm, const humoto::wpg04::Model &model)
Get next model state.
std::size_t getNumberOfVariableSteps() const
Returns number of variable steps in the preview.
Class containing options of the walking pattern generator.
static humoto::rigidbody::PointMassState evaluate(const double Ts, const double T, const double com_height, const etools::Vector6 &cstate, const etools::Vector2 &control)
void guessSolution(Solution &solution_guess, const Solution &old_solution) const
Guess solution.
humoto::LeftRightContainer< humoto::rigidbody::RigidBodyState > feet_
States of the feet.
Transitional double support.
humoto::wpg04::ModelState getNextModelState(const humoto::walking::StanceFiniteStateMachine &stance_fsm, const humoto::wpg04::Model &model) const
Get next model state.
void parseSolution(const humoto::Solution &solution)
Process solution.
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
void unset()
Initialize state (everything is set to NaN).
void initialize(const SolutionStructure &sol_structure)
Initialize the solution vector.
bool form(const MPCParameters &mpc_params, const Model &model, const humoto::walking::StanceFiniteStateMachine &stance_fsm, const WalkParameters &walk_parameters)
Form the preview horizon object.
static etools::Matrix1x3 getD3(const double T, const double omega)
Create D matrix of final model.
std::vector< PreviewHorizonInterval > intervals_
Eigen::VectorXd cstate_profile
static const char * FOOTPOS_VARIABLES_ID
void setLeft(const t_Data &data)
Get/set/copy left or right object.
etools::Vector6 getCState() const
Get cstate.
Location getSolutionPartLocation(const std::string &id) const
Get location of a data in the solution vector.
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].
etools::DiagonalBlockMatrix< 2, 2 > R_
etools::Matrix2 rotation_
The root namespace of HuMoTo.
walking::StanceType::Type stance_type_
current stance type
void log(humoto::Logger &, const LogEntryName &, const std::string &) const
Log.
Class that groups together parmeters related to a robot foot.
etools::SelectionMatrix velocity_selector_
t_Data & getRight()
Get/set/copy left or right object.
Eigen::VectorXd dcop_profile
void formFootPosMatrices(const humoto::wpg04::Model &model)
Create the foot position matrices.
std::size_t getPreviewHorizonLength() const
Returns length of the preview horizon.
Stance getNextStance() const
Preview next walk state of the FSM.
MPCforWPG(const humoto::wpg04::MPCParameters &mpc_parameters)
Constructor.
humoto::rigidbody::RigidBodyState getFootLandingState(const humoto::wpg04::Model &model) const
Get landing state of a foot.
A class representing a "state" of the walk.
humoto::wpg04::ModelState state_
state of the model
ControlProblemStatus::Status update(const humoto::wpg04::Model &model, const humoto::walking::StanceFiniteStateMachine &stance_fsm, const humoto::wpg04::WalkParameters &walk_parameters)
Update control problem.
static etools::Vector3 getB3(const double T, const double omega, const double Tsample)
Create B matrix of final model.
void getFootLandingState(humoto::rigidbody::RigidBodyState &foot_state, const humoto::wpg04::Model &model, const humoto::LeftOrRight::Type landing_foot) const
Determine landing state of a foot.
humoto::rigidbody::PointMassState getCoMState(const humoto::wpg04::Model &model, const std::size_t time_instant_ms)
Computes CoM state at the given time instant.
static etools::Matrix3 getA3(const double T, const double omega, const double Tsample)
Create A matrix of final model.
Finite state machine for walking. [initialize_contact_walk_fsm.m].
humoto::wpg04::ModelState initializeNextModelState(const humoto::walking::StanceFiniteStateMachine &stance_fsm, const humoto::wpg04::Model &model) const
Initialize next model state.
void formRotationMatrices()
Create the rotation matrices of the MPC problem.
LogEntryName & add(const char *name)
extends entry name with a subname
t_Data & getLeft()
Get/set/copy left or right object.
Location of a data chunk (offset + length).
Eigen::VectorXd cop_profile
humoto::wpg04::MPCParameters mpc_parameters_
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="mpcwpg") const
Log.
Abstract base class for Model Predictive Control problems.
void setDefaults()
Initialize state (everything is set to zeros).
static Type invert(const Type left_or_right)
Exchange left and right.
humoto::wpg04::PreviewHorizon preview_horizon_