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
25
26#include <VirtualRobot/IK/DifferentialIK.h>
27#include <VirtualRobot/Nodes/RobotNode.h>
28#include <VirtualRobot/Robot.h>
29#include <VirtualRobot/RobotNodeSet.h>
30#include <VirtualRobot/math/AbstractFunctionR1R6.h>
31
33
34namespace armarx
35{
37 const VirtualRobot::RobotNodePtr& tcp) :
38 tcp(tcp)
39 {
40 }
41
42 Eigen::VectorXf
44 const ::math::AbstractFunctionR1R6Ptr& trajectory,
45 float t,
46 VirtualRobot::IKSolver::CartesianSelection mode)
47 {
48 int posLen = mode & VirtualRobot::IKSolver::Position ? 3 : 0;
49 int oriLen = mode & VirtualRobot::IKSolver::Orientation ? 3 : 0;
50 Eigen::VectorXf cartesianVel(posLen + oriLen);
51
52 if (posLen)
53 {
54 Eigen::Vector3f targetPos = trajectory->GetPosition(t);
55 Eigen::Vector3f errPos = targetPos - tcp->getPositionInRootFrame();
56 Eigen::Vector3f posVel = errPos * KpPos;
58 {
59 posVel += trajectory->GetPositionDerivative(t);
60 }
61
62 if (maxPosVel > 0)
63 {
64 posVel = math::MathUtils::LimitTo(posVel, maxPosVel);
65 }
66 cartesianVel.block<3, 1>(0, 0) = posVel;
67 }
68
69 if (oriLen)
70 {
71 Eigen::Matrix3f targetOri = trajectory->GetOrientation(t).toRotationMatrix();
72 Eigen::Matrix3f tcpOri = tcp->getPoseInRootFrame().block<3, 3>(0, 0);
73 Eigen::Matrix3f oriDir = targetOri * tcpOri.inverse();
74 Eigen::AngleAxisf aa(oriDir);
75 Eigen::Vector3f errOri = aa.axis() * aa.angle();
76 Eigen::Vector3f oriVel = errOri * KpOri;
78 {
79 oriVel += trajectory->GetOrientationDerivative(t);
80 }
81
82 if (maxOriVel > 0)
83 {
84 oriVel = math::MathUtils::LimitTo(oriVel, maxOriVel);
85 }
86 cartesianVel.block<3, 1>(posLen, 0) = oriVel;
87 }
88 return cartesianVel;
89 }
90
91 float
93 const ::math::AbstractFunctionR1R6Ptr& trajectory,
94 float t)
95 {
96 Eigen::Vector3f targetPos = trajectory->GetPosition(t);
97 Eigen::Vector3f errPos = targetPos - tcp->getPositionInRootFrame();
98 return errPos.norm();
99 }
100
101 float
103 const ::math::AbstractFunctionR1R6Ptr& trajectory,
104 float t)
105 {
106 Eigen::Matrix3f targetOri = trajectory->GetOrientation(t).toRotationMatrix();
107 Eigen::Matrix3f tcpOri = tcp->getPoseInRootFrame().block<3, 3>(0, 0);
108 Eigen::Matrix3f oriDir = targetOri * tcpOri.inverse();
109 Eigen::AngleAxisf aa(oriDir);
110 return aa.angle();
111 }
112
113 Eigen::Vector3f
115 const ::math::AbstractFunctionR1R6Ptr& trajectory,
116 float t)
117 {
118 Eigen::Vector3f targetPos = trajectory->GetPosition(t);
119 return targetPos - tcp->getPositionInRootFrame();
120 }
121
122 Eigen::Vector3f
124 const ::math::AbstractFunctionR1R6Ptr& trajectory,
125 float t)
126 {
127 Eigen::Matrix3f targetOri = trajectory->GetOrientation(t).toRotationMatrix();
128 Eigen::Matrix3f tcpOri = tcp->getPoseInRootFrame().block<3, 3>(0, 0);
129 Eigen::Matrix3f oriDir = targetOri * tcpOri.inverse();
130 Eigen::AngleAxisf aa(oriDir);
131 return aa.axis() * aa.angle();
132 }
133} // namespace armarx
Eigen::Vector3f getOrientationDiff(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
float getOrientationError(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
float getPositionError(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
Eigen::Vector3f getPositionDiff(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t)
CartesianFeedForwardPositionController(const VirtualRobot::RobotNodePtr &tcp)
Eigen::VectorXf calculate(const ::math::AbstractFunctionR1R6Ptr &trajectory, float t, VirtualRobot::IKSolver::CartesianSelection mode)
static double LimitTo(double value, double absThreshold)
Definition MathUtils.h:71
This file offers overloads of toIce() and fromIce() functions for STL container types.