mc_rtc  2.14.0
AdmittanceTask.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2022 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 
10 
11 namespace mc_tasks
12 {
13 
14 namespace force
15 {
16 
39 {
40 public:
41  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42 
55  double stiffness = 5.0,
56  double weight = 1000.0,
57  bool showTarget = true,
58  bool showPose = true);
59 
77  AdmittanceTask(const std::string & robotSurface,
78  const mc_rbdyn::Robots & robots,
79  unsigned robotIndex,
80  double stiffness = 5.0,
81  double weight = 1000.0,
82  bool showTarget = true,
83  bool showPose = true);
84 
92  void reset() override;
93 
97  const sva::ForceVecd & admittance() const { return admittance_; }
98 
104  void admittance(const sva::ForceVecd & admittance) { admittance_ = admittance; }
105 
107  sva::PTransformd surfacePose() const { return frame_->position(); }
108 
110  sva::PTransformd targetPose() { return this->target(); }
111 
117  void targetPose(const sva::PTransformd & X_0_target) { this->target(X_0_target); }
118 
120  sva::PTransformd poseError() { return targetPose() * surfacePose().inv(); }
121 
123  const sva::ForceVecd & targetWrench() const { return targetWrench_; }
124 
129  void targetWrenchW(const sva::ForceVecd & wrenchW) { targetWrench(frame_->position().dualMul(wrenchW)); }
130 
136  void targetWrench(const sva::ForceVecd & wrench) { targetWrench_ = wrench; }
137 
139  sva::ForceVecd measuredWrench() const { return frame_->wrench(); }
140 
142  void maxLinearVel(const Eigen::Vector3d & maxLinearVel)
143  {
144  if((maxLinearVel.array() <= 0.).any())
145  {
146  mc_rtc::log::error("discarding maxLinearVel update as it is not positive");
147  ;
148  return;
149  }
150  maxLinearVel_ = maxLinearVel;
151  }
152 
154  const Eigen::Vector3d & maxLinearVel() const noexcept { return maxLinearVel_; }
155 
157  void maxAngularVel(const Eigen::Vector3d & maxAngularVel)
158  {
159  if((maxAngularVel.array() <= 0.).any())
160  {
161  mc_rtc::log::error("discarding maxAngularVel update as it is not positive");
162  ;
163  return;
164  }
165  maxAngularVel_ = maxAngularVel;
166  }
167 
169  const Eigen::Vector3d & maxAngularVel() const noexcept { return maxAngularVel_; }
170 
175  void velFilterGain(double gain) { velFilterGain_ = mc_filter::utils::clamp(gain, 0, 1); }
176 
178  double velFilterGain() const noexcept { return velFilterGain_; }
179 
193  void refVelB(const sva::MotionVecd & velB) { feedforwardVelB_ = velB; }
194 
196  void load(mc_solver::QPSolver & solver, const mc_rtc::Configuration & config) override;
197 
198 protected:
199  Eigen::Vector3d maxAngularVel_ = {0.1, 0.1, 0.1}; // [rad] / [s]
200  Eigen::Vector3d maxLinearVel_ = {0.1, 0.1, 0.1}; // [m] / [s]
201  double timestep_;
202  double velFilterGain_ = 0.8; //< Gain for the low-pass filter on reference velocity [0..1]
203  sva::ForceVecd admittance_ = sva::ForceVecd(Eigen::Vector6d::Zero());
204  sva::ForceVecd targetWrench_ = sva::ForceVecd(Eigen::Vector6d::Zero());
205  sva::ForceVecd wrenchError_ = sva::ForceVecd(Eigen::Vector6d::Zero());
206  sva::MotionVecd feedforwardVelB_ = sva::MotionVecd(Eigen::Vector6d::Zero());
207  sva::MotionVecd refVelB_ = sva::MotionVecd(Eigen::Vector6d::Zero());
208 
209  void update(mc_solver::QPSolver &) override;
210 
211  void addToGUI(mc_rtc::gui::StateBuilder & gui) override;
212  void addToLogger(mc_rtc::Logger & logger) override;
213 
214  bool showTarget_ = true;
215  bool showPose_ = true;
216 
219 
221  using TransformTask::target;
222 
226  void addToSolver(mc_solver::QPSolver & solver) override;
227 };
228 
229 } // namespace force
230 
231 } // namespace mc_tasks
#define MC_TASKS_DLLAPI
Definition: api.h:50
double clamp(double value, double lower, double upper)
Definition: clamp.h:29
void error(Args &&... args)
Definition: logging.h:63
Definition: StabilizerStandingState.h:12
Definition: RobotFrame.h:22
Definition: Robots.h:16
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
Logs controller data to disk.
Definition: Logger.h:30
Definition: StateBuilder.h:28
Definition: QPSolver.h:86
Control a frame 6D pose.
Definition: TransformTask.h:16
sva::MotionVecd refVelB() const
Get reference velocity in frame coordinates as a motion vector.
Definition: TransformTask.h:198
virtual sva::PTransformd target() const
Get the task's target.
Hybrid position-force control on a contacting end-effector.
Definition: AdmittanceTask.h:39
void reset() override
Reset the task.
void load(mc_solver::QPSolver &solver, const mc_rtc::Configuration &config) override
Load parameters from a Configuration object.
void maxAngularVel(const Eigen::Vector3d &maxAngularVel)
Set the maximum angular velocity of the task.
Definition: AdmittanceTask.h:157
sva::PTransformd surfacePose() const
Get the current pose of the control frame in the inertial frame.
Definition: AdmittanceTask.h:107
AdmittanceTask(const std::string &robotSurface, const mc_rbdyn::Robots &robots, unsigned robotIndex, double stiffness=5.0, double weight=1000.0, bool showTarget=true, bool showPose=true)
Initialize a new admittance task.
void velFilterGain(double gain)
Set the gain of the low-pass filter on the reference velocity.
Definition: AdmittanceTask.h:175
void refVelB(const sva::MotionVecd &velB)
Set the reference body velocity.
Definition: AdmittanceTask.h:193
void addToGUI(mc_rtc::gui::StateBuilder &gui) override
sva::PTransformd targetPose()
Get the target pose of the control frame in the world frame.
Definition: AdmittanceTask.h:110
void admittance(const sva::ForceVecd &admittance)
Set the admittance coefficients of the task.
Definition: AdmittanceTask.h:104
void maxLinearVel(const Eigen::Vector3d &maxLinearVel)
Set the maximum translation velocity of the task.
Definition: AdmittanceTask.h:142
void addToSolver(mc_solver::QPSolver &solver) override
void targetPose(const sva::PTransformd &X_0_target)
Set target pose (position and orientation) of the frame in the world frame.
Definition: AdmittanceTask.h:117
void targetWrench(const sva::ForceVecd &wrench)
Set the target wrench in the control frame.
Definition: AdmittanceTask.h:136
const sva::ForceVecd & admittance() const
Get the admittance coefficients of the task.
Definition: AdmittanceTask.h:97
sva::PTransformd poseError()
Transform from current frame pose to target.
Definition: AdmittanceTask.h:120
sva::ForceVecd measuredWrench() const
Get the measured wrench in the control frame.
Definition: AdmittanceTask.h:139
void addToLogger(mc_rtc::Logger &logger) override
EIGEN_MAKE_ALIGNED_OPERATOR_NEW AdmittanceTask(const mc_rbdyn::RobotFrame &frame, double stiffness=5.0, double weight=1000.0, bool showTarget=true, bool showPose=true)
Initialize a new admittance task.
double timestep_
Definition: AdmittanceTask.h:201
const Eigen::Vector3d & maxLinearVel() const noexcept
Definition: AdmittanceTask.h:154
const sva::ForceVecd & targetWrench() const
Get the target wrench in the control frame.
Definition: AdmittanceTask.h:123
void update(mc_solver::QPSolver &) override
Update the task.
void targetWrenchW(const sva::ForceVecd &wrenchW)
Set the target wrench in world frame.
Definition: AdmittanceTask.h:129
const Eigen::Vector3d & maxAngularVel() const noexcept
Definition: AdmittanceTask.h:169
double velFilterGain() const noexcept
Return the gain of the low-pass filter on the reference velocity.
Definition: AdmittanceTask.h:178