CartesianPositionController.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 <VirtualRobot/RobotNodeSet.h>
27 #include <VirtualRobot/IK/DifferentialIK.h>
28 #include <VirtualRobot/Robot.h>
29 #include <Eigen/Dense>
30 
31 #include <RobotAPI/interface/core/CartesianPositionControllerConfig.h>
34 
35 namespace armarx
36 {
37  class CartesianPositionController;
38  using CartesianPositionControllerPtr = std::shared_ptr<CartesianPositionController>;
39 
40  // This is a P-controller. In: Target pose, out Cartesian velocity.
42  {
43  public:
44  CartesianPositionController(const VirtualRobot::RobotNodePtr& tcp,
45  const VirtualRobot::RobotNodePtr& referenceFrame = nullptr);
46 
49 
50  Eigen::VectorXf calculate(const Eigen::Matrix4f& targetPose, VirtualRobot::IKSolver::CartesianSelection mode) const;
51  Eigen::VectorXf calculatePos(const Eigen::Vector3f& targetPos) const;
52 
53  float getPositionError(const Eigen::Matrix4f& targetPose) const;
54  float getOrientationError(const Eigen::Matrix4f& targetPose) const;
55  static float GetPositionError(const Eigen::Matrix4f& targetPose,
56  const VirtualRobot::RobotNodePtr& tcp,
57  const VirtualRobot::RobotNodePtr& referenceFrame = nullptr);
58  static float GetOrientationError(const Eigen::Matrix4f& targetPose,
59  const VirtualRobot::RobotNodePtr& tcp,
60  const VirtualRobot::RobotNodePtr& referenceFrame = nullptr);
61  static bool Reached(const Eigen::Matrix4f& targetPose,
62  const VirtualRobot::RobotNodePtr& tcp,
63  bool checkOri,
64  float thresholdPosReached,
65  float thresholdOriReached,
66  const VirtualRobot::RobotNodePtr& referenceFrame = nullptr);
67  bool reached(const Eigen::Matrix4f& targetPose, VirtualRobot::IKSolver::CartesianSelection mode, float thresholdPosReached, float thresholdOriReached);
68 
69  Eigen::Vector3f getPositionDiff(const Eigen::Matrix4f& targetPose) const;
70  Eigen::Vector3f getPositionDiffVec3(const Eigen::Vector3f& targetPosition) const;
71  Eigen::Vector3f getOrientationDiff(const Eigen::Matrix4f& targetPose) const;
72  VirtualRobot::RobotNodePtr getTcp() const;
73 
74  float KpPos = 1;
75  float KpOri = 1;
76  float maxPosVel = -1;
77  float maxOriVel = -1;
78 
79 
80  private:
81  VirtualRobot::RobotNodePtr tcp;
82  VirtualRobot::RobotNodePtr referenceFrame;
83  };
84 }
85 namespace armarx::VariantType
86 {
87  // variant types
88  const VariantTypeId CartesianPositionControllerConfig = Variant::addTypeName("::armarx::CartesianPositionControllerConfig");
89 }
90 
91 namespace armarx
92 {
93  class CartesianPositionControllerConfig : virtual public CartesianPositionControllerConfigBase
94  {
95  public:
97 
98  // inherited from VariantDataClass
99  Ice::ObjectPtr ice_clone() const override
100  {
101  return this->clone();
102  }
103  VariantDataClassPtr clone(const Ice::Current& = ::Ice::Current()) const override
104  {
105  return new CartesianPositionControllerConfig(*this);
106  }
107  std::string output(const Ice::Current& c = ::Ice::Current()) const override;
108  VariantTypeId getType(const Ice::Current& = ::Ice::Current()) const override
109  {
111  }
112  bool validate(const Ice::Current& = ::Ice::Current()) override
113  {
114  return true;
115  }
116 
117  friend std::ostream& operator<<(std::ostream& stream, const CartesianPositionControllerConfig& rhs)
118  {
119  stream << "CartesianPositionControllerConfig: " << std::endl << rhs.output() << std::endl;
120  return stream;
121  }
122 
123  public: // serialization
124  void serialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = ::Ice::Current()) const override;
125  void deserialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = ::Ice::Current()) override;
126 
127  };
128 
130 }
131 
armarx::CartesianPositionController::CartesianPositionController
CartesianPositionController(const VirtualRobot::RobotNodePtr &tcp, const VirtualRobot::RobotNodePtr &referenceFrame=nullptr)
Definition: CartesianPositionController.cpp:31
armarx::CartesianPositionControllerConfig::validate
bool validate(const Ice::Current &=::Ice::Current()) override
Definition: CartesianPositionController.h:112
armarx::VariantType::CartesianPositionControllerConfig
const VariantTypeId CartesianPositionControllerConfig
Definition: CartesianPositionController.h:88
armarx::CartesianPositionController::maxPosVel
float maxPosVel
Definition: CartesianPositionController.h:76
armarx::CartesianPositionController::calculatePos
Eigen::VectorXf calculatePos(const Eigen::Vector3f &targetPos) const
Definition: CartesianPositionController.cpp:77
AbstractObjectSerializer.h
armarx::CartesianPositionControllerPtr
std::shared_ptr< CartesianPositionController > CartesianPositionControllerPtr
Definition: CartesianPositionController.h:38
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::CartesianPositionController::GetOrientationError
static float GetOrientationError(const Eigen::Matrix4f &targetPose, const VirtualRobot::RobotNodePtr &tcp, const VirtualRobot::RobotNodePtr &referenceFrame=nullptr)
Definition: CartesianPositionController.cpp:114
armarx::CartesianPositionController::getPositionDiff
Eigen::Vector3f getPositionDiff(const Eigen::Matrix4f &targetPose) const
Definition: CartesianPositionController.cpp:158
armarx::CartesianPositionControllerConfig::operator<<
friend std::ostream & operator<<(std::ostream &stream, const CartesianPositionControllerConfig &rhs)
Definition: CartesianPositionController.h:117
armarx::CartesianPositionController::reached
bool reached(const Eigen::Matrix4f &targetPose, VirtualRobot::IKSolver::CartesianSelection mode, float thresholdPosReached, float thresholdOriReached)
Definition: CartesianPositionController.cpp:138
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::CartesianPositionController::getPositionError
float getPositionError(const Eigen::Matrix4f &targetPose) const
Definition: CartesianPositionController.cpp:93
armarx::CartesianPositionControllerConfig
Definition: CartesianPositionController.h:93
armarx::CartesianPositionController::getPositionDiffVec3
Eigen::Vector3f getPositionDiffVec3(const Eigen::Vector3f &targetPosition) const
Definition: CartesianPositionController.cpp:165
armarx::CartesianPositionControllerConfig::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=::Ice::Current()) const override
Definition: CartesianPositionController.cpp:211
armarx::CartesianPositionController::KpOri
float KpOri
Definition: CartesianPositionController.h:75
armarx::CartesianPositionController::GetPositionError
static float GetPositionError(const Eigen::Matrix4f &targetPose, const VirtualRobot::RobotNodePtr &tcp, const VirtualRobot::RobotNodePtr &referenceFrame=nullptr)
Definition: CartesianPositionController.cpp:103
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
armarx::VariantType
Definition: ChannelRef.h:160
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::CartesianPositionControllerConfig::CartesianPositionControllerConfig
CartesianPositionControllerConfig()
Definition: CartesianPositionController.cpp:191
armarx::CartesianPositionController::getTcp
VirtualRobot::RobotNodePtr getTcp() const
Definition: CartesianPositionController.cpp:180
armarx::CartesianPositionController::operator=
CartesianPositionController & operator=(CartesianPositionController &&)=default
armarx::CartesianPositionControllerConfig::output
std::string output(const Ice::Current &c=::Ice::Current()) const override
Definition: CartesianPositionController.cpp:195
armarx::CartesianPositionControllerConfig::clone
VariantDataClassPtr clone(const Ice::Current &=::Ice::Current()) const override
Definition: CartesianPositionController.h:103
armarx::CartesianPositionController::getOrientationDiff
Eigen::Vector3f getOrientationDiff(const Eigen::Matrix4f &targetPose) const
Definition: CartesianPositionController.cpp:170
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::CartesianPositionControllerConfigPtr
IceInternal::Handle< CartesianPositionControllerConfig > CartesianPositionControllerConfigPtr
Definition: CartesianPositionController.h:129
armarx::CartesianPositionController
Definition: CartesianPositionController.h:41
armarx::CartesianPositionController::maxOriVel
float maxOriVel
Definition: CartesianPositionController.h:77
armarx::CartesianPositionController::Reached
static bool Reached(const Eigen::Matrix4f &targetPose, const VirtualRobot::RobotNodePtr &tcp, bool checkOri, float thresholdPosReached, float thresholdOriReached, const VirtualRobot::RobotNodePtr &referenceFrame=nullptr)
Definition: CartesianPositionController.cpp:127
armarx::CartesianPositionControllerConfig::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=::Ice::Current()) override
Definition: CartesianPositionController.cpp:226
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::CartesianPositionController::KpPos
float KpPos
Definition: CartesianPositionController.h:74
armarx::CartesianPositionControllerConfig::getType
VariantTypeId getType(const Ice::Current &=::Ice::Current()) const override
Definition: CartesianPositionController.h:108
armarx::CartesianPositionControllerConfig::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: CartesianPositionController.h:99
Variant.h
armarx::CartesianPositionController::getOrientationError
float getOrientationError(const Eigen::Matrix4f &targetPose) const
Definition: CartesianPositionController.cpp:98
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::Variant::addTypeName
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.
Definition: Variant.cpp:751
armarx::CartesianPositionController::calculate
Eigen::VectorXf calculate(const Eigen::Matrix4f &targetPose, VirtualRobot::IKSolver::CartesianSelection mode) const
Definition: CartesianPositionController.cpp:37