mc_solver::QPSolver Class Referenceabstract

#include <mc_solver/QPSolver.h>

Inheritance diagram for mc_solver::QPSolver:
Collaboration diagram for mc_solver::QPSolver:

Classes

struct  ControllerToken
 

Public Types

enum  Backend { Backend::Unset, Backend::Tasks, Backend::TVM }
 

Public Member Functions

 QPSolver (mc_rbdyn::RobotsPtr robots, double timeStep, Backend backend)
 
 QPSolver (double timeStep, Backend backend)
 
virtual ~QPSolver ()=default
 
Backend backend () const noexcept
 
void addConstraintSet (ConstraintSet &cs)
 
template<typename T >
void addConstraintSet (const std::unique_ptr< T > &ptr)
 
void removeConstraintSet (ConstraintSet &cs)
 
template<typename T >
void removeConstraintSet (const std::unique_ptr< T > &ptr)
 
void addTask (mc_tasks::MetaTask *task)
 
void addTask (std::shared_ptr< mc_tasks::MetaTask > task)
 
void removeTask (mc_tasks::MetaTask *task)
 
void removeTask (std::shared_ptr< mc_tasks::MetaTask > task)
 
void setContacts (const std::vector< mc_rbdyn::Contact > &contacts={})
 
virtual void setContacts (ControllerToken, const std::vector< mc_rbdyn::Contact > &contacts)=0
 
const std::vector< mc_rbdyn::Contact > & contacts () const noexcept
 
const std::vector< mc_solver::ConstraintSet * > & constraints () const noexcept
 
const std::vector< mc_tasks::MetaTask * > & tasks () const noexcept
 
virtual const sva::ForceVecd desiredContactForce (const mc_rbdyn::Contact &id) const =0
 
bool run (FeedbackType fType=FeedbackType::None)
 
const mc_rbdyn::Robotrobot () const
 
mc_rbdyn::Robotrobot ()
 
mc_rbdyn::Robotrobot (unsigned int idx)
 
const mc_rbdyn::Robotrobot (unsigned int idx) const
 
const mc_rbdyn::Robotenv () const
 
mc_rbdyn::Robotenv ()
 
const mc_rbdyn::Robotsrobots () const
 
mc_rbdyn::Robotsrobots ()
 
const mc_rbdyn::RobotsrealRobots () const
 
mc_rbdyn::RobotsrealRobots ()
 
double dt () const
 
virtual double solveTime ()=0
 
virtual double solveAndBuildTime ()=0
 
void logger (std::shared_ptr< mc_rtc::Logger > logger)
 
std::shared_ptr< mc_rtc::Loggerlogger () const
 
void gui (std::shared_ptr< mc_rtc::gui::StateBuilder > gui)
 
std::shared_ptr< mc_rtc::gui::StateBuildergui () const
 
void controller (mc_control::MCController *ctl) noexcept
 
const mc_control::MCControllercontroller () const noexcept
 
mc_control::MCControllercontroller () noexcept
 

Static Public Member Functions

static Backend context_backend ()
 
static void context_backend (Backend backend)
 

Protected Member Functions

void addTaskToGUI (mc_tasks::MetaTask *task)
 
virtual bool run_impl (FeedbackType fType=FeedbackType::None)=0
 
virtual void addDynamicsConstraint (mc_solver::DynamicsConstraint *dynamics)=0
 
virtual void removeDynamicsConstraint (mc_solver::ConstraintSet *maybe_dynamics)=0
 

Protected Attributes

Backend backend_
 
mc_rbdyn::RobotsPtr robots_p
 
mc_rbdyn::RobotsPtr realRobots_p
 
double timeStep
 
std::vector< mc_rbdyn::Contactcontacts_
 
std::vector< mc_tasks::MetaTask * > metaTasks_
 
std::vector< std::shared_ptr< void > > shPtrTasksStorage
 
