ImpedanceTask.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 
9 
10 #include <mc_filter/LowPass.h>
11 
12 #include <mc_rtc/constants.h>
13 
14 namespace mc_tasks
15 {
16 
17 namespace force
18 {
19 
53 {
54 public:
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56 
72  ImpedanceTask(const std::string & surfaceName,
73  const mc_rbdyn::Robots & robots,
74  unsigned robotIndex,
75  double stiffness = 5.0,
76  double weight = 1000.0);
77 
88  ImpedanceTask(const mc_rbdyn::RobotFrame & frame, double stiffness = 5.0, double weight = 1000.0);
89 
96  void reset() override;
97 
99  inline const ImpedanceGains & gains() const noexcept { return gains_; }
100 
102  inline ImpedanceGains & gains() noexcept { return gains_; }
103 
105  const sva::PTransformd & targetPose() const noexcept { return targetPoseW_; }
106 
108  void targetPose(const sva::PTransformd & pose) { targetPoseW_ = pose; }
109 
111  const sva::MotionVecd & targetVel() const noexcept { return targetVelW_; }
112 
114  void targetVel(const sva::MotionVecd & worldVel) override { targetVelW_ = worldVel; }
115 
117  const sva::MotionVecd & targetAccel() const noexcept { return targetAccelW_; }
118 
120  void targetAccel(const sva::MotionVecd & accel) { targetAccelW_ = accel; }
121 
123  const sva::PTransformd & deltaCompliancePose() const { return deltaCompPoseW_; }
124 
131  const sva::PTransformd compliancePose() const
132  {
133  sva::PTransformd T_0_d(targetPoseW_.rotation());
134  return T_0_d * deltaCompPoseW_ * T_0_d.inv() * targetPoseW_;
135  }
136 
138  const sva::ForceVecd & targetWrench() const noexcept { return targetWrench_; }
139 
144  void targetWrenchW(const sva::ForceVecd & wrenchW) { targetWrench(frame_->position().dualMul(wrenchW)); }
145 
147  void targetWrench(const sva::ForceVecd & wrench) { targetWrench_ = wrench; }
148 
150  const sva::ForceVecd & measuredWrench() const { return measuredWrench_; }
151 
153  const sva::ForceVecd & filteredMeasuredWrench() const { return filteredMeasuredWrench_; }
154 
156  double cutoffPeriod() const { return lowPass_.cutoffPeriod(); }
157 
159  void cutoffPeriod(double cutoffPeriod)
160  {
161  cutoffPeriod_ = cutoffPeriod;
162  lowPass_.cutoffPeriod(cutoffPeriod_);
163  }
164 
166  inline bool hold() const noexcept { return hold_; }
167 
178  inline void hold(bool hold) noexcept { hold_ = hold; }
179 
181  void load(mc_solver::QPSolver & solver, const mc_rtc::Configuration & config) override;
182 
183 protected:
185 
191  sva::PTransformd deltaCompPoseW_ = sva::PTransformd::Identity();
192  sva::MotionVecd deltaCompVelW_ = sva::MotionVecd::Zero();
193  sva::MotionVecd deltaCompAccelW_ = sva::MotionVecd::Zero();
195 
196  // Limits of relative pose, velocity, and acceleration from target frame to compliance frame.
197  double deltaCompPoseLinLimit_ = 1.0;
198  double deltaCompPoseAngLimit_ = mc_rtc::constants::PI;
199  double deltaCompVelLinLimit_ = 1e3;
200  double deltaCompVelAngLimit_ = 1e3;
201  double deltaCompAccelLinLimit_ = 1e3;
202  double deltaCompAccelAngLimit_ = 1e3;
203 
204  // Target pose, velocity, and acceleration in the world frame
205  sva::PTransformd targetPoseW_ = sva::PTransformd::Identity();
206  sva::MotionVecd targetVelW_ = sva::MotionVecd::Zero();
207  sva::MotionVecd targetAccelW_ = sva::MotionVecd::Zero();
208 
209  // Wrench in the surface frame
210  sva::ForceVecd targetWrench_ = sva::ForceVecd::Zero();
211  sva::ForceVecd measuredWrench_ = sva::ForceVecd::Zero();
212  sva::ForceVecd filteredMeasuredWrench_ = sva::ForceVecd::Zero();
213 
214  double cutoffPeriod_ = 0.05;
216 
217  // Hold mode
218  bool hold_ = false;
219 
220  void update(mc_solver::QPSolver & solver) override;
221 
222  void addToSolver(mc_solver::QPSolver & solver) override;
223  void addToGUI(mc_rtc::gui::StateBuilder & gui) override;
224  void addToLogger(mc_rtc::Logger & logger) override;
225 
226 private:
236 
237  /* \brief Same as targetPose(const sva::PTransformd &) */
238  void target(const sva::PTransformd & pos) override { targetPose(pos); }
239 
240  /* \brief Same as targetPose() */
241  sva::PTransformd target() const override { return targetPose(); }
242 };
243 
244 } // namespace force
245 
246 } // namespace mc_tasks
mc_tasks::force::ImpedanceTask::targetWrench
const sva::ForceVecd & targetWrench() const noexcept
Get the target wrench in the surface frame.
Definition: ImpedanceTask.h:138
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_rbdyn::Robots
Definition: Robots.h:15
mc_tasks::force::ImpedanceGains::Default
static ImpedanceGains Default()
Definition: ImpedanceGains.h:132
MC_TASKS_DLLAPI
#define MC_TASKS_DLLAPI
Definition: api.h:50
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_tasks::force::ImpedanceTask::cutoffPeriod
void cutoffPeriod(double cutoffPeriod)
Set the cutoff period for the low-pass filter of measured wrench.
Definition: ImpedanceTask.h:159
mc_tasks::force::ImpedanceGains
Represent impedance gains for an ImpedanceTask.
Definition: ImpedanceGains.h:95
mc_tasks::force::ImpedanceTask::targetVel
void targetVel(const sva::MotionVecd &worldVel) override
Set the target velocity of the surface in the world frame.
Definition: ImpedanceTask.h:114
mc_tasks::force::ImpedanceTask::filteredMeasuredWrench
const sva::ForceVecd & filteredMeasuredWrench() const
Get the filtered measured wrench in the surface frame.
Definition: ImpedanceTask.h:153
mc_tasks::force::ImpedanceTask::hold
void hold(bool hold) noexcept
Set hold mode.
Definition: ImpedanceTask.h:178
mc_tasks::force::ImpedanceTask::targetWrench
void targetWrench(const sva::ForceVecd &wrench)
Set the target wrench in the surface frame.
Definition: ImpedanceTask.h:147
mc_tasks::force::ImpedanceTask::compliancePose
const sva::PTransformd compliancePose() const
Get the compliance pose of the surface in the world frame.
Definition: ImpedanceTask.h:131
mc_tasks::force::ImpedanceTask::measuredWrench
const sva::ForceVecd & measuredWrench() const
Get the measured wrench in the surface frame.
Definition: ImpedanceTask.h:150
mc_rtc::Logger
Logs controller data to disk.
Definition: Logger.h:29
mc_tasks::force::ImpedanceTask::targetVel
const sva::MotionVecd & targetVel() const noexcept
Get the target velocity of the surface in the world frame.
Definition: ImpedanceTask.h:111
mc_rbdyn::RobotFrame
Definition: RobotFrame.h:21
mc_tasks::force::ImpedanceTask::gains
ImpedanceGains & gains() noexcept
Access the impedance gains.
Definition: ImpedanceTask.h:102
mc_filter::LowPass< sva::ForceVecd >
mc_tasks::TrajectoryTaskGeneric::refAccel
const Eigen::VectorXd & refAccel() const
Get the trajectory reference acceleration.
mc_tasks::force::ImpedanceTask::gains
const ImpedanceGains & gains() const noexcept
Access the impedance gains.
Definition: ImpedanceTask.h:99
mc_tasks::force::ImpedanceTask::lowPass_
mc_filter::LowPass< sva::ForceVecd > lowPass_
Definition: ImpedanceTask.h:215
mc_rtc::gui::StateBuilder
Definition: StateBuilder.h:27
mc_tasks::force::ImpedanceTask::targetAccel
const sva::MotionVecd & targetAccel() const noexcept
Get the target acceleration of the surface in the world frame.
Definition: ImpedanceTask.h:117
mc_tasks::TransformTask
Control a frame 6D pose.
Definition: TransformTask.h:15
mc_tasks::force::ImpedanceTask::hold
bool hold() const noexcept
Get whether hold mode is enabled.
Definition: ImpedanceTask.h:166
TransformTask.h
mc_tasks::TransformTask::refVelB
sva::MotionVecd refVelB() const
Get reference velocity in frame coordinates as a motion vector.
Definition: TransformTask.h:192
mc_rtc::constants::PI
constexpr double PI
Definition: constants.h:18
mc_tasks::force::ImpedanceTask::targetPose
void targetPose(const sva::PTransformd &pose)
Set the target pose of the surface in the world frame.
Definition: ImpedanceTask.h:108
constants.h
mc_tasks::force::ImpedanceTask::targetWrenchW
void targetWrenchW(const sva::ForceVecd &wrenchW)
Set the target wrench in the world frame. This function will convert the wrench from the world frame ...
Definition: ImpedanceTask.h:144
mc_tasks::force::ImpedanceTask
Impedance control of the end-effector.
Definition: ImpedanceTask.h:52
mc_tasks::force::ImpedanceTask::targetAccel
void targetAccel(const sva::MotionVecd &accel)
Set the target acceleration of the surface in the world frame.
Definition: ImpedanceTask.h:120
mc_tasks::force::ImpedanceTask::deltaCompliancePose
const sva::PTransformd & deltaCompliancePose() const
Get the relative pose from target frame to compliance frame represented in the world frame.
Definition: ImpedanceTask.h:123
mc_tasks::force::ImpedanceTask::cutoffPeriod
double cutoffPeriod() const
Get the cutoff period for the low-pass filter of measured wrench.
Definition: ImpedanceTask.h:156
mc_tasks
Definition: StabilizerStandingState.h:11
LowPass.h
mc_tasks::force::ImpedanceTask::targetPose
const sva::PTransformd & targetPose() const noexcept
Get the target pose of the surface in the world frame.
Definition: ImpedanceTask.h:105
ImpedanceGains.h