PositionTask.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 
16 {
17 public:
18  friend struct EndEffectorTask;
19 
28  PositionTask(const mc_rbdyn::RobotFrame & frame, double stiffness = 2.0, double weight = 500.0);
29 
43  PositionTask(const std::string & bodyName,
44  const mc_rbdyn::Robots & robots,
45  unsigned int robotIndex,
46  double stiffness = 2.0,
47  double weight = 500);
48 
49  virtual ~PositionTask() = default;
50 
55  void reset() override;
56 
58  inline const Eigen::Vector3d & position() const noexcept
59  {
60  switch(backend_)
61  {
62  case Backend::Tasks:
63  return static_cast<tasks::qp::PositionTask *>(errorT.get())->position();
64  case Backend::TVM:
65  return static_cast<mc_tvm::PositionFunction *>(errorT.get())->position();
66  default:
67  mc_rtc::log::error_and_throw("Not implemented");
68  }
69  }
70 
76  inline void position(const Eigen::Vector3d & pos) noexcept
77  {
78  switch(backend_)
79  {
80  case Backend::Tasks:
81  static_cast<tasks::qp::PositionTask *>(errorT.get())->position(pos);
82  break;
83  case Backend::TVM:
84  static_cast<mc_tvm::PositionFunction *>(errorT.get())->position(pos);
85  break;
86  default:
87  mc_rtc::log::error_and_throw("Not implemented");
88  }
89  }
90 
93  inline const Eigen::Vector3d & bodyPoint() const noexcept
94  {
95  switch(backend_)
96  {
97  case Backend::Tasks:
98  return static_cast<tasks::qp::PositionTask *>(errorT.get())->bodyPoint();
99  case Backend::TVM:
100  {
101  static Eigen::Vector3d res = Eigen::Vector3d::Zero();
102  return res;
103  }
104  default:
105  mc_rtc::log::error_and_throw("Not implemented");
106  }
107  }
108 
109  void addToGUI(mc_rtc::gui::StateBuilder & gui) override;
110 
111 protected:
113  void addToLogger(mc_rtc::Logger & logger) override;
114 };
115 
116 } // namespace mc_tasks
Definition: PositionFunction.h:19
#define MC_TASKS_DLLAPI
Definition: api.h:50
std::shared_ptr< const RobotFrame > ConstRobotFramePtr
Definition: fwd.h:25
void error_and_throw(Args &&... args)
Definition: logging.h:47
Definition: StabilizerStandingState.h:12
Definition: RobotFrame.h:22
Definition: Robots.h:16
Logs controller data to disk.
Definition: Logger.h:30
Definition: StateBuilder.h:28
Controls an end-effector.
Definition: EndEffectorTask.h:20
Control the position of a frame.
Definition: PositionTask.h:16
void position(const Eigen::Vector3d &pos) noexcept
Set the position target.
Definition: PositionTask.h:76
void addToLogger(mc_rtc::Logger &logger) override
const Eigen::Vector3d & bodyPoint() const noexcept
Get the body point being controlled.
Definition: PositionTask.h:93
void addToGUI(mc_rtc::gui::StateBuilder &gui) override
mc_rbdyn::ConstRobotFramePtr frame_
Definition: PositionTask.h:112
void reset() override
Reset the task.
virtual ~PositionTask()=default
PositionTask(const mc_rbdyn::RobotFrame &frame, double stiffness=2.0, double weight=500.0)
Constructor.
const Eigen::Vector3d & position() const noexcept
Get the position target.
Definition: PositionTask.h:58
PositionTask(const std::string &bodyName, const mc_rbdyn::Robots &robots, unsigned int robotIndex, double stiffness=2.0, double weight=500)
Constructor.
Generic wrapper for a trajectory dynamic over an error function.
Definition: TrajectoryTaskGeneric.h:27