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#pragma once
24
25#include <boost/shared_ptr.hpp>
26
27#include <Ice/Handle.h>
28
29#include <VirtualRobot/VirtualRobot.h>
30
31#include <dmp/representation/trajectory.h>
32
33namespace DMP
34{
36}
37
38namespace armarx
39{
41}
42
44{
45
47 {
48 float goDist = 80;
49 float backDist = 50;
50 float maxValue = 100;
51 float slop = 1000;
52 float Kpos = 1;
53 float Dpos = 2;
54 float Kori = 1;
55 float Dori = 0;
56 float mm2radi = 10;
57 };
58
60 {
61 int DMPKernelSize = 50;
62 std::string DMPMode = "Linear";
63 std::string DMPStyle = "Discrete";
64 float DMPAmplitude = 1;
65 float oriAmplitude = 1;
68 };
69
70 struct DebugInfo
71 {
72 double canVal;
73 double mpcFactor;
74 double poseError;
75 double posiError;
76 double oriError;
77 };
78
79 /**
80 * @defgroup Library-TaskSpaceDMPController TaskSpaceDMPController
81 * @ingroup Library-RobotUnit-NJointControllers
82 * A description of the library TaskSpaceDMPController.
83 *
84 * @class TaskSpaceDMPController
85 * @ingroup Library-TaskSpaceDMPController
86 * @brief Brief description of class TaskSpaceDMPController.
87 *
88 * Detailed description of class TaskSpaceDMPController.
89 */
91 {
92 public:
93 TaskSpaceDMPController(std::string name,
95 bool isPhaseStopControl = true);
96
97 std::string getName();
98
99
100 void flow(double deltaT, const Eigen::Matrix4f& currentPose, const Eigen::VectorXf& twist);
101 double flow(double canVal,
102 double deltaT,
103 const Eigen::Matrix4f& currentPose,
104 const Eigen::VectorXf& twist);
105
106 Eigen::VectorXf getTargetVelocity();
107 std::vector<double> getTargetPose();
108 Eigen::Matrix4f getTargetPoseMat();
109 Eigen::Matrix4f getIntegratedPoseMat();
110
111 void learnDMPFromFiles(const std::vector<std::string>& fileNames,
112 const std::vector<double>& ratios);
113 void learnDMPFromFiles(const std::vector<std::string>& fileNames);
114
115 void learnDMPFromSampledTrajectory(const DMP::Vec<DMP::SampledTrajectoryV2>& trajs);
116 void learnDMPFromTrajectory(const TrajectoryPtr& traj);
117
118 void loadDMPFromXML(const std::string& dmpXML);
119 void loadDMPFromString(const std::string& dmpStr);
120
121 void saveDMPToXML(const std::string& dmpXML);
122 std::string saveDMPToString();
123
124 void setViaPose(double canVal, const Eigen::Matrix4f& viaPose);
125 void setViaPose(double canVal, const std::vector<double>& viaPoseWithQuaternion);
126
127 void removeAllViaPoints();
128 void prepareExecution(const Eigen::Matrix4f& currentPose, const Eigen::Matrix4f& goalPose);
129 void prepareExecution(const std::vector<double>& currentPoseVec,
130 const std::vector<double>& goalPoseVec);
131
132 void setSpeed(double times);
133 void setAmplitude(double amp);
134
135 void setGoalPose(const Eigen::Matrix4f& goalPose);
136 void setGoalPoseVec(const std::vector<double> goalPoseVec);
137
138 void learnDMPFromSampledTrajectory(const DMP::Vec<DMP::SampledTrajectoryV2>& trajs,
139 const std::vector<double>& ratios);
140 void setRatios(const std::vector<double>& ratios);
141
143 std::vector<double> eigen4f2vec(const Eigen::Matrix4f& pose);
144
146
147 void pauseController();
148 void resumeController();
149
150 void setWeights(const std::vector<std::vector<double>>& weights);
151 void setTranslWeights(const std::vector<std::vector<double>>& weights);
152 void setRotWeights(const std::vector<std::vector<double>>& weights);
153
154 DMP::DVec2d getWeights();
155 DMP::DVec2d getTranslWeights();
156 DMP::DVec2d getRotWeights();
157
158 double canVal;
160 std::string dmpName;
163
164 private:
165 double tau;
166 DMP::DVec goalPoseVec;
167
168 Eigen::VectorXf targetVel;
169 DMP::DVec targetPoseVec;
170
171 DMP::Vec<DMP::DMPState> currentState;
172 bool paused;
173
174
175 bool isDisturbance;
176
177
178 void getError(const Eigen::Matrix4f& pose,
179 Eigen::Vector3f& position,
180 Eigen::Quaterniond& quaternion,
181 double& posiError,
182 double& oriError);
183
184 Eigen::Quaterniond oldDMPAngularVelocity;
185 };
186
187 using TaskSpaceDMPControllerPtr = std::shared_ptr<TaskSpaceDMPController>;
188
189} // namespace armarx::control::deprecated_njoint_mp_controller::tsvmp
void learnDMPFromSampledTrajectory(const DMP::Vec< DMP::SampledTrajectoryV2 > &trajs)
void prepareExecution(const Eigen::Matrix4f &currentPose, const Eigen::Matrix4f &goalPose)
TaskSpaceDMPController(std::string name, const TaskSpaceDMPControllerConfig &config, bool isPhaseStopControl=true)
void setTranslWeights(const std::vector< std::vector< double > > &weights)
void learnDMPFromFiles(const std::vector< std::string > &fileNames, const std::vector< double > &ratios)
void setRotWeights(const std::vector< std::vector< double > > &weights)
void setWeights(const std::vector< std::vector< double > > &weights)
void flow(double deltaT, const Eigen::Matrix4f &currentPose, const Eigen::VectorXf &twist)
boost::shared_ptr< class UMITSMP > UMITSMPPtr
Quaternion< double, 0 > Quaterniond
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52