std::vector< mc_solver::ConstraintSet * > constraints_
 
std::shared_ptr< mc_rtc::Loggerlogger_ = nullptr
 
std::shared_ptr< mc_rtc::gui::StateBuildergui_ = nullptr
 
mc_control::MCControllercontroller_ = nullptr
 

Detailed Description

Abstract base class for wrapping a solver

Always ensure that the solver is up-to-date

Member Enumeration Documentation

◆ Backend

Known backends for QPSolver implementation, tasks and constraints in mc_rtc can discriminate on this value to select the implementation

Enumerator
Unset 

Unset

Tasks 

Use Tasks library as a backend

TVM 

Use TVM library as a backend

Constructor & Destructor Documentation

◆ QPSolver() [1/2]

mc_solver::QPSolver::QPSolver ( mc_rbdyn::RobotsPtr  robots,
double  timeStep,
Backend  backend 
)

Constructor

Parameters
robotsSet of robots managed by this solver
timeStepTimestep of the solver
Note
The real robots will be created by copying the provided robots

◆ QPSolver() [2/2]

mc_solver::QPSolver::QPSolver ( double  timeStep,
Backend  backend 
)

Constructor (the solver creates its own Robots instance)

Parameters
timeStepTimestep of the solver

◆ ~QPSolver()

virtual mc_solver::QPSolver::~QPSolver ( )
virtualdefault

Member Function Documentation

◆ addConstraintSet() [1/2]

template<typename T >
void mc_solver::QPSolver::addConstraintSet ( const std::unique_ptr< T > &  ptr)
inline

Add a constraint set

Parameters
csConstraint set added to the solver

◆ addConstraintSet() [2/2]

void mc_solver::QPSolver::addConstraintSet ( ConstraintSet cs)

Add a constraint set

Parameters
csConstraint set added to the solver

◆ addDynamicsConstraint()

virtual void mc_solver::QPSolver::addDynamicsConstraint ( mc_solver::DynamicsConstraint dynamics)
protectedpure virtual

This is called when a dynamics constraint is added to the solver

◆ addTask() [1/2]

void mc_solver::QPSolver::addTask ( mc_tasks::MetaTask task)

Add a task to the solver

Adding the same task multiple times has no effect.

Parameters
taskPointer to an mc_tasks::MetaTask, QPSolver does not take ownership of this pointer. The MetaTask update function will be automatically called before the optimization is solved.

◆ addTask() [2/2]

void mc_solver::QPSolver::addTask ( std::shared_ptr< mc_tasks::MetaTask task)
inline

Add a task to the solver, ownership is shared with the solver

◆ addTaskToGUI()

void mc_solver::QPSolver::addTaskToGUI ( mc_tasks::MetaTask task)
protected

◆ backend()

Backend mc_solver::QPSolver::backend ( ) const
inlinenoexcept

Returns the backend for this solver instance

◆ constraints()

const std::vector<mc_solver::ConstraintSet *>& mc_solver::QPSolver::constraints ( ) const
inlinenoexcept

Returns the current set of constraints

◆ contacts()

const std::vector<mc_rbdyn::Contact>& mc_solver::QPSolver::contacts ( ) const
inlinenoexcept

Returns the current set of contacts

◆ context_backend() [1/2]

static Backend mc_solver::QPSolver::context_backend ( )
static

Returns the current context backend

This should be set whenever constraints or tasks are about to be created and it is known they don't use the solver object and thus cannot determine the correct backend

For example:

  • QPSolver implementations should set it on the thread it's created
  • ConstraintSetLoader and MetaTasksLoader set it before loading objects
  • MCGlobalController sets it before run
  • You might need to set it if you create tasks in a thread you created

◆ context_backend() [2/2]

static void mc_solver::QPSolver::context_backend ( Backend  backend)
static

Set the current context backend

◆ controller() [1/3]

