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 
27 
30 #include <RobotAPI/interface/units/GraspCandidateProviderInterface.h>
31 
34 
39 #include <ArmarXCore/interface/serialization/Eigen.h>
40 
41 #include <VirtualRobot/math/AbstractFunctionR1R6.h>
42 #include <VirtualRobot/math/Helpers.h>
43 
44 #include <Eigen/Core>
45 
46 #include <vector>
47 #include <map>
48 
49 namespace armarx
50 {
51  typedef std::shared_ptr<class GraspTrajectory> GraspTrajectoryPtr;
52 
54  {
55  public:
56  class Keypoint;
57  typedef std::shared_ptr<Keypoint> KeypointPtr;
58 
59  class Keypoint
60  {
61  public:
63  Eigen::VectorXf handJointsTarget;
64  float dt;
65  Eigen::Vector3f feedForwardPosVelocity;
66  Eigen::Vector3f feedForwardOriVelocity;
68 
69  Keypoint(const Eigen::Matrix4f& tcpTarget, const Eigen::VectorXf& handJointsTarget);
70  Keypoint(const Eigen::Matrix4f& tcpTarget, const Eigen::VectorXf& handJointsTarget, float dt,
71  const Eigen::Vector3f& feedForwardPosVelocity, const Eigen::Vector3f& feedForwardOriVelocity,
72  const Eigen::VectorXf& feedForwardHandJointsVelocity);
73  Eigen::Vector3f getTargetPosition() const;
76  void updateVelocities(const KeypointPtr& prev, float dt);
77  };
78 
79  struct Length
80  {
81  float pos = 0;
82  float ori = 0;
83  };
84 
85 
86  public:
87  GraspTrajectory(const Eigen::Matrix4f& tcpStart, const Eigen::VectorXf& handJointsStart);
88 
89  void addKeypoint(const Eigen::Matrix4f& tcpTarget, const Eigen::VectorXf& handJointsTarget, float dt);
90 
91  size_t getKeypointCount() const;
92 
93  void insertKeypoint(size_t index, const Eigen::Matrix4f& tcpTarget, const Eigen::VectorXf& handJointsTarget, float dt);
94 
95  void removeKeypoint(size_t index);
96 
97  void replaceKeypoint(size_t index, const Eigen::Matrix4f& tcpTarget, const Eigen::VectorXf& handJointsTarget, float dt);
98 
99  void setKeypointDt(size_t index, float dt);
100 
102  KeypointPtr& getKeypoint(int i);
104 
105  void getIndex(float t, int& i1, int& i2, float& f);
106 
107  Eigen::Vector3f GetPosition(float t);
108 
110 
111  Eigen::Matrix4f GetPose(float t);
112 
113  std::vector<Eigen::Matrix4f> getAllKeypointPoses();
114  std::vector<Eigen::Vector3f> getAllKeypointPositions();
115  std::vector<Eigen::Matrix3f> getAllKeypointOrientations();
116 
117  Eigen::VectorXf GetHandValues(float t);
118 
119  Eigen::Vector3f GetPositionDerivative(float t);
120 
121  Eigen::Vector3f GetOrientationDerivative(float t);
122 
124 
125  Eigen::VectorXf GetHandJointsDerivative(float t);
126 
127  float getDuration() const;
128 
129  Length calculateLength() const;
130  int GetHandJointCount() const;
131 
132 
133  GraspTrajectoryPtr getTranslatedAndRotated(const Eigen::Vector3f& translation, const Eigen::Matrix3f& rotation);
135 
137 
138  GraspTrajectoryPtr getTransformedToGraspPose(const Eigen::Matrix4f& target, const Eigen::Vector3f& handForward = Eigen::Vector3f::UnitZ());
139 
140  SimpleDiffIK::Reachability calculateReachability(VirtualRobot::RobotNodeSetPtr rns, VirtualRobot::RobotNodePtr tcp = VirtualRobot::RobotNodePtr(), SimpleDiffIK::Parameters params = SimpleDiffIK::Parameters());
141 
142  void writeToFile(const std::string& filename);
143 
144  static GraspTrajectoryPtr ReadFromFile(const grasping::GraspCandidatePtr& cnd);
145 
147  static GraspTrajectoryPtr ReadFromFile(const std::string& filename);
148  static GraspTrajectoryPtr ReadFromString(const std::string& xml);
149 
150  private:
151 
152  void updateKeypointMap();
153 
154  private:
155  std::vector<KeypointPtr> keypoints;
156  std::map<float, size_t> keypointMap;
157  };
158 }
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::GraspTrajectory::Keypoint::tcpTarget
Eigen::Matrix4f tcpTarget
Definition: GraspTrajectory.h:62
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::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::GraspTrajectory::getTranslatedAndRotated
GraspTrajectoryPtr getTranslatedAndRotated(const Eigen::Vector3f &translation, const Eigen::Matrix3f &rotation)
Definition: GraspTrajectory.cpp:332
armarx::GraspTrajectory::getStartPose
Eigen::Matrix4f getStartPose()
Definition: GraspTrajectory.cpp:174
armarx::SimpleDiffIK::Reachability
Definition: SimpleDiffIK.h:81
SimpleJsonLogger.h
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
StructuralJsonParser.h
RapidXmlWriter.h
armarx::GraspTrajectory::Keypoint::handJointsTarget
Eigen::VectorXf handJointsTarget
Definition: GraspTrajectory.h:63
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::GraspTrajectory::Keypoint::getTargetOrientation
Eigen::Matrix3f getTargetOrientation() const
Definition: GraspTrajectory.cpp:50
armarx::GraspTrajectory::ReadFromReader
static GraspTrajectoryPtr ReadFromReader(const RapidXmlReaderPtr &reader)
Definition: GraspTrajectory.cpp:401
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::GetPositionDerivative
Eigen::Vector3f GetPositionDerivative(float t)
Definition: GraspTrajectory.cpp:270
armarx::GraspTrajectory::removeKeypoint
void removeKeypoint(size_t index)
Definition: GraspTrajectory.cpp:122
JPathNavigator.h
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::Keypoint::getTargetPosition
Eigen::Vector3f getTargetPosition() const
Definition: GraspTrajectory.cpp:45
armarx::GraspTrajectory::getTransformed
GraspTrajectoryPtr getTransformed(const Eigen::Matrix4f &transform)
Definition: GraspTrajectory.cpp:343
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::GraspTrajectory::Keypoint::dt
float dt
Definition: GraspTrajectory.h:64
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
CMakePackageFinder.h
armarx::GraspTrajectory::Keypoint
Definition: GraspTrajectory.h:59
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::GraspTrajectory::GetHandJointCount
int GetHandJointCount() const
Definition: GraspTrajectory.cpp:327
armarx::GraspTrajectory::lastKeypoint
KeypointPtr & lastKeypoint()
Definition: GraspTrajectory.cpp:164
armarx::GraspTrajectory::getKeypoint
KeypointPtr & getKeypoint(int i)
Definition: GraspTrajectory.cpp:169
armarx::GraspTrajectory::Keypoint::Keypoint
Keypoint(const Eigen::Matrix4f &tcpTarget, const Eigen::VectorXf &handJointsTarget)
Definition: GraspTrajectory.cpp:31
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
RapidXmlReader.h
armarx::GraspTrajectory::GetOrientation
Eigen::Matrix3f GetOrientation(float t)
Definition: GraspTrajectory.cpp:211
armarx::GraspTrajectory::Keypoint::feedForwardHandJointsVelocity
Eigen::VectorXf feedForwardHandJointsVelocity
Definition: GraspTrajectory.h:67
armarx::GraspTrajectory::Keypoint::feedForwardOriVelocity
Eigen::Vector3f feedForwardOriVelocity
Definition: GraspTrajectory.h:66
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::GraspTrajectory::Keypoint::getTargetPose
Eigen::Matrix4f getTargetPose() const
Definition: GraspTrajectory.cpp:55
armarx::GraspTrajectory::GetPose
Eigen::Matrix4f GetPose(float t)
Definition: GraspTrajectory.cpp:226
armarx::GraspTrajectory::getClone
GraspTrajectoryPtr getClone()
Definition: GraspTrajectory.cpp:354
armarx::GraspTrajectory::Keypoint::feedForwardPosVelocity
Eigen::Vector3f feedForwardPosVelocity
Definition: GraspTrajectory.h:65
armarx::GraspTrajectory::getDuration
float getDuration() const
Definition: GraspTrajectory.cpp:302
armarx::GraspTrajectory::Keypoint::updateVelocities
void updateVelocities(const KeypointPtr &prev, float dt)
Definition: GraspTrajectory.cpp:60
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
Exception.h
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