CartesianFeedForwardPositionController.cpp
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 
26 
27 namespace armarx
28 {
30  : tcp(tcp)
31  {
32 
33  }
34 
35  Eigen::VectorXf CartesianFeedForwardPositionController::calculate(const ::math::AbstractFunctionR1R6Ptr& trajectory, float t, VirtualRobot::IKSolver::CartesianSelection mode)
36  {
37  int posLen = mode & VirtualRobot::IKSolver::Position ? 3 : 0;
38  int oriLen = mode & VirtualRobot::IKSolver::Orientation ? 3 : 0;
39  Eigen::VectorXf cartesianVel(posLen + oriLen);
40 
41  if (posLen)
42  {
43  Eigen::Vector3f targetPos = trajectory->GetPosition(t);
44  Eigen::Vector3f errPos = targetPos - tcp->getPositionInRootFrame();
45  Eigen::Vector3f posVel = errPos * KpPos;
47  {
48  posVel += trajectory->GetPositionDerivative(t);
49  }
50 
51  if (maxPosVel > 0)
52  {
53  posVel = math::MathUtils::LimitTo(posVel, maxPosVel);
54  }
55  cartesianVel.block<3, 1>(0, 0) = posVel;
56  }
57 
58  if (oriLen)
59  {
60  Eigen::Matrix3f targetOri = trajectory->GetOrientation(t).toRotationMatrix();
61  Eigen::Matrix3f tcpOri = tcp->getPoseInRootFrame().block<3, 3>(0, 0);
62  Eigen::Matrix3f oriDir = targetOri * tcpOri.inverse();
63  Eigen::AngleAxisf aa(oriDir);
64  Eigen::Vector3f errOri = aa.axis() * aa.angle();
65  Eigen::Vector3f oriVel = errOri * KpOri;
67  {
68  oriVel += trajectory->GetOrientationDerivative(t);
69  }
70 
71  if (maxOriVel > 0)
72  {
73  oriVel = math::MathUtils::LimitTo(oriVel, maxOriVel);
74  }
75  cartesianVel.block<3, 1>(posLen, 0) = oriVel;
76  }
77  return cartesianVel;
78  }
79 
80  float CartesianFeedForwardPositionController::getPositionError(const ::math::AbstractFunctionR1R6Ptr& trajectory, float t)
81  {
82  Eigen::Vector3f targetPos = trajectory->GetPosition(t);
83  Eigen::Vector3f errPos = targetPos - tcp->getPositionInRootFrame();
84  return errPos.norm();
85  }
86 
87  float CartesianFeedForwardPositionController::getOrientationError(const ::math::AbstractFunctionR1R6Ptr& trajectory, float t)
88  {
89  Eigen::Matrix3f targetOri = trajectory->GetOrientation(t).toRotationMatrix();
90  Eigen::Matrix3f tcpOri = tcp->getPoseInRootFrame().block<3, 3>(0, 0);
91  Eigen::Matrix3f oriDir = targetOri * tcpOri.inverse();
92  Eigen::AngleAxisf aa(oriDir);
93  return aa.angle();
94  }
95 
96  Eigen::Vector3f CartesianFeedForwardPositionController::getPositionDiff(const ::math::AbstractFunctionR1R6Ptr& trajectory, float t)
97  {
98  Eigen::Vector3f targetPos = trajectory->GetPosition(t);
99  return targetPos - tcp->getPositionInRootFrame();
100 
101  }
102 
103  Eigen::Vector3f CartesianFeedForwardPositionController::getOrientationDiff(const ::math::AbstractFunctionR1R6Ptr& trajectory, float t)
104  {
105  Eigen::Matrix3f targetOri = trajectory->GetOrientation(t).toRotationMatrix();
106  Eigen::Matrix3f tcpOri = tcp->getPoseInRootFrame().block<3, 3>(0, 0);
107  Eigen::Matrix3f oriDir = targetOri * tcpOri.inverse();
108  Eigen::AngleAxisf aa(oriDir);
109  return aa.axis() * aa.angle();
110  }
111 }
armarx::CartesianFeedForwardPositionController::getPositionDiff
Eigen::Vector3f getPositionDiff(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
Definition: CartesianFeedForwardPositionController.cpp:96
armarx::CartesianFeedForwardPositionController::calculate
Eigen::VectorXf calculate(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t, VirtualRobot::IKSolver::CartesianSelection mode)
Definition: CartesianFeedForwardPositionController.cpp:35
armarx::CartesianFeedForwardPositionController::getOrientationDiff
Eigen::Vector3f getOrientationDiff(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
Definition: CartesianFeedForwardPositionController.cpp:103
MathUtils.h
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
armarx::CartesianFeedForwardPositionController::enableFeedForward
bool enableFeedForward
Definition: CartesianFeedForwardPositionController.h:52
armarx::CartesianFeedForwardPositionController::CartesianFeedForwardPositionController
CartesianFeedForwardPositionController(const VirtualRobot::RobotNodePtr &tcp)
Definition: CartesianFeedForwardPositionController.cpp:29
armarx::CartesianFeedForwardPositionController::getOrientationError
float getOrientationError(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
Definition: CartesianFeedForwardPositionController.cpp:87
CartesianFeedForwardPositionController.h
armarx::CartesianFeedForwardPositionController::maxPosVel
float maxPosVel
Definition: CartesianFeedForwardPositionController.h:50
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
armarx::CartesianFeedForwardPositionController::maxOriVel
float maxOriVel
Definition: CartesianFeedForwardPositionController.h:51
armarx::CartesianFeedForwardPositionController::getPositionError
float getPositionError(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
Definition: CartesianFeedForwardPositionController.cpp:80
armarx::CartesianFeedForwardPositionController::KpPos
float KpPos
Definition: CartesianFeedForwardPositionController.h:48
armarx::math::MathUtils::LimitTo
static double LimitTo(double value, double absThreshold)
Definition: MathUtils.h:56
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
armarx::CartesianFeedForwardPositionController::KpOri
float KpOri
Definition: CartesianFeedForwardPositionController.h:49
armarx::navigation::core::Position
Eigen::Vector3f Position
Definition: basic_types.h:36
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28