mc_rtc  2.14.0
SplineTrajectoryTask.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 
11 
12 namespace mc_tasks
13 {
14 
36 template<typename Derived>
38 {
43 
44  static std::vector<std::pair<double, Eigen::Matrix3d>> loadOriWaypoints(const mc_rtc::Configuration & c);
45 
61  double duration,
62  double stiffness,
63  double weight,
64  const Eigen::Matrix3d & target,
65  const std::vector<std::pair<double, Eigen::Matrix3d>> & oriWp = {});
66 
68  void load(mc_solver::QPSolver & solver, const mc_rtc::Configuration & config) override;
69 
78  std::function<bool(const mc_tasks::MetaTask &, std::string &)> buildCompletionCriteria(
79  double dt,
80  const mc_rtc::Configuration & config) const override;
81 
86  void oriWaypoints(const std::vector<std::pair<double, Eigen::Matrix3d>> & oriWp);
87 
102  // Ensures that accessors from the base class are available
106 
116  void dimWeight(const Eigen::VectorXd & dimW) override;
117 
122  Eigen::VectorXd dimWeight() const override;
123 
132  void stiffness(double stiffness);
133 
146  void stiffness(const Eigen::VectorXd & stiffness);
147 
154  void damping(double damping);
155 
166  void damping(const Eigen::VectorXd & damping);
167 
176  void setGains(double stiffness, double damping);
177 
191  void setGains(const Eigen::VectorXd & stiffness, const Eigen::VectorXd & damping);
192 
206  void dimWeightInterpolation(const std::vector<std::pair<double, Eigen::Vector6d>> & dimWeights);
207  inline const std::vector<std::pair<double, Eigen::Vector6d>> & dimWeightInterpolation() const noexcept
208  {
210  }
211 
226  void stiffnessInterpolation(const std::vector<std::pair<double, Eigen::Vector6d>> & stiffnessGains);
227  inline const std::vector<std::pair<double, Eigen::Vector6d>> & stiffnessInterpolation() const noexcept
228  {
230  }
231 
245  void dampingInterpolation(const std::vector<std::pair<double, Eigen::Vector6d>> & dampingGains);
246  inline const std::vector<std::pair<double, Eigen::Vector6d>> & dampingInterpolation() const noexcept
247  {
248  return dampingInterpolator_.values();
249  }
250 
257  bool timeElapsed() const;
258 
264  Eigen::VectorXd eval() const override;
265 
272  virtual Eigen::VectorXd evalTracking() const;
273 
280  void target(const sva::PTransformd & target);
285  const sva::PTransformd target() const;
286 
291  void displaySamples(unsigned s);
296  unsigned displaySamples() const;
297 
312  inline void pause(bool paused) { paused_ = paused; }
313 
315  inline bool pause() const noexcept { return paused_; }
316 
318  inline double currentTime() const noexcept { return currTime_; }
319 
321  inline double duration() const noexcept { return duration_; }
322 
323 protected:
329  void refPose(const sva::PTransformd & pose);
335  const sva::PTransformd & refPose() const;
336 
337  /* Hide parent's refVel and refAccel implementation as the Spline tasks
338  * are overriding these at every iteration according to the underlying curve */
341 
346  void addToGUI(mc_rtc::gui::StateBuilder & gui) override;
347 
352  void addToLogger(mc_rtc::Logger & logger) override;
353 
355  void update(mc_solver::QPSolver &) override;
356 
359 
360 protected:
362  double duration_ = 0;
364  // Linear interpolation for gains
368 
369  bool paused_ = false;
370 
371  double currTime_ = 0.;
372  unsigned samples_ = 20;
373  bool inSolver_ = false;
374 };
375 } // namespace mc_tasks
376 
377 #include <mc_tasks/SplineTrajectoryTask.hpp>
std::shared_ptr< const RobotFrame > ConstRobotFramePtr
Definition: fwd.h:25
Definition: StabilizerStandingState.h:12
Definition: RobotFrame.h:22
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
Represents a generic task.
Definition: MetaTask.h:40
Generic CRTP implementation for a task tracking a curve in both position and orientation....
Definition: SplineTrajectoryTask.h:38
void stiffness(const Eigen::VectorXd &stiffness)
Set dimensional stiffness.
const std::vector< std::pair< double, Eigen::Vector6d > > & dimWeightInterpolation() const noexcept
Sets the dimensional weights (controls the importance of orientation/translation).
Definition: SplineTrajectoryTask.h:207
void damping(double damping)
Set the task damping, leaving its stiffness unchanged.
double currentTime() const noexcept
Definition: SplineTrajectoryTask.h:318
bool timeElapsed() const
Whether the trajectory has finished.
void stiffnessInterpolation(const std::vector< std::pair< double, Eigen::Vector6d >> &stiffnessGains)
void damping(const Eigen::VectorXd &damping)
Set dimensional damping.
double currTime_
Definition: SplineTrajectoryTask.h:371
void dimWeightInterpolation(const std::vector< std::pair< double, Eigen::Vector6d >> &dimWeights)
void target(const sva::PTransformd &target)
Sets the curve target pose. Translation target will be handled by the Derived curve,...
void stiffness(double stiffness)
Set the task stiffness/damping.
const sva::PTransformd & refPose() const
Returns the trajectory reference world pose.
Eigen::VectorXd eval() const override
Returns the transformError between current robot surface pose and its final target.
double duration_
Definition: SplineTrajectoryTask.h:362
void displaySamples(unsigned s)
Number of points to sample on the spline for the gui display.
Eigen::VectorXd dimWeight() const override
Gets the dimensional weights (orientation/translation)
std::function< bool(const mc_tasks::MetaTask &, std::string &)> buildCompletionCriteria(double dt, const mc_rtc::Configuration &config) const override
unsigned samples_
Definition: SplineTrajectoryTask.h:372
void load(mc_solver::QPSolver &solver, const mc_rtc::Configuration &config) override
Load parameters from a Configuration object.
void update(mc_solver::QPSolver &) override
Update trajectory target.
void refPose(const sva::PTransformd &pose)
Tracks a reference world pose.
double duration() const noexcept
Returns the trajectory's duration.
Definition: SplineTrajectoryTask.h:321
SequenceInterpolator6d stiffnessInterpolator_
Definition: SplineTrajectoryTask.h:366
const sva::PTransformd target() const
Gets the target pose (position/orientation)
void setGains(double stiffness, double damping)
Set both stiffness and damping.
bool pause() const noexcept
Definition: SplineTrajectoryTask.h:315
mc_rbdyn::ConstRobotFramePtr frame_
Definition: SplineTrajectoryTask.h:361
const std::vector< std::pair< double, Eigen::Vector6d > > & stiffnessInterpolation() const noexcept
Sets the dimensional weights (controls the importance of orientation/translation).
Definition: SplineTrajectoryTask.h:227
mc_trajectory::InterpolatedRotation oriSpline_
Definition: SplineTrajectoryTask.h:363
void setGains(const Eigen::VectorXd &stiffness, const Eigen::VectorXd &damping)
Set dimensional stiffness and damping.
void dampingInterpolation(const std::vector< std::pair< double, Eigen::Vector6d >> &dampingGains)
void addToLogger(mc_rtc::Logger &logger) override
Add information about the task to the logger.
void dimWeight(const Eigen::VectorXd &dimW) override
Sets the dimensional weights (controls the importance of orientation/translation).
const std::vector< std::pair< double, Eigen::Vector6d > > & dampingInterpolation() const noexcept
Sets the dimensional weights (controls the importance of orientation/translation).
Definition: SplineTrajectoryTask.h:246
void stiffness(double stiffness)
Set the task stiffness/damping.
bool inSolver_
Definition: SplineTrajectoryTask.h:373
unsigned displaySamples() const
Number of samples for displaying the spline.
SequenceInterpolator6d dimWeightInterpolator_
Definition: SplineTrajectoryTask.h:365
SplineTrajectoryTask(const mc_rbdyn::RobotFrame &frame, double duration, double stiffness, double weight, const Eigen::Matrix3d &target, const std::vector< std::pair< double, Eigen::Matrix3d >> &oriWp={})
Constructor.
void damping(double damping)
Set the task damping, leaving its stiffness unchanged.
virtual Eigen::VectorXd evalTracking() const
Returns the trajectory tracking error: transformError between the current robot surface pose and its ...
void oriWaypoints(const std::vector< std::pair< double, Eigen::Matrix3d >> &oriWp)
Sets the orientation waypoints.
void pause(bool paused)
Allows to pause the task.
Definition: SplineTrajectoryTask.h:312
SequenceInterpolator6d dampingInterpolator_
Definition: SplineTrajectoryTask.h:367
bool paused_
Definition: SplineTrajectoryTask.h:369
static std::vector< std::pair< double, Eigen::Matrix3d > > loadOriWaypoints(const mc_rtc::Configuration &c)
void addToGUI(mc_rtc::gui::StateBuilder &gui) override
Add task controls to the GUI. Interactive controls for the trajectory waypoints and end-endpoints aut...
Generic wrapper for a trajectory dynamic over an error function.
Definition: TrajectoryTaskGeneric.h:27
double damping() const
Get the current task damping.
Eigen::VectorXd dimWeight() const override
Get the current task's dim weight vector.
double stiffness() const
Get the current task stiffness.
const Eigen::VectorXd & refAccel() const
Get the trajectory reference acceleration.
double weight() const
Returns the task weight.
const Eigen::VectorXd & refVel() const
Get the trajectory reference velocity.
TrajectoryTaskGeneric(const mc_rbdyn::Robots &robots, unsigned int robotIndex, double stiffness, double weight)
Constructor (auto damping)
Describes a trajectory with smoothly interpolate rotation between waypoints.
Definition: InterpolatedRotation.h:23
void values(const TimedValueVector &values)
Set interpolator values.
Definition: SequenceInterpolator.h:82