ocra-recipes
Doxygen documentation for the ocra-recipes repository
|
Wocra Controller based on LQP solver for the ocra framework. More...
#include <WocraController.h>
Classes | |
struct | Pimpl |
Public Member Functions | |
WocraController (const std::string &ctrlName, std::shared_ptr< Model > innerModel, std::shared_ptr< OneLevelSolver > innerSolver, bool useReducedProblem) | |
virtual | ~WocraController () |
Destructor of Wocra controller. More... | |
std::shared_ptr< Model > | getModel () |
std::shared_ptr< OneLevelSolver > | getSolver () |
bool | isUsingReducedProblem () |
void | setVariableMinimizationWeights (double w_ddq, double w_tau, double w_fc) |
void | takeIntoAccountGravity (bool useGrav) |
void | writePerformanceInStream (std::ostream &myOstream, bool addCommaAtEnd) const |
std::string | getPerformances () const |
void | addConstraint (ocra::LinearConstraint &constraint) const |
void | removeConstraint (ocra::LinearConstraint &constraint) const |
void | addConstraint (ocra::ControlConstraint &constraint) const |
void | removeConstraint (ocra::ControlConstraint &constraint) const |
Public Member Functions inherited from ocra::Controller | |
virtual | ~Controller ()=0 |
void | printInfo (int level, const std::string &filename) |
void | setMaxJointTorques (const Eigen::VectorXd &tau_max) |
const Eigen::VectorXd & | getMaxJointTorques () const |
void | addTask (std::shared_ptr< Task > task) |
void | addTasks (const std::vector< std::shared_ptr< Task >> &tasks) |
void | removeTask (const std::string &taskName) |
void | removeTasks (const std::vector< std::string > tasks) |
std::vector< std::string > | getTaskNames () |
std::string | getTaskPortName (const std::string &taskName) |
std::vector< std::string > | getTaskPortNames () |
void | addContactSet (const ContactSet &contacts) |
std::shared_ptr< Task > | getTask (const std::string &name) |
const std::shared_ptr< Task > | getTask (const std::string &name) const |
const std::map< std::string, std::shared_ptr< Task > > & | getTasks () const |
void | computeOutput (Eigen::VectorXd &tau) |
Computation of output torques based on the tasks added to the controller. More... | |
const Eigen::VectorXd & | computeOutput () |
std::shared_ptr< Task > | createContactTask (const std::string &name, PointContactFeature::Ptr feature, double mu, double margin) const |
Creates a contact task. More... | |
std::shared_ptr< Task > | createTask (const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const |
Generic task creation. More... | |
std::shared_ptr< Task > | createTask (const std::string &name, Feature::Ptr feature) const |
void | enableErrorHandling () |
void | disableErrorHandling () |
bool | isErrorHandlingEnabled () const |
const std::string & | getErrorMessage () const |
void | clearErrorFlag () |
int | getErrorFlag () const |
void | setMaxJointTorqueNorm (double maxTau) |
double | getMaxJointTorqueNorm () const |
void | setFixedLinkForOdometry (std::string newFixedLink) |
void | setUseOdometry (bool useOdometry) |
void | getFixedLinkForOdometry (std::string ¤tFixedLink) |
void | setContactState (int isInLeftSupport, int isInRightSupport) |
void | getContactState (int &leftSupport, int &rightSupport) |
Public Member Functions inherited from ocra::NamedInstance | |
NamedInstance (const std::string &name) | |
const std::string & | getName () const |
virtual | ~NamedInstance () |
Protected Member Functions | |
virtual void | doComputeOutput (Eigen::VectorXd &tau) |
virtual void | doAddTask (std::shared_ptr< Task > task) |
virtual void | doAddContactSet (const ContactSet &contacts) |
virtual std::shared_ptr< Task > | doCreateTask (const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const |
virtual std::shared_ptr< Task > | doCreateTask (const std::string &name, Feature::Ptr feature) const |
virtual std::shared_ptr< Task > | doCreateContactTask (const std::string &name, PointContactFeature::Ptr feature, double mu, double margin) const |
Protected Member Functions inherited from ocra::Controller | |
Controller (const std::string &name, Model &model) | |
const std::vector< std::shared_ptr< Task > > & | getActiveTasks () const |
void | setErrorFlag (int eflag) |
void | setErrorMessage (const std::string &msg) |
virtual void | doSetMaxJointTorques (const Eigen::VectorXd &tauMax) |
Additional Inherited Members | |
Public Types inherited from ocra::Controller | |
enum | ErrorFlag { SUCCESS = 0, CRITICAL_ERROR = 1, STATIC_EQ_LOSS = 2, DYN_EQ_LOSS = 4, INSTABILITY = 8 + 1, OTHER = 16 } |
Error handling. More... | |
Wocra Controller based on LQP solver for the ocra framework.
This controller is a generic optimization-based whole-body dynamic one, which can deal with tasks transitions. The multi-task management and their sequencing is done with a weighting strategy. A mechanical system presents different control issues regarding its limitations and physical constraints which are passed to the optimization problem as equality and inequality constraints. The controller will correct the error between actual and desired states by, for example, minimizing an error resulting from the quadratic norm of their difference. This error will be minimized through a Linear Quadratic Program (LQP), which is composed by a quadratic cost function with linear constraints.
The following are types of internal and external physical constraints of the system, describing a robot and its interaction with the environment:
All the previous constraints are linear except for the unilateral frictional contacts, which represent the constraint of the contact forces lying in the Coulomb friction cone and is nonlinear, but at least quadratic. To deal with these kinds of constraints the WOCRA controller will rely on the LQP formulation, since it is simpler and more suitable for the real-time dynamic control of humanoid robots.
Wocra will address the low-level control of the robot through the concept of tasks, i.e. the control of one or more DoF of the system towards objectives which are generally the minimization of tracking errors. Tasks are composed of two main elements, the subset of the controlled DoF and their desired goals (For more details on tasks, see ()). An example of a task function is the norm of an error.
Different tasks can be mixed in wocra to achieve a desired high-level motion. These tasks will be subject to the aforementioned equality and inequality constraints, which motivate the use of an LQP, which solves the following problem:
Where is the vector to optimize, , and represent the quadratic cost function, , define the inequality constraints and , define the equality constraints, which are the concatenation of the different constraints previously mentioned. The controller thus builds these matrices according to the tasks and the constraints acting on the robot and, when the solution is found, extracts the input torque vector to actuate the system. can be replaced by which we also denote by the dynamic variable , where is further referred to as the action variable.
But the story does not end here. In particular, Wocra will use a weighting strategy which associates each task with a coefficient that sets its importance with respect to the others (a task with a higher weights gets a higher priority). The first point is to set these coefficients as real values. As a consequence, priorities are not strict and all tasks are achieved according to the trade-off defined by the weights. Given a set of tasks and their related weights one solves their weighted sum subject to the concatenation of the constraints. The task is dedicated to the minimization of the whole optimization variable. This is required when the control problem has many solutions, in order to ensure the uniqueness and more specifically to provide a solution that minimizes the input torque vector . has a very small weight with respect to the others to limit the induced error. This program is solved only one time per call.
The algorithm consists then in finding , the solution of the problem:
[salini2012Thesis].
Definition at line 101 of file WocraController.h.
wocra::WocraController::WocraController | ( | const std::string & | ctrlName, |
std::shared_ptr< Model > | innerModel, | ||
std::shared_ptr< OneLevelSolver > | innerSolver, | ||
bool | useReducedProblem | ||
) |
Initializes Wocra controller.
During the instantiation of this class a WocraController::Pimpl object is created. This object, in turn, will specify the constraints (robot dynamics) and objectives ( ) for the solver, as well as its relative minimization weights and will take into account gravity.
ctrlName | The name of the controller |
innerModel | The internal model of the robot one wants to control |
innerSolver | The internal solver one wants to use to make the quadratic optimization |
useReducedProblem | Tell if the redundant problem is considered (unknown variable is ), or is the reduced problem (non-redundant) is considred (unknown variable is ) |
Definition at line 80 of file WocraController.cpp.
|
virtual |
Destructor of Wocra controller.
It disconnects all the tasks connected to the controller, then it disconnects the inner objectives that minimize the problem variables, and finally it disconnects the dynamic equation constraint (if needed).
Definition at line 116 of file WocraController.cpp.
void wocra::WocraController::addConstraint | ( | ocra::LinearConstraint & | constraint | ) | const |
Adds a Linear constraint that is equivalent for the full & reduced problems.
Linear | constraint. |
Definition at line 181 of file WocraController.cpp.
void wocra::WocraController::addConstraint | ( | ocra::ControlConstraint & | constraint | ) | const |
Adds a Linear constraint that has different expressions, depending on the problem type. In this case, the constraint needs to be connected to the controller to get the matrices for the problem reduction. See wocra::ControlConstraint for more info.
constraint | Constraint. |
Definition at line 191 of file WocraController.cpp.
|
protectedvirtual |
Internal implementation inside the addContactSet method.
contacts | The contact set to add in the controller. |
Implements ocra::Controller.
Definition at line 214 of file WocraController.cpp.
|
protectedvirtual |
Internal implementation inside the addTask method.
task | The task to add in the controller. |
Implements ocra::Controller.
Definition at line 203 of file WocraController.cpp.
|
protectedvirtual |
Computes the output of the controller.
Here, the controller solves the optimization problem depending on the tasks and constraints, and the result is set in the variable of the problem, either or . The torque variable is finally applied to the robot.
tau | The torque variable, which is the output of our problem. |
Implements ocra::Controller.
Definition at line 278 of file WocraController.cpp.
|
protectedvirtual |
Internal implementation inside the createContactTask method.
name | The task name, a unique identifier |
feature | The contact point feature of the robot one wants to control |
mu | The friction cone coefficient such as |
margin | The margin inside the friction cone |
This method is called by the higher level methods createWocraContactTask(const std::string&, PointContactFeature::Ptr, , double, double) const and is the concrete implementation required by the ocra::Controller class.
Implements ocra::Controller.
Definition at line 266 of file WocraController.cpp.
|
protectedvirtual |
Internal implementation inside the createTask method.
name | The task name, a unique identifier |
feature | The part of the robot one wants to control (full state, frame, CoM,...) |
featureDes | The desired state one wants to reach, depends on the feature argument |
This method is called by the higher level methods createWocraTask(const std::string&, const Feature&, const Feature&) const and is the concrete implementation required by the ocra Controller class.
Create an WocraTask.
Implements ocra::Controller.
Definition at line 256 of file WocraController.cpp.
|
protectedvirtual |
Internal implementation inside the createTask method.
name | The task name, a unique identifier |
feature | The part of the robot one wants to control (full state, frame, CoM,...) |
This method is called by the higher level methods #createWocraTask(const std::string&, const Feature&) const and is the concrete implementation required by the ocra Controller class.
Implements ocra::Controller.
Definition at line 261 of file WocraController.cpp.
std::shared_ptr< Model > wocra::WocraController::getModel | ( | ) |
Returns the inner model.
Definition at line 145 of file WocraController.cpp.
std::string wocra::WocraController::getPerformances | ( | ) | const |
Get information about performances through a string.
Information are saved in a JSON way (http://www.json.org/). It returns a dictionnary of the form:
where performance_info are:
See wocra::WocraController::writePerformanceInStream(std::ostream&, bool) const and wocra::OneLevelSolver::writePerformanceInStream(std::ostream&, bool).
Definition at line 321 of file WocraController.cpp.
std::shared_ptr< OneLevelSolver > wocra::WocraController::getSolver | ( | ) |
Returns the inner solver.
Definition at line 153 of file WocraController.cpp.
bool wocra::WocraController::isUsingReducedProblem | ( | ) |
true
if variable of reduced problem ( ) is considered, or false
if it uses the variable of the full one ( ). Definition at line 161 of file WocraController.cpp.
void wocra::WocraController::removeConstraint | ( | ocra::LinearConstraint & | constraint | ) | const |
Removes a Linear constraint that is equivalent for the full & reduced problems.
Linear | Constraint to remove. |
Definition at line 186 of file WocraController.cpp.
void wocra::WocraController::removeConstraint | ( | ocra::ControlConstraint & | constraint | ) | const |
Removes a Linear constraint that has different expressions, depending on the problem type. In this case, the constraint needs to be disconnected from the controller.
constraint | Constraint. |
Definition at line 197 of file WocraController.cpp.
void wocra::WocraController::setVariableMinimizationWeights | ( | double | w_ddq, |
double | w_tau, | ||
double | w_fc | ||
) |
Sets weights for the objectives that minimize the norm of the problem variables: .
w_ddq | weight for the minimization of . |
w_tau | weight for the minimization of . |
w_fc | weight for the minimization of . |
Definition at line 169 of file WocraController.cpp.
void wocra::WocraController::takeIntoAccountGravity | ( | bool | useGrav | ) |
Whether to take into account gavity in the dynamic equation of motion.
useGrav | true if gravity is enable, false otherwise. |
Definition at line 176 of file WocraController.cpp.
void wocra::WocraController::writePerformanceInStream | ( | std::ostream & | myOstream, |
bool | addCommaAtEnd | ||
) | const |
Writes information about controller performances in a string stream.
outstream | the output stream where to write the performances information |
addCommaAtEnd | If true, add a comma at the end of the stream. If false, it means that this is the end of the json file, nothing will be added after that. |
See wocra::WocraController::getPerformances() to know more. Here it saves:
Definition at line 309 of file WocraController.cpp.