GraspTrajectory.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#pragma once
25
26#include <map>
27#include <memory>
28#include <optional>
29
30#include <Eigen/Core>
31
32#include <VirtualRobot/VirtualRobot.h>
33
34#include <RobotAPI/interface/units/GraspCandidateProviderInterface.h>
36
37namespace armarx
38{
39 class RapidXmlReader;
40 using RapidXmlReaderPtr = std::shared_ptr<RapidXmlReader>;
41
42 class GraspTrajectory;
43 typedef std::shared_ptr<GraspTrajectory> GraspTrajectoryPtr;
44
46 {
47 public:
48 using GraspTrajectoryKeypointPtr = std::shared_ptr<GraspTrajectoryKeypoint>;
49
50 Eigen::Matrix4f tcpTarget;
51 armarx::NameValueMap handJointsTarget;
52 std::optional<std::string> shape;
53 float dt;
54 Eigen::Vector3f feedForwardPosVelocity;
55 Eigen::Vector3f feedForwardOriVelocity;
57
59
60 GraspTrajectoryKeypoint(const Eigen::Matrix4f& tcpTarget,
61 const armarx::NameValueMap& handJointsTarget,
62 const std::optional<std::string>& shape = std::nullopt);
63
64 GraspTrajectoryKeypoint(const Eigen::Matrix4f& tcpTarget,
65 const armarx::NameValueMap& handJointsTarget,
66 float dt,
67 const Eigen::Vector3f& feedForwardPosVelocity,
68 const Eigen::Vector3f& feedForwardOriVelocity,
69 const Eigen::VectorXf& feedForwardHandJointsVelocity,
70 const std::optional<std::string>& shape = std::nullopt);
71
72 Eigen::Vector3f getTargetPosition() const;
73 Eigen::Matrix3f getTargetOrientation() const;
74 Eigen::Matrix4f getTargetPose() const;
75 void updateVelocities(const GraspTrajectoryKeypointPtr& prev, float deltat);
76 };
77
78 class GraspTrajectory
79 {
80 public:
82 using KeypointPtr = std::shared_ptr<Keypoint>;
83
84 struct Length
85 {
86 float pos = 0;
87 float ori = 0;
88 };
89
90
91 public:
92 GraspTrajectory() = default;
93 GraspTrajectory(const std::vector<Keypoint>& keypoints);
94
95 GraspTrajectory(const Eigen::Matrix4f& tcpStart,
96 const armarx::NameValueMap& handJointsStart,
97 const std::optional<std::string>& shape = std::nullopt);
98
99 void addKeypoint(const Eigen::Matrix4f& tcpTarget,
100 const armarx::NameValueMap& handJointsTarget,
101 float dt,
102 const std::optional<std::string>& shape = std::nullopt);
103
104 size_t getKeypointCount() const;
105 const std::vector<KeypointPtr>& getAllKeypoints() const;
106
107 void insertKeypoint(size_t index,
108 const Eigen::Matrix4f& tcpTarget,
109 const armarx::NameValueMap& handJointsTarget,
110 float dt,
111 const std::optional<std::string>& shape = std::nullopt);
112
113 void removeKeypoint(size_t index);
114
115 void replaceKeypoint(size_t index,
116 const Eigen::Matrix4f& tcpTarget,
117 const armarx::NameValueMap& handJointsTarget,
118 float dt,
119 const std::optional<std::string>& shape = std::nullopt);
120
121 void setKeypointDt(size_t index, float dt);
122
123 const KeypointPtr& lastKeypoint() const;
124 const KeypointPtr& getKeypoint(int i) const;
125 Eigen::Matrix4f getStartPose() const;
126
127 void getIndex(float t, int& i1, int& i2, float& f) const;
128
129 Eigen::Vector3f GetPosition(float t) const;
130
131 Eigen::Matrix3f GetOrientation(float t) const;
132
133 Eigen::Matrix4f GetPose(float t) const;
134
135 std::vector<Eigen::Matrix4f> getAllKeypointPoses() const;
136 std::vector<Eigen::Vector3f> getAllKeypointPositions() const;
137 std::vector<Eigen::Matrix3f> getAllKeypointOrientations() const;
138
139 armarx::NameValueMap GetHandValues(float t) const;
140 std::optional<std::string> GetShape(float t) const;
141
142 Eigen::Vector3f GetPositionDerivative(float t) const;
143
144 Eigen::Vector3f GetOrientationDerivative(float t) const;
145
147
148 Eigen::Vector3f GetHandJointsDerivative(float t) const;
149
150 float getDuration() const;
151
153
154
155 GraspTrajectoryPtr getTranslatedAndRotated(const Eigen::Vector3f& translation,
156 const Eigen::Matrix3f& rotation) const;
157 GraspTrajectoryPtr getTransformed(const Eigen::Matrix4f& transform) const;
159
161
163 const Eigen::Matrix4f& target,
164 const Eigen::Vector3f& handForward = Eigen::Vector3f::UnitZ()) const;
165
167 calculateReachability(VirtualRobot::RobotNodeSetPtr rns,
168 VirtualRobot::RobotNodePtr tcp = VirtualRobot::RobotNodePtr(),
170
171
172 void writeToFile(const std::string& filename);
173
175 static GraspTrajectoryPtr ReadFromFile(const std::string& filename);
176 static GraspTrajectoryPtr ReadFromJSON(const std::string& filename);
177 static GraspTrajectoryPtr ReadFromString(const std::string& xml);
178
179 void setFrame(const std::string& frame);
180 const std::optional<std::string>& getFrame() const;
181
182 private:
183 void updateKeypointMap();
184
185 private:
186 std::vector<KeypointPtr> keypoints;
187 std::map<float, size_t> keypointMap;
188
189 std::optional<std::string> frame_;
190 };
191} // namespace armarx
uint8_t index
constexpr T dt
Eigen::Matrix3f getTargetOrientation() const
void updateVelocities(const GraspTrajectoryKeypointPtr &prev, float deltat)
std::shared_ptr< GraspTrajectoryKeypoint > GraspTrajectoryKeypointPtr
armarx::NameValueMap handJointsTarget
Eigen::VectorXf feedForwardHandJointsVelocity
Eigen::Vector3f getTargetPosition() const
Eigen::Matrix4f getTargetPose() const
std::optional< std::string > shape
Eigen::VectorXf GetHandValues(float t)
void removeKeypoint(size_t index)
float getDuration() const
static GraspTrajectoryPtr ReadFromString(const std::string &xml)
std::optional< std::string > GetShape(float t) const
Eigen::Vector3f GetOrientationDerivative(float t)
Eigen::Matrix4f getStartPose()
Eigen::Matrix4f GetPose(float t)
const std::vector< KeypointPtr > & getAllKeypoints() const
SimpleDiffIK::Reachability calculateReachability(VirtualRobot::RobotNodeSetPtr rns, VirtualRobot::RobotNodePtr tcp=VirtualRobot::RobotNodePtr(), SimpleDiffIK::Parameters params=SimpleDiffIK::Parameters())
Eigen::Vector3f GetPositionDerivative(float t)
void addKeypoint(const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget, float dt)
static GraspTrajectoryPtr ReadFromFile(const std::string &filename)
void setFrame(const std::string &frame)
GraspTrajectoryPtr getClone()
static GraspTrajectoryPtr ReadFromJSON(const std::string &filename)
GraspTrajectoryPtr getTranslatedAndRotated(const Eigen::Vector3f &translation, const Eigen::Matrix3f &rotation)
GraspTrajectoryPtr getTransformedToOtherHand() const
size_t getKeypointCount() const
const std::optional< std::string > & getFrame() const
std::vector< Eigen::Vector3f > getAllKeypointPositions()
Eigen::Vector3f GetPosition(float t)
Length calculateLength() const
void setKeypointDt(size_t index, float dt)
std::vector< Eigen::Matrix3f > getAllKeypointOrientations()
std::shared_ptr< Keypoint > KeypointPtr
void replaceKeypoint(size_t index, const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget, float dt)
Eigen::VectorXf GetHandJointsDerivative(float t)
GraspTrajectoryPtr getTransformed(const Eigen::Matrix4f &transform)
KeypointPtr & getKeypoint(int i)
void getIndex(float t, int &i1, int &i2, float &f)
static GraspTrajectoryPtr ReadFromReader(const RapidXmlReaderPtr &reader)
std::vector< Eigen::Matrix4f > getAllKeypointPoses()
Eigen::Matrix3f GetOrientation(float t)
void insertKeypoint(size_t index, const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget, float dt)
GraspTrajectoryPtr getTransformedToGraspPose(const Eigen::Matrix4f &target, const Eigen::Vector3f &handForward=Eigen::Vector3f::UnitZ())
Eigen::Vector6f GetTcpDerivative(float t)
void writeToFile(const std::string &filename)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition algorithm.h:351
std::shared_ptr< class GraspTrajectory > GraspTrajectoryPtr