TaskSpaceVMP.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::DMPController
17  * @author zhou ( you dot zhou at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #ifndef _ARMARX_LIB_RobotAPI_TaskSpaceDMPController_H
24 #define _ARMARX_LIB_RobotAPI_TaskSpaceDMPController_H
25 
26 
27 #include <dmp/representation/dmp/umitsmp.h>
28 
29 
30 #include <VirtualRobot/RobotNodeSet.h>
31 #include <VirtualRobot/MathTools.h>
35 
37 {
38 
40  {
41  float goDist = 80;
42  float backDist = 50;
43  float maxValue = 100;
44  float slop = 1000;
45  float Kpos = 1;
46  float Dpos = 2;
47  float Kori = 1;
48  float Dori = 0;
49  float mm2radi = 10;
50  };
51 
53  {
54  int DMPKernelSize = 50;
55  std::string DMPMode = "Linear";
56  std::string DMPStyle = "Discrete";
57  float DMPAmplitude = 1;
58  float oriAmplitude = 1;
59  float motionTimeDuration = 10;
61  };
62 
63  struct DebugInfo
64  {
65  double canVal;
66  double mpcFactor;
67  double poseError;
68  double posiError;
69  double oriError;
70  };
71 
72  /**
73  * @defgroup Library-TaskSpaceDMPController TaskSpaceDMPController
74  * @ingroup Library-RobotUnit-NJointControllers
75  * A description of the library TaskSpaceDMPController.
76  *
77  * @class TaskSpaceDMPController
78  * @ingroup Library-TaskSpaceDMPController
79  * @brief Brief description of class TaskSpaceDMPController.
80  *
81  * Detailed description of class TaskSpaceDMPController.
82  */
84  {
85  public:
87  {
88  this->config = config;
89 
90  int ModeInd;
91  if (config.DMPMode == "MinimumJerk")
92  {
93  ModeInd = 2;
94  }
95  else
96  {
97  ModeInd = 1;
98  }
99 
100 
101  dmpPtr.reset(new DMP::UMITSMP(config.DMPKernelSize, ModeInd));
103 
104  targetPoseVec.resize(7);
105  targetVel.resize(6);
106  targetVel.setZero();
107  currentState.resize(7);
108 
110  dmpName = name;
111  this->paused = false;
112  tau = 1;
113  }
114 
115  std::string getName()
116  {
117  return dmpName;
118  }
119 
120 
121  void flow(double deltaT, const Eigen::Matrix4f& currentPose, const Eigen::VectorXf& twist);
122  double flow(double canVal, double deltaT, const Eigen::Matrix4f& currentPose, const Eigen::VectorXf& twist);
123 
124  Eigen::VectorXf getTargetVelocity()
125  {
126  return targetVel;
127  }
128 
129  std::vector<double> getTargetPose()
130  {
131  return targetPoseVec;
132  }
133 
135  {
136  Eigen::Matrix4f res = VirtualRobot::MathTools::quat2eigen4f(targetPoseVec.at(4), targetPoseVec.at(5), targetPoseVec.at(6), targetPoseVec.at(3));
137  res(0, 3) = targetPoseVec.at(0);
138  res(1, 3) = targetPoseVec.at(1);
139  res(2, 3) = targetPoseVec.at(2);
140 
141  return res;
142  }
143 
145  {
146  Eigen::Matrix4f res = VirtualRobot::MathTools::quat2eigen4f(currentState.at(4).pos,
147  currentState.at(5).pos,
148  currentState.at(6).pos,
149  currentState.at(3).pos);
150  res(0, 3) = currentState.at(0).pos;
151  res(1, 3) = currentState.at(1).pos;
152  res(2, 3) = currentState.at(2).pos;
153 
154  return res;
155  }
156 
157  void learnDMPFromFiles(const std::vector<std::string>& fileNames, const std::vector<double>& ratios);
158  void learnDMPFromFiles(const std::vector<std::string>& fileNames);
159 
160  void learnDMPFromSampledTrajectory(const DMP::Vec<DMP::SampledTrajectoryV2 >& trajs);
161  void learnDMPFromTrajectory(const TrajectoryPtr& traj);
162 
163  void loadDMPFromXML(const std::string& dmpXML);
164  void loadDMPFromString(const std::string& dmpStr);
165 
166  void saveDMPToXML(const std::string& dmpXML);
167  std::string saveDMPToString();
168 
169  void setViaPose(double canVal, const Eigen::Matrix4f& viaPose);
170  void setViaPose(double canVal, const std::vector<double>& viaPoseWithQuaternion);
171 
172  void removeAllViaPoints();
173  void prepareExecution(const Eigen::Matrix4f& currentPose, const Eigen::Matrix4f& goalPose);
174  void prepareExecution(const std::vector<double>& currentPoseVec, const std::vector<double>& goalPoseVec);
175 
176  void setSpeed(double times);
177  void setAmplitude(double amp);
178 
179  void setGoalPose(const Eigen::Matrix4f& goalPose)
180  {
181  setViaPose(dmpPtr->getUMin(), goalPose);
182  }
183 
184  void setGoalPoseVec(const std::vector<double> goalPoseVec)
185  {
186  setViaPose(dmpPtr->getUMin(), goalPoseVec);
187  }
188 
189  void learnDMPFromSampledTrajectory(const DMP::Vec<DMP::SampledTrajectoryV2>& trajs, const std::vector<double>& ratios);
190  void setRatios(const std::vector<double>& ratios);
191 
193  std::vector<double> eigen4f2vec(const Eigen::Matrix4f& pose);
194 
195  DMP::UMITSMPPtr getDMP()
196  {
197  return dmpPtr;
198  }
199 
201  {
202  this->paused = true;
203  }
205  {
206  this->paused = false;
207  }
208 
209  void setWeights(const std::vector<std::vector<double> >& weights)
210  {
211  dmpPtr->setWeights(weights);
212  }
213 
214  void setTranslWeights(const std::vector<std::vector<double> >& weights)
215  {
216  ARMARX_CHECK_EQUAL(weights.size(), 3);
217 
218  for (size_t i = 0; i < 3; ++i)
219  {
220  dmpPtr->setWeights(i, weights[i]);
221  }
222  }
223 
224  void setRotWeights(const std::vector<std::vector<double> >& weights)
225  {
226  ARMARX_CHECK_EQUAL(weights.size(), 4);
227 
228  for (size_t i = 0; i < 4; ++i)
229  {
230  dmpPtr->setWeights(3 + i, weights[i]);
231  }
232  }
233 
234  DMP::DVec2d getWeights()
235  {
236  return dmpPtr->getWeights();
237  }
238 
239  DMP::DVec2d getTranslWeights()
240  {
241  DMP::DVec2d res;
242  DMP::DVec2d weights = getWeights();
243  for (size_t i = 0; i < 3; ++i)
244  {
245  res.push_back(weights[i]);
246  }
247  return res;
248  }
249 
250  DMP::DVec2d getRotWeights()
251  {
252  DMP::DVec2d res;
253  DMP::DVec2d weights = getWeights();
254  for (size_t i = 3; i < 7; ++i)
255  {
256  res.push_back(weights[i]);
257  }
258  return res;
259  }
260 
261  double canVal;
263  std::string dmpName;
264  DMP::UMITSMPPtr dmpPtr;
266  private:
267 
268  double tau;
269  DMP::DVec goalPoseVec;
270 
271  Eigen::VectorXf targetVel;
272  DMP::DVec targetPoseVec;
273 
274  DMP::Vec<DMP::DMPState > currentState;
275  bool paused;
276 
277 
278  bool isDisturbance;
279 
280 
281  void getError(const Eigen::Matrix4f& pose, Eigen::Vector3f& position, Eigen::Quaterniond& quaternion, double& posiError, double& oriError);
282 
283  Eigen::Quaterniond oldDMPAngularVelocity;
284  };
285 
286  using TaskSpaceDMPControllerPtr = std::shared_ptr<TaskSpaceDMPController>;
287 
288 }
289 
290 #endif
armarx::control::deprecated_njoint_mp_controller::tsvmp::DebugInfo::canVal
double canVal
Definition: TaskSpaceVMP.h:65
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Kori
float Kori
Definition: TaskSpaceVMP.h:47
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setGoalPose
void setGoalPose(const Eigen::Matrix4f &goalPose)
Definition: TaskSpaceVMP.h:179
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::debugData
DebugInfo debugData
Definition: TaskSpaceVMP.h:192
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Dpos
float Dpos
Definition: TaskSpaceVMP.h:46
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPKernelSize
int DMPKernelSize
Definition: TaskSpaceVMP.h:54
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::oriAmplitude
float oriAmplitude
Definition: TaskSpaceVMP.h:58
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::resumeController
void resumeController()
Definition: TaskSpaceVMP.h:204
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getRotWeights
DMP::DVec2d getRotWeights()
Definition: TaskSpaceVMP.h:250
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setGoalPoseVec
void setGoalPoseVec(const std::vector< double > goalPoseVec)
Definition: TaskSpaceVMP.h:184
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setViaPose
void setViaPose(double canVal, const Eigen::Matrix4f &viaPose)
Definition: TaskSpaceVMP.cpp:377
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig
Definition: TaskSpaceVMP.h:52
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::phaseStopParas
PhaseStopParams phaseStopParas
Definition: TaskSpaceVMP.h:60
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::goDist
float goDist
Definition: TaskSpaceVMP.h:41
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getTargetVelocity
Eigen::VectorXf getTargetVelocity()
Definition: TaskSpaceVMP.h:124
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setRotWeights
void setRotWeights(const std::vector< std::vector< double > > &weights)
Definition: TaskSpaceVMP.h:224
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::motionTimeDuration
float motionTimeDuration
Definition: TaskSpaceVMP.h:59
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::removeAllViaPoints
void removeAllViaPoints()
Definition: TaskSpaceVMP.cpp:395
IceInternal::Handle< Trajectory >
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::backDist
float backDist
Definition: TaskSpaceVMP.h:42
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setAmplitude
void setAmplitude(double amp)
Definition: TaskSpaceVMP.cpp:444
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::maxValue
float maxValue
Definition: TaskSpaceVMP.h:43
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getTranslWeights
DMP::DVec2d getTranslWeights()
Definition: TaskSpaceVMP.h:239
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::config
TaskSpaceDMPControllerConfig config
Definition: TaskSpaceVMP.h:265
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Dori
float Dori
Definition: TaskSpaceVMP.h:48
armarx::control::deprecated_njoint_mp_controller::tsvmp::DebugInfo::poseError
double poseError
Definition: TaskSpaceVMP.h:67
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::isPhaseStopControl
bool isPhaseStopControl
Definition: TaskSpaceVMP.h:262
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setTranslWeights
void setTranslWeights(const std::vector< std::vector< double > > &weights)
Definition: TaskSpaceVMP.h:214
armarx::control::common::mp::DVec
Ice::DoubleSeq DVec
Definition: MP.h:46
armarx::control::deprecated_njoint_mp_controller::tsvmp::DebugInfo
Definition: TaskSpaceVMP.h:63
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::saveDMPToString
std::string saveDMPToString()
Definition: TaskSpaceVMP.cpp:343
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::learnDMPFromSampledTrajectory
void learnDMPFromSampledTrajectory(const DMP::Vec< DMP::SampledTrajectoryV2 > &trajs)
armarx::control::deprecated_njoint_mp_controller::tsvmp::DebugInfo::posiError
double posiError
Definition: TaskSpaceVMP.h:68
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getName
std::string getName()
Definition: TaskSpaceVMP.h:115
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPAmplitude
float DMPAmplitude
Definition: TaskSpaceVMP.h:57
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams
Definition: TaskSpaceVMP.h:39
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::prepareExecution
void prepareExecution(const Eigen::Matrix4f &currentPose, const Eigen::Matrix4f &goalPose)
Definition: TaskSpaceVMP.cpp:401
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::slop
float slop
Definition: TaskSpaceVMP.h:44
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Kpos
float Kpos
Definition: TaskSpaceVMP.h:45
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::loadDMPFromXML
void loadDMPFromXML(const std::string &dmpXML)
Definition: TaskSpaceVMP.cpp:352
armarx::control::deprecated_njoint_mp_controller::tsvmp::DebugInfo::oriError
double oriError
Definition: TaskSpaceVMP.h:69
ExpressionException.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getDMP
DMP::UMITSMPPtr getDMP()
Definition: TaskSpaceVMP.h:195
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getIntegratedPoseMat
Eigen::Matrix4f getIntegratedPoseMat()
Definition: TaskSpaceVMP.h:144
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::saveDMPToXML
void saveDMPToXML(const std::string &dmpXML)
Definition: TaskSpaceVMP.cpp:365
Trajectory.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::TaskSpaceDMPController
TaskSpaceDMPController(std::string name, const TaskSpaceDMPControllerConfig &config, bool isPhaseStopControl=true)
Definition: TaskSpaceVMP.h:86
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getWeights
DMP::DVec2d getWeights()
Definition: TaskSpaceVMP.h:234
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPStyle
std::string DMPStyle
Definition: TaskSpaceVMP.h:56
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getTargetPoseMat
Eigen::Matrix4f getTargetPoseMat()
Definition: TaskSpaceVMP.h:134
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPMode
std::string DMPMode
Definition: TaskSpaceVMP.h:55
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::learnDMPFromFiles
void learnDMPFromFiles(const std::vector< std::string > &fileNames, const std::vector< double > &ratios)
Definition: TaskSpaceVMP.cpp:231
Eigen::Quaterniond
Quaternion< double, 0 > Quaterniond
Definition: EigenForwardDeclarations.h:62
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::mm2radi
float mm2radi
Definition: TaskSpaceVMP.h:49
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::flow
void flow(double deltaT, const Eigen::Matrix4f &currentPose, const Eigen::VectorXf &twist)
Definition: TaskSpaceVMP.cpp:37
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setSpeed
void setSpeed(double times)
Definition: TaskSpaceVMP.cpp:433
Logging.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::DebugInfo::mpcFactor
double mpcFactor
Definition: TaskSpaceVMP.h:66
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::loadDMPFromString
void loadDMPFromString(const std::string &dmpStr)
Definition: TaskSpaceVMP.cpp:331
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::pauseController
void pauseController()
Definition: TaskSpaceVMP.h:200
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::dmpName
std::string dmpName
Definition: TaskSpaceVMP.h:263
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::canVal
double canVal
Definition: TaskSpaceVMP.h:261
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setWeights
void setWeights(const std::vector< std::vector< double > > &weights)
Definition: TaskSpaceVMP.h:209
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::getTargetPose
std::vector< double > getTargetPose()
Definition: TaskSpaceVMP.h:129
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController
Brief description of class TaskSpaceDMPController.
Definition: TaskSpaceVMP.h:83
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::eigen4f2vec
std::vector< double > eigen4f2vec(const Eigen::Matrix4f &pose)
Definition: TaskSpaceVMP.cpp:454
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::learnDMPFromTrajectory
void learnDMPFromTrajectory(const TrajectoryPtr &traj)
Definition: TaskSpaceVMP.cpp:308
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::setRatios
void setRatios(const std::vector< double > &ratios)
Definition: TaskSpaceVMP.cpp:302
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController::dmpPtr
DMP::UMITSMPPtr dmpPtr
Definition: TaskSpaceVMP.h:264