const mc_control::MCController* mc_solver::QPSolver::controller ( ) const
inlinenoexcept

Returns the controller owning this instance (if any) (const)

◆ controller() [2/3]

mc_control::MCController* mc_solver::QPSolver::controller ( )
inlinenoexcept

Returns the controller owning this instance (if any)

◆ controller() [3/3]

void mc_solver::QPSolver::controller ( mc_control::MCController ctl)
inlinenoexcept

Set the controller that is owning this QPSolver instance

◆ desiredContactForce()

virtual const sva::ForceVecd mc_solver::QPSolver::desiredContactForce ( const mc_rbdyn::Contact id) const
pure virtual

Desired resultant of contact force in robot surface frame

Parameters
contactContact for which the force is desired. This contact must be one of the active contacts in the solver.
Returns
Contact force in robot surface frame

Implemented in mc_solver::TasksQPSolver, and mc_solver::TVMQPSolver.

◆ dt()

double mc_solver::QPSolver::dt ( ) const

Returns the timestep of the solver

Returns
The timestep of the solver

◆ env() [1/2]

mc_rbdyn::Robot& mc_solver::QPSolver::env ( )

Gives access to the environment robot in the solver (see mc_rbdyn::Robots)

◆ env() [2/2]

const mc_rbdyn::Robot& mc_solver::QPSolver::env ( ) const

Gives access to the environment robot in the solver (see mc_rbdyn::Robots)

◆ gui() [1/2]

std::shared_ptr<mc_rtc::gui::StateBuilder> mc_solver::QPSolver::gui ( ) const

Access to the gui instance

◆ gui() [2/2]

void mc_solver::QPSolver::gui ( std::shared_ptr< mc_rtc::gui::StateBuilder gui)

Set the GUI helper for this solver instance

◆ logger() [1/2]

std::shared_ptr<mc_rtc::Logger> mc_solver::QPSolver::logger ( ) const

Access to the logger instance

◆ logger() [2/2]

void mc_solver::QPSolver::logger ( std::shared_ptr< mc_rtc::Logger logger)

Set the logger for this solver instance

◆ realRobots() [1/2]

mc_rbdyn::Robots& mc_solver::QPSolver::realRobots ( )

Gives access to the real robots used by this solver

◆ realRobots() [2/2]

const mc_rbdyn::Robots& mc_solver::QPSolver::realRobots ( ) const

Gives access to the real robots used by this solver

◆ removeConstraintSet() [1/2]

template<typename T >
void mc_solver::QPSolver::removeConstraintSet ( const std::unique_ptr< T > &  ptr)
inline

Remove a constraint set

Parameters
csConstraint set removed from the solver

◆ removeConstraintSet() [2/2]

void mc_solver::QPSolver::removeConstraintSet ( ConstraintSet cs)

Remove a constraint set

Parameters
csConstrain set removed from the solver

◆ removeDynamicsConstraint()

virtual void mc_solver::QPSolver::removeDynamicsConstraint ( mc_solver::ConstraintSet maybe_dynamics)
protectedpure virtual

This is called anytime a constraint is removed, the passed constraint is not always a dynamics constraint

◆ removeTask() [1/2]

void mc_solver::QPSolver::removeTask ( mc_tasks::MetaTask task)

Remove a task from the solver

Removing a task that is not in the solver has no effect.

Parameters
taskPointer to an mc_tasks::MetaTask. The task will not be updated anymore and memory should be released by the task's owner.

◆ removeTask() [2/2]

void mc_solver::QPSolver::removeTask ( std::shared_ptr< mc_tasks::MetaTask task)
inline

Remove a task from the solver which was shared with the solver

◆ robot() [1/4]

mc_rbdyn::Robot& mc_solver::QPSolver::robot ( )

Gives access to the main robot in the solver

◆ robot() [2/4]

const mc_rbdyn::Robot& mc_solver::QPSolver::robot ( ) const

Gives access to the main robot in the solver

◆ robot() [3/4]

mc_rbdyn::Robot& mc_solver::QPSolver::robot ( unsigned int  idx)

Gives access to the robot with the given index in the solver

◆ robot() [4/4]

const mc_rbdyn::Robot& mc_solver::QPSolver::robot ( unsigned int  idx) const

Gives access to the robot with the given index in the solver

◆ robots() [1/2]

mc_rbdyn::Robots& mc_solver::QPSolver::robots ( )

Gives access to the robots controlled by this solver

◆ robots() [2/2]

const mc_rbdyn::Robots& mc_solver::QPSolver::robots ( ) const

Gives access to the robots controlled by this solver

◆ run()

bool mc_solver::QPSolver::run ( FeedbackType  fType = FeedbackType::None)

Run one iteration of the QP.

If succesful, will update the robots' configurations

Parameters
fTypeType of feedback used to close the loop on sensory information
Returns
True if successful, false otherwise.

◆ run_impl()

virtual bool mc_solver::QPSolver::run_impl ( FeedbackType  fType = FeedbackType::None)
protectedpure virtual

Should run the control prroblem and update the control robot accordingly

◆ setContacts() [1/2]

void mc_solver::QPSolver::setContacts ( const std::vector< mc_rbdyn::Contact > &  contacts = {})

Reset all contacts in the solver and use the new set of contacts provided \item contact Set of mc_rbdyn::Contact

◆ setContacts() [2/2]

virtual void mc_solver::QPSolver::setContacts ( ControllerToken  ,
const std::vector< mc_rbdyn::Contact > &  contacts 
)
pure virtual

◆ solveAndBuildTime()

virtual double mc_solver::QPSolver::solveAndBuildTime ( )
pure virtual

Returns the building and solving time in ms

Implemented in mc_solver::TasksQPSolver, and mc_solver::TVMQPSolver.

◆ solveTime()

virtual double mc_solver::QPSolver::solveTime ( )
pure virtual

Returns the solving time in ms

Implemented in mc_solver::TasksQPSolver, and mc_solver::TVMQPSolver.

◆ tasks()

const std::vector<mc_tasks::MetaTask *>& mc_solver::QPSolver::tasks ( ) const
inlinenoexcept

Returns the MetaTasks currently in the solver

Member Data Documentation

◆ backend_

Backend mc_solver::QPSolver::backend_
protected

◆ constraints_

std::vector<mc_solver::ConstraintSet *> mc_solver::QPSolver::constraints_
protected

Holds ConstraintSet currently in the solver

◆ contacts_

std::vector<mc_rbdyn::Contact> mc_solver::QPSolver::contacts_
protected

Holds mc_rbdyn::Contact in the solver

◆ controller_

mc_control::MCController* mc_solver::QPSolver::controller_ = nullptr
protected

Can be nullptr if this not associated to any controller

◆ gui_

std::shared_ptr<mc_rtc::gui::StateBuilder> mc_solver::QPSolver::gui_ = nullptr
protected

Pointer to the GUI helper

◆ logger_

std::shared_ptr<mc_rtc::Logger> mc_solver::QPSolver::logger_ = nullptr
protected

Pointer to the Logger

◆ metaTasks_

std::vector<mc_tasks::MetaTask *> mc_solver::QPSolver::metaTasks_
protected

Holds MetaTask currently in the solver

◆ realRobots_p

mc_rbdyn::RobotsPtr mc_solver::QPSolver::realRobots_p
protected

◆ robots_p

mc_rbdyn::RobotsPtr mc_solver::QPSolver::robots_p
protected

◆ shPtrTasksStorage

std::vector<std::shared_ptr<void> > mc_solver::QPSolver::shPtrTasksStorage
protected

Storage for shared_pointer on tasks

◆ timeStep

double mc_solver::QPSolver::timeStep
protected

The documentation for this class was generated from the following file: