ComplianceTask.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 #include <mc_tasks/MetaTask.h>
9 
10 namespace mc_tasks
11 {
12 
13 namespace force
14 {
15 
25 {
26 public:
27  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 
29  static const std::pair<double, double> defaultFGain;
30  static const std::pair<double, double> defaultTGain;
31 
61  ComplianceTask(const mc_rbdyn::Robots & robots,
62  unsigned int robotIndex,
63  const std::string & body,
64  double timestep,
65  const Eigen::Matrix6d & dof = Eigen::Matrix6d::Identity(),
66  double stiffness = 5.0,
67  double weight = 1000.0,
68  double forceThresh = 3.,
69  double torqueThresh = 1.,
70  std::pair<double, double> forceGain = defaultFGain,
71  std::pair<double, double> torqueGain = defaultTGain);
72 
99  ComplianceTask(const mc_rbdyn::Robots & robots,
100  unsigned int robotIndex,
101  const std::string & body,
102  double timestep,
103  double stiffness = 5.0,
104  double weight = 1000.0,
105  double forceThresh = 3.,
106  double torqueThresh = 1.,
107  std::pair<double, double> forceGain = defaultFGain,
108  std::pair<double, double> torqueGain = defaultTGain);
109 
115  void reset() override;
116 
118  sva::ForceVecd getFilteredWrench() const;
119 
121  void setTargetWrench(const sva::ForceVecd & wrench) { obj_ = wrench; }
122 
124  sva::ForceVecd getTargetWrench() { return obj_; }
125 
127  void stiffness(double s)
128  {
129  efTask_->positionTask->stiffness(s);
130  efTask_->orientationTask->stiffness(s);
131  }
133  double stiffness() { return efTask_->positionTask->stiffness(); }
134 
136  void weight(double w)
137  {
138  efTask_->positionTask->weight(w);
139  efTask_->orientationTask->weight(w);
140  }
142  double weight() { return efTask_->positionTask->weight(); }
143 
145  void forceThresh(double t) { forceThresh_ = t; }
147  double forceThresh() { return forceThresh_; }
148 
150  void torqueThresh(double t) { torqueThresh_ = t; }
152  double torqueThresh() { return torqueThresh_; }
153 
155  void forceGain(std::pair<double, double> t) { forceGain_ = t; }
157  std::pair<double, double> forceGain() { return forceGain_; }
158 
160  void torqueGain(std::pair<double, double> t) { torqueGain_ = t; }
162  std::pair<double, double> torqueGain() { return torqueGain_; }
163 
165  void dof(const Eigen::Matrix6d & dof) { dof_ = dof; }
167  Eigen::Matrix6d dof() { return dof_; }
168 
169  void dimWeight(const Eigen::VectorXd & dimW) override;
170 
171  Eigen::VectorXd dimWeight() const override;
172 
173  void selectActiveJoints(mc_solver::QPSolver & solver,
174  const std::vector<std::string> & activeJointsName,
175  const std::map<std::string, std::vector<std::array<int, 2>>> & activeDofs = {}) override;
176 
177  void selectUnactiveJoints(mc_solver::QPSolver & solver,
178  const std::vector<std::string> & unactiveJointsName,
179  const std::map<std::string, std::vector<std::array<int, 2>>> & unactiveDofs = {}) override;
180 
181  void resetJointsSelector(mc_solver::QPSolver & solver) override;
182 
183  Eigen::VectorXd eval() const override { return wrench_.vector(); }
184 
185  Eigen::VectorXd speed() const override
186  {
187  return robots_.robot(rIndex_).mbc().bodyVelW[robots_.robot(rIndex_).bodyIndexByName(sensor_.parentBody())].vector();
188  }
189 
190 private:
191  sva::PTransformd computePose();
192 
193  std::shared_ptr<EndEffectorTask> efTask_;
194  sva::ForceVecd wrench_;
195  sva::ForceVecd obj_;
196  sva::ForceVecd error_;
197  sva::ForceVecd errorD_;
198  const mc_rbdyn::Robots & robots_;
199  unsigned int rIndex_;
200  const mc_rbdyn::ForceSensor & sensor_;
201  double timestep_;
202  double forceThresh_, torqueThresh_;
203  std::pair<double, double> forceGain_, torqueGain_;
204  Eigen::Matrix6d dof_;
205  std::function<double(double)> clampTrans_, clampRot_;
206 
207  void addToSolver(mc_solver::QPSolver & solver) override;
208 
209  void removeFromSolver(mc_solver::QPSolver & solver) override;
210 
211  void update(mc_solver::QPSolver &) override;
212 };
213 
214 } // namespace force
215 
216 } // namespace mc_tasks
mc_rbdyn::Robots
Definition: Robots.h:15
mc_tasks::force::ComplianceTask
Add a contact in a compliant manner.
Definition: ComplianceTask.h:24
mc_tasks::MetaTask
Represents a generic task.
Definition: MetaTask.h:39
mc_tasks::force::ComplianceTask::torqueThresh
double torqueThresh()
Get the torque threshold.
Definition: ComplianceTask.h:152
mc_tasks::force::ComplianceTask::defaultTGain
static const std::pair< double, double > defaultTGain
Definition: ComplianceTask.h:30
MC_TASKS_DLLAPI
#define MC_TASKS_DLLAPI
Definition: api.h:50
mc_tasks::force::ComplianceTask::weight
double weight()
Get the task weight.
Definition: ComplianceTask.h:142
EndEffectorTask.h
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_tasks::force::ComplianceTask::setTargetWrench
void setTargetWrench(const sva::ForceVecd &wrench)
Modify the target wrench.
Definition: ComplianceTask.h:121
mc_tasks::force::ComplianceTask::forceThresh
double forceThresh()
Get the force threshold.
Definition: ComplianceTask.h:147
mc_tasks::force::ComplianceTask::speed
Eigen::VectorXd speed() const override
Returns the task velocity.
Definition: ComplianceTask.h:185
mc_tasks::force::ComplianceTask::forceGain
std::pair< double, double > forceGain()
Get the force gain.
Definition: ComplianceTask.h:157
mc_tasks::force::ComplianceTask::eval
Eigen::VectorXd eval() const override
Returns the task error.
Definition: ComplianceTask.h:183
mc_tasks::force::ComplianceTask::dof
Eigen::Matrix6d dof()
Get the current dof matrix.
Definition: ComplianceTask.h:167
mc_rbdyn::ForceSensor
Definition: ForceSensor.h:19
mc_tasks::force::ComplianceTask::stiffness
double stiffness()
Get the task stiffness.
Definition: ComplianceTask.h:133
mc_tasks::force::ComplianceTask::torqueGain
std::pair< double, double > torqueGain()
Get the torque gain.
Definition: ComplianceTask.h:162
mc_tasks::force::ComplianceTask::getTargetWrench
sva::ForceVecd getTargetWrench()
Get the current target wrench.
Definition: ComplianceTask.h:124
mc_tasks::force::ComplianceTask::dof
void dof(const Eigen::Matrix6d &dof)
Set the current dof matrix.
Definition: ComplianceTask.h:165
mc_tasks::force::ComplianceTask::stiffness
void stiffness(double s)
Set the task stiffness.
Definition: ComplianceTask.h:127
mc_tasks::force::ComplianceTask::torqueThresh
void torqueThresh(double t)
Set the torque threshold.
Definition: ComplianceTask.h:150
mc_tasks::force::ComplianceTask::forceThresh
void forceThresh(double t)
Set the force threshold.
Definition: ComplianceTask.h:145
MetaTask.h
mc_tasks::force::ComplianceTask::torqueGain
void torqueGain(std::pair< double, double > t)
Set the torque gain.
Definition: ComplianceTask.h:160
mc_tasks::force::ComplianceTask::forceGain
void forceGain(std::pair< double, double > t)
Set the force gain.
Definition: ComplianceTask.h:155
mc_tasks::force::ComplianceTask::defaultFGain
static const EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::pair< double, double > defaultFGain
Definition: ComplianceTask.h:29
mc_tasks::force::ComplianceTask::weight
void weight(double w)
Set the task weight.
Definition: ComplianceTask.h:136
mc_tasks
Definition: StabilizerStandingState.h:11