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 
29 #include <Eigen/Core>
30 
31 #include <VirtualRobot/VirtualRobot.h>
32 
33 #include <RobotAPI/interface/units/GraspCandidateProviderInterface.h>
35 
36 namespace armarx
37 {
38  class RapidXmlReader;
39  using RapidXmlReaderPtr = std::shared_ptr<RapidXmlReader>;
40 
41  class GraspTrajectory;
42  typedef std::shared_ptr<GraspTrajectory> GraspTrajectoryPtr;
43 
45  {
46  public:
47  using GraspTrajectoryKeypointPtr = std::shared_ptr<GraspTrajectoryKeypoint>;
48 
51  std::optional<std::string> shape;
52  float dt;
53  Eigen::Vector3f feedForwardPosVelocity;
54  Eigen::Vector3f feedForwardOriVelocity;
56 
57  GraspTrajectoryKeypoint() = default;
58 
61  const std::optional<std::string>& shape = std::nullopt);
62 
65  float dt,
66  const Eigen::Vector3f& feedForwardPosVelocity,
67  const Eigen::Vector3f& feedForwardOriVelocity,
68  const Eigen::VectorXf& feedForwardHandJointsVelocity,
69  const std::optional<std::string>& shape = std::nullopt);
70 
71  Eigen::Vector3f getTargetPosition() const;
74  void updateVelocities(const GraspTrajectoryKeypointPtr& prev, float deltat);
75  };
76 
77  class GraspTrajectory
78  {
79  public:
81  using KeypointPtr = std::shared_ptr<Keypoint>;
82 
83  struct Length
84  {
85  float pos = 0;
86  float ori = 0;
87  };
88 
89 
90  public:
91  GraspTrajectory() = default;
92  GraspTrajectory(const std::vector<Keypoint>& keypoints);
93 
94  GraspTrajectory(const Eigen::Matrix4f& tcpStart,
95  const armarx::NameValueMap& handJointsStart,
96  const std::optional<std::string>& shape = std::nullopt);
97 
98  void addKeypoint(const Eigen::Matrix4f& tcpTarget,
99  const armarx::NameValueMap& handJointsTarget,
100  float dt,
101  const std::optional<std::string>& shape = std::nullopt);
102 
103  size_t getKeypointCount() const;
104  const std::vector<KeypointPtr>& getAllKeypoints() const;
105 
106  void insertKeypoint(size_t index,
107  const Eigen::Matrix4f& tcpTarget,
108  const armarx::NameValueMap& handJointsTarget,
109  float dt,
110  const std::optional<std::string>& shape = std::nullopt);
111 
112  void removeKeypoint(size_t index);
113 
114  void replaceKeypoint(size_t index,
115  const Eigen::Matrix4f& tcpTarget,
116  const armarx::NameValueMap& handJointsTarget,
117  float dt,
118  const std::optional<std::string>& shape = std::nullopt);
119 
120  void setKeypointDt(size_t index, float dt);
121 
122  const KeypointPtr& lastKeypoint() const;
123  const KeypointPtr& getKeypoint(int i) const;
125 
126  void getIndex(float t, int& i1, int& i2, float& f) const;
127 
128  Eigen::Vector3f GetPosition(float t) const;
129 
130  Eigen::Matrix3f GetOrientation(float t) const;
131 
132  Eigen::Matrix4f GetPose(float t) const;
133 
134  std::vector<Eigen::Matrix4f> getAllKeypointPoses() const;
135  std::vector<Eigen::Vector3f> getAllKeypointPositions() const;
136  std::vector<Eigen::Matrix3f> getAllKeypointOrientations() const;
137 
138  armarx::NameValueMap GetHandValues(float t) const;
139  std::optional<std::string> GetShape(float t) const;
140 
141  Eigen::Vector3f GetPositionDerivative(float t) const;
142 
143  Eigen::Vector3f GetOrientationDerivative(float t) const;
144 
146 
147  Eigen::Vector3f GetHandJointsDerivative(float t) const;
148 
149  float getDuration() const;
150 
151  Length calculateLength() const;
152 
153 
154  GraspTrajectoryPtr getTranslatedAndRotated(const Eigen::Vector3f& translation,
155  const Eigen::Matrix3f& rotation) const;
158 
160 
162  const Eigen::Matrix4f& target,
163  const Eigen::Vector3f& handForward = Eigen::Vector3f::UnitZ()) const;
164 
166  calculateReachability(VirtualRobot::RobotNodeSetPtr rns,
167  VirtualRobot::RobotNodePtr tcp = VirtualRobot::RobotNodePtr(),
169 
170 
171  void writeToFile(const std::string& filename);
172 
174  static GraspTrajectoryPtr ReadFromFile(const std::string& filename);
175  static GraspTrajectoryPtr ReadFromJSON(const std::string& filename);
176  static GraspTrajectoryPtr ReadFromString(const std::string& xml);
177 
178  void setFrame(const std::string& frame);
179  const std::optional<std::string>& getFrame() const;
180 
181  private:
182  void updateKeypointMap();
183 
184  private:
185  std::vector<KeypointPtr> keypoints;
186  std::map<float, size_t> keypointMap;
187 
188  std::optional<std::string> frame_;
189  };
190 } // namespace armarx
armarx::RapidXmlReaderPtr
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
Definition: RapidXmlReader.h:66
armarx::GraspTrajectory::GetPosition
Eigen::Vector3f GetPosition(float t)
Definition: GraspTrajectory.cpp:203
armarx::GraspTrajectory::getAllKeypointPositions
std::vector< Eigen::Vector3f > getAllKeypointPositions()
Definition: GraspTrajectory.cpp:241
armarx::GraspTrajectoryKeypoint::tcpTarget
Eigen::Matrix4f tcpTarget
Definition: GraspTrajectory.h:49
armarx::GraspTrajectory::getAllKeypointOrientations
std::vector< Eigen::Matrix3f > getAllKeypointOrientations()
Definition: GraspTrajectory.cpp:251
armarx::GraspTrajectory::calculateReachability
SimpleDiffIK::Reachability calculateReachability(VirtualRobot::RobotNodeSetPtr rns, VirtualRobot::RobotNodePtr tcp=VirtualRobot::RobotNodePtr(), SimpleDiffIK::Parameters params=SimpleDiffIK::Parameters())
Definition: GraspTrajectory.cpp:373
armarx::GraspTrajectory::getFrame
const std::optional< std::string > & getFrame() const
Definition: GraspTrajectory.cpp:777
armarx::GraspTrajectory::ReadFromJSON
static GraspTrajectoryPtr ReadFromJSON(const std::string &filename)
Definition: GraspTrajectory.cpp:199
armarx::SimpleDiffIK::Parameters
Definition: SimpleDiffIK.h:40
armarx::GraspTrajectory::ReadFromFile
static GraspTrajectoryPtr ReadFromFile(const grasping::GraspCandidatePtr &cnd)
Definition: GraspTrajectory.cpp:393
armarx::GraspTrajectory::insertKeypoint
void insertKeypoint(size_t index, const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget, float dt)
Definition: GraspTrajectory.cpp:103
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::GraspTrajectoryKeypoint::GraspTrajectoryKeypointPtr
std::shared_ptr< GraspTrajectoryKeypoint > GraspTrajectoryKeypointPtr
Definition: GraspTrajectory.h:47
armarx::GraspTrajectory::getTranslatedAndRotated
GraspTrajectoryPtr getTranslatedAndRotated(const Eigen::Vector3f &translation, const Eigen::Matrix3f &rotation)
Definition: GraspTrajectory.cpp:332
armarx::GraspTrajectoryKeypoint::feedForwardHandJointsVelocity
Eigen::VectorXf feedForwardHandJointsVelocity
Definition: GraspTrajectory.h:55
armarx::GraspTrajectory::getStartPose
Eigen::Matrix4f getStartPose()
Definition: GraspTrajectory.cpp:174
armarx::GraspTrajectoryKeypoint::getTargetPose
Eigen::Matrix4f getTargetPose() const
armarx::SimpleDiffIK::Reachability
Definition: SimpleDiffIK.h:81
armarx::GraspTrajectory::KeypointPtr
std::shared_ptr< Keypoint > KeypointPtr
Definition: GraspTrajectory.h:56
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::GraspTrajectoryKeypoint::updateVelocities
void updateVelocities(const GraspTrajectoryKeypointPtr &prev, float deltat)
armarx::GraspTrajectoryKeypoint::feedForwardPosVelocity
Eigen::Vector3f feedForwardPosVelocity
Definition: GraspTrajectory.h:53
armarx::GraspTrajectory::getTransformedToOtherHand
GraspTrajectoryPtr getTransformedToOtherHand() const
Definition: GraspTrajectory.cpp:654
armarx::GraspTrajectory::Length::pos
float pos
Definition: GraspTrajectory.h:81
armarx::GraspTrajectory
Definition: GraspTrajectory.h:53
armarx::GraspTrajectory::GetTcpDerivative
Eigen::Vector6f GetTcpDerivative(float t)
Definition: GraspTrajectory.cpp:286
armarx::GraspTrajectoryKeypoint::getTargetOrientation
Eigen::Matrix3f getTargetOrientation() const
armarx::GraspTrajectory::ReadFromReader
static GraspTrajectoryPtr ReadFromReader(const RapidXmlReaderPtr &reader)
Definition: GraspTrajectory.cpp:401
armarx::GraspTrajectory::GetShape
std::optional< std::string > GetShape(float t) const
Definition: GraspTrajectory.cpp:508
armarx::GraspTrajectoryKeypoint::feedForwardOriVelocity
Eigen::Vector3f feedForwardOriVelocity
Definition: GraspTrajectory.h:54
armarx::GraspTrajectory::getAllKeypointPoses
std::vector< Eigen::Matrix4f > getAllKeypointPoses()
Definition: GraspTrajectory.cpp:231
armarx::GraspTrajectoryPtr
std::shared_ptr< class GraspTrajectory > GraspTrajectoryPtr
Definition: GraspTrajectory.h:51
armarx::GraspTrajectory::GraspTrajectory
GraspTrajectory()=default
armarx::GraspTrajectory::setFrame
void setFrame(const std::string &frame)
Definition: GraspTrajectory.cpp:771
armarx::GraspTrajectory::GetPositionDerivative
Eigen::Vector3f GetPositionDerivative(float t)
Definition: GraspTrajectory.cpp:270
armarx::GraspTrajectory::removeKeypoint
void removeKeypoint(size_t index)
Definition: GraspTrajectory.cpp:122
armarx::GraspTrajectoryKeypoint::getTargetPosition
Eigen::Vector3f getTargetPosition() const
armarx::GraspTrajectory::GetHandValues
Eigen::VectorXf GetHandValues(float t)
Definition: GraspTrajectory.cpp:261
armarx::GraspTrajectory::calculateLength
Length calculateLength() const
Definition: GraspTrajectory.cpp:307
armarx::GraspTrajectory::setKeypointDt
void setKeypointDt(size_t index, float dt)
Definition: GraspTrajectory.cpp:152
armarx::GraspTrajectory::getTransformed
GraspTrajectoryPtr getTransformed(const Eigen::Matrix4f &transform)
Definition: GraspTrajectory.cpp:343
armarx::KeypointPtr
std::shared_ptr< Keypoint > KeypointPtr
Definition: KeypointManager.h:104
SimpleDiffIK.h
filename
std::string filename
Definition: VisualizationRobot.cpp:83
armarx::GraspTrajectory::getIndex
void getIndex(float t, int &i1, int &i2, float &f)
Definition: GraspTrajectory.cpp:179
armarx::GraspTrajectoryKeypoint::GraspTrajectoryKeypoint
GraspTrajectoryKeypoint()=default
armarx::GraspTrajectory::getAllKeypoints
const std::vector< KeypointPtr > & getAllKeypoints() const
Definition: GraspTrajectory.cpp:289
armarx::GraspTrajectoryKeypoint::dt
float dt
Definition: GraspTrajectory.h:52
armarx::GraspTrajectory::GetHandJointsDerivative
Eigen::VectorXf GetHandJointsDerivative(float t)
Definition: GraspTrajectory.cpp:294
armarx::GraspTrajectory::GetOrientationDerivative
Eigen::Vector3f GetOrientationDerivative(float t)
Definition: GraspTrajectory.cpp:278
armarx::GraspTrajectory::ReadFromString
static GraspTrajectoryPtr ReadFromString(const std::string &xml)
Definition: GraspTrajectory.cpp:447
armarx::GraspTrajectory::Length::ori
float ori
Definition: GraspTrajectory.h:82
armarx::GraspTrajectory::getTransformedToGraspPose
GraspTrajectoryPtr getTransformedToGraspPose(const Eigen::Matrix4f &target, const Eigen::Vector3f &handForward=Eigen::Vector3f::UnitZ())
Definition: GraspTrajectory.cpp:359
armarx::GraspTrajectory::Length
Definition: GraspTrajectory.h:79
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::GraspTrajectoryKeypoint
Definition: GraspTrajectory.h:44
armarx::GraspTrajectory::Keypoint
Definition: GraspTrajectory.h:59
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
armarx::GraspTrajectoryKeypoint::shape
std::optional< std::string > shape
Definition: GraspTrajectory.h:51
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::GraspTrajectory::lastKeypoint
KeypointPtr & lastKeypoint()
Definition: GraspTrajectory.cpp:164
armarx::GraspTrajectory::getKeypoint
KeypointPtr & getKeypoint(int i)
Definition: GraspTrajectory.cpp:169
armarx::transform
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:315
armarx::GraspTrajectory::GetOrientation
Eigen::Matrix3f GetOrientation(float t)
Definition: GraspTrajectory.cpp:211
Eigen::Matrix< float, 6, 1 >
armarx::GraspTrajectory::replaceKeypoint
void replaceKeypoint(size_t index, const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget, float dt)
Definition: GraspTrajectory.cpp:138
armarx::GraspTrajectory::writeToFile
void writeToFile(const std::string &filename)
Definition: GraspTrajectory.cpp:378
armarx::GraspTrajectoryKeypoint::handJointsTarget
armarx::NameValueMap handJointsTarget
Definition: GraspTrajectory.h:50
armarx::GraspTrajectory::GetPose
Eigen::Matrix4f GetPose(float t)
Definition: GraspTrajectory.cpp:226
armarx::GraspTrajectory::getClone
GraspTrajectoryPtr getClone()
Definition: GraspTrajectory.cpp:354
armarx::GraspTrajectory::getDuration
float getDuration() const
Definition: GraspTrajectory.cpp:302
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::GraspTrajectory::getKeypointCount
size_t getKeypointCount() const
Definition: GraspTrajectory.cpp:98
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:42
armarx::GraspTrajectory::addKeypoint
void addKeypoint(const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget, float dt)
Definition: GraspTrajectory.cpp:87