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 
59  double duration,
60  double stiffness,
61  double weight,
62  const Eigen::Matrix3d & target,
63  const std::vector<std::pair<double, Eigen::Matrix3d>> & oriWp = {});
64 
66  void load(mc_solver::QPSolver & solver, const mc_rtc::Configuration & config) override;
67 
76  std::function<bool(const mc_tasks::MetaTask &, std::string &)> buildCompletionCriteria(
77  double dt,
78  const mc_rtc::Configuration & config) const override;
79 
84  void oriWaypoints(const std::vector<std::pair<double, Eigen::Matrix3d>> & oriWp);
85 
100  // Ensures that accessors from the base class are available
104 
114  void dimWeight(const Eigen::VectorXd & dimW) override;
115 
120  Eigen::VectorXd dimWeight() const override;
121 
130  void stiffness(double stiffness);
131 
144  void stiffness(const Eigen::VectorXd & stiffness);
145 
152  void damping(double damping);
153 
164  void damping(const Eigen::VectorXd & damping);
165 
174  void setGains(double stiffness, double damping);
175 
189  void setGains(const Eigen::VectorXd & stiffness, const Eigen::VectorXd & damping);
190 
204  void dimWeightInterpolation(const std::vector<std::pair<double, Eigen::Vector6d>> & dimWeights);
205  inline const std::vector<std::pair<double, Eigen::Vector6d>> & dimWeightInterpolation() const noexcept
206  {
208  }
209 
224  void stiffnessInterpolation(const std::vector<std::pair<double, Eigen::Vector6d>> & stiffnessGains);
225  inline const std::vector<std::pair<double, Eigen::Vector6d>> & stiffnessInterpolation() const noexcept
226  {
228  }
229 
243  void dampingInterpolation(const std::vector<std::pair<double, Eigen::Vector6d>> & dampingGains);
244  inline const std::vector<std::pair<double, Eigen::Vector6d>> & dampingInterpolation() const noexcept
245  {
246  return dampingInterpolator_.values();
247  }
248 
255  bool timeElapsed() const;
256 
262  Eigen::VectorXd eval() const override;
263 
270  virtual Eigen::VectorXd evalTracking() const;
271 
278  void target(const sva::PTransformd & target);
283  const sva::PTransformd target() const;
284 
289  void displaySamples(unsigned s);
294  unsigned displaySamples() const;
295 
310  inline void pause(bool paused) { paused_ = paused; }
311 
313  inline bool pause() const noexcept { return paused_; }
314 
316  inline double currentTime() const noexcept { return currTime_; }
317 
319  inline double duration() const noexcept { return duration_; }
320 
321 protected:
327  void refPose(const sva::PTransformd & pose);
333  const sva::PTransformd & refPose() const;
334 
335  /* Hide parent's refVel and refAccel implementation as the Spline tasks
336  * are overriding these at every iteration according to the underlying curve */
339 
344  void addToGUI(mc_rtc::gui::StateBuilder & gui) override;
345 
350  void addToLogger(mc_rtc::Logger & logger) override;
351 
353  void update(mc_solver::QPSolver &) override;
354 
356  void interpolateGains();
357 
358 protected:
360  double duration_ = 0;
362  // Linear interpolation for gains
366 
367  bool paused_ = false;
368 
369  double currTime_ = 0.;
370  unsigned samples_ = 20;
371  bool inSolver_ = false;
372 };
373 } // namespace mc_tasks
374 
375 #include <mc_tasks/SplineTrajectoryTask.hpp>
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_tasks::SplineTrajectoryTask::update
void update(mc_solver::QPSolver &) override
Update trajectory target.
mc_tasks::SplineTrajectoryTask::duration_
double duration_
Definition: SplineTrajectoryTask.h:360
mc_tasks::TrajectoryTaskGeneric::damping
double damping() const
Get the current task damping.
mc_trajectory::InterpolatedRotation
Describes a trajectory with smoothly interpolate rotation between waypoints.
Definition: InterpolatedRotation.h:21
mc_tasks::SplineTrajectoryTask::dimWeight
Eigen::VectorXd dimWeight() const override
Gets the dimensional weights (orientation/translation)
SequenceInterpolator.h
mc_tasks::MetaTask
Represents a generic task.
Definition: MetaTask.h:39
mc_tasks::SplineTrajectoryTask::inSolver_
bool inSolver_
Definition: SplineTrajectoryTask.h:371
mc_tasks::SplineTrajectoryTask::pause
bool pause() const noexcept
Definition: SplineTrajectoryTask.h:313
mc_tasks::TrajectoryTaskGeneric::refVel
const Eigen::VectorXd & refVel() const
Get the trajectory reference velocity.
mc_tasks::SplineTrajectoryTask::stiffnessInterpolator_
SequenceInterpolator6d stiffnessInterpolator_
Definition: SplineTrajectoryTask.h:364
mc_trajectory::SequenceInterpolator< Eigen::Vector6d, mc_trajectory::LinearInterpolation< Eigen::Vector6d > >
mc_tasks::SplineTrajectoryTask::addToLogger
void addToLogger(mc_rtc::Logger &logger) override
Add information about the task to the logger.
mc_tasks::SplineTrajectoryTask::frame_
mc_rbdyn::ConstRobotFramePtr frame_
Definition: SplineTrajectoryTask.h:359
InterpolatedRotation.h
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_tasks::SplineTrajectoryTask::setGains
void setGains(double stiffness, double damping)
Set both stiffness and damping.
mc_tasks::SplineTrajectoryTask::samples_
unsigned samples_
Definition: SplineTrajectoryTask.h:370
mc_tasks::SplineTrajectoryTask::paused_
bool paused_
Definition: SplineTrajectoryTask.h:367
mc_tasks::SplineTrajectoryTask::displaySamples
unsigned displaySamples() const
Number of samples for displaying the spline.
mc_tasks::TrajectoryTaskGeneric::weight
double weight() const
Returns the task weight.
mc_tasks::SplineTrajectoryTask
Generic CRTP implementation for a task tracking a curve in both position and orientation....
Definition: SplineTrajectoryTask.h:37
mc_tasks::SplineTrajectoryTask::refPose
const sva::PTransformd & refPose() const
Returns the trajectory reference world pose.
mc_tasks::SplineTrajectoryTask::load
void load(mc_solver::QPSolver &solver, const mc_rtc::Configuration &config) override
Load parameters from a Configuration object.
mc_tasks::SplineTrajectoryTask::timeElapsed
bool timeElapsed() const
Whether the trajectory has finished.
mc_rtc::Logger
Logs controller data to disk.
Definition: Logger.h:29
mc_tasks::TrajectoryTaskGeneric::stiffness
double stiffness() const
Get the current task stiffness.
mc_tasks::SplineTrajectoryTask::interpolateGains
void interpolateGains()
mc_rbdyn::RobotFrame
Definition: RobotFrame.h:21
mc_tasks::SplineTrajectoryTask::duration
double duration() const noexcept
Returns the trajectory's duration.
Definition: SplineTrajectoryTask.h:319
mc_tasks::SplineTrajectoryTask::stiffnessInterpolation
const std::vector< std::pair< double, Eigen::Vector6d > > & stiffnessInterpolation() const noexcept
Sets the dimensional weights (controls the importance of orientation/translation).
Definition: SplineTrajectoryTask.h:225
mc_tasks::TrajectoryTaskGeneric::dimWeight
Eigen::VectorXd dimWeight() const override
Get the current task's dim weight vector.
mc_tasks::TrajectoryTaskGeneric::refAccel
const Eigen::VectorXd & refAccel() const
Get the trajectory reference acceleration.
mc_tasks::SplineTrajectoryTask::addToGUI
void addToGUI(mc_rtc::gui::StateBuilder &gui) override
Add task controls to the GUI. Interactive controls for the trajectory waypoints and end-endpoints aut...
mc_tasks::SplineTrajectoryTask::buildCompletionCriteria
std::function< bool(const mc_tasks::MetaTask &, std::string &)> buildCompletionCriteria(double dt, const mc_rtc::Configuration &config) const override
mc_tasks::SplineTrajectoryTask::oriWaypoints
void oriWaypoints(const std::vector< std::pair< double, Eigen::Matrix3d >> &oriWp)
Sets the orientation waypoints.
mc_tasks::SplineTrajectoryTask::dimWeightInterpolation
const std::vector< std::pair< double, Eigen::Vector6d > > & dimWeightInterpolation() const noexcept
Sets the dimensional weights (controls the importance of orientation/translation).
Definition: SplineTrajectoryTask.h:205
mc_rtc::gui::StateBuilder
Definition: StateBuilder.h:27
mc_tasks::TrajectoryTaskGeneric::TrajectoryTaskGeneric
TrajectoryTaskGeneric(const mc_rbdyn::Robots &robots, unsigned int robotIndex, double stiffness, double weight)
Constructor (auto damping)
mc_rbdyn::ConstRobotFramePtr
std::shared_ptr< const RobotFrame > ConstRobotFramePtr
Definition: fwd.h:25
mc_tasks::SplineTrajectoryTask::target
const sva::PTransformd target() const
Gets the target pose (position/orientation)
mc_trajectory::SequenceInterpolator::values
void values(const TimedValueVector &values)
Set interpolator values.
Definition: SequenceInterpolator.h:82
mc_tasks::SplineTrajectoryTask::currentTime
double currentTime() const noexcept
Definition: SplineTrajectoryTask.h:316
mc_tasks::SplineTrajectoryTask::dampingInterpolator_
SequenceInterpolator6d dampingInterpolator_
Definition: SplineTrajectoryTask.h:365
mc_tasks::SplineTrajectoryTask::currTime_
double currTime_
Definition: SplineTrajectoryTask.h:369
mc_tasks::SplineTrajectoryTask::dimWeightInterpolator_
SequenceInterpolator6d dimWeightInterpolator_
Definition: SplineTrajectoryTask.h:363
mc_tasks::SplineTrajectoryTask::pause
void pause(bool paused)
Allows to pause the task.
Definition: SplineTrajectoryTask.h:310
mc_tasks::SplineTrajectoryTask::evalTracking
virtual Eigen::VectorXd evalTracking() const
Returns the trajectory tracking error: transformError between the current robot surface pose and its ...
mc_tasks::SplineTrajectoryTask::oriSpline_
mc_trajectory::InterpolatedRotation oriSpline_
Definition: SplineTrajectoryTask.h:361
mc_tasks::SplineTrajectoryTask::SplineTrajectoryTask
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.
mc_tasks
Definition: StabilizerStandingState.h:11
TrajectoryTaskGeneric.h
mc_tasks::SplineTrajectoryTask::dampingInterpolation
const std::vector< std::pair< double, Eigen::Vector6d > > & dampingInterpolation() const noexcept
Sets the dimensional weights (controls the importance of orientation/translation).
Definition: SplineTrajectoryTask.h:244
mc_tasks::TrajectoryTaskGeneric
Generic wrapper for a trajectory dynamic over an error function.
Definition: TrajectoryTaskGeneric.h:26
mc_tasks::SplineTrajectoryTask::eval
Eigen::VectorXd eval() const override
Returns the transformError between current robot surface pose and its final target.