CartesianVelocityControllerWithRamp.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 Sonja Marahrens (sonja dot marahrens)
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
31
32namespace armarx
33{
35 const VirtualRobot::RobotNodeSetPtr& rns,
36 const Eigen::VectorXf& currentJointVelocity,
37 VirtualRobot::IKSolver::CartesianSelection mode,
38 float maxPositionAcceleration,
39 float maxOrientationAcceleration,
40 float maxNullspaceAcceleration,
41 const VirtualRobot::RobotNodePtr& tcp) :
42 controller(rns, tcp), mode(mode)
43 {
45 maxPositionAcceleration, maxOrientationAcceleration, maxNullspaceAcceleration);
46#pragma GCC diagnostic push
47#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
48 setCurrentJointVelocity(currentJointVelocity);
49#pragma GCC diagnostic pop
50 }
51
52 void
54 const Eigen::Ref<const Eigen::VectorXf>& currentJointVelocity)
55 {
56 Eigen::MatrixXf jacobi = controller.ik->getJacobianMatrix(controller._tcp, mode);
57 //Eigen::MatrixXf inv = controller.ik->computePseudoInverseJacobianMatrix(jacobi, controller.ik->getJacobiRegularization(mode));
58
59
60 Eigen::FullPivLU<Eigen::MatrixXf> lu_decomp(jacobi);
61 Eigen::MatrixXf nullspace = lu_decomp.kernel();
62 Eigen::VectorXf nsv = Eigen::VectorXf::Zero(nullspace.rows());
63
64 for (int i = 0; i < nullspace.cols(); i++)
65 {
66 nsv += nullspace.col(i) * nullspace.col(i).dot(currentJointVelocity) /
67 nullspace.col(i).squaredNorm();
68 }
69 cartesianVelocityRamp.setState(jacobi * currentJointVelocity, mode);
70 nullSpaceVelocityRamp.setState(nsv);
71 }
72
73 void
74 CartesianVelocityControllerWithRamp::switchMode(const Eigen::VectorXf& currentJointVelocity,
75 VirtualRobot::IKSolver::CartesianSelection mode)
76 {
77 Eigen::MatrixXf jacobi = controller.ik->getJacobianMatrix(controller._tcp, mode);
78 cartesianVelocityRamp.setState(jacobi * currentJointVelocity, mode);
79 this->mode = mode;
80 }
81
82 VirtualRobot::IKSolver::CartesianSelection
87
88 Eigen::VectorXf
89 CartesianVelocityControllerWithRamp::calculate(const Eigen::VectorXf& cartesianVel,
90 float jointLimitAvoidanceScale,
91 float dt)
92 {
93 Eigen::VectorXf nullspaceVel =
94 controller.calculateNullspaceVelocity(cartesianVel, jointLimitAvoidanceScale, mode);
95 return calculate(cartesianVel, nullspaceVel, dt);
96 }
97
98 Eigen::VectorXf
99 CartesianVelocityControllerWithRamp::calculate(const Eigen::VectorXf& cartesianVel,
100 const Eigen::VectorXf& nullspaceVel,
101 float dt)
102 {
104 return controller.calculate(cartesianVelocityRamp.update(cartesianVel, dt),
105 nullSpaceVelocityRamp.update(nullspaceVel, dt),
106 mode);
107 }
108
109 void
111 float maxOrientationAcceleration,
112 float maxNullspaceAcceleration)
113 {
114 cartesianVelocityRamp.setMaxOrientationAcceleration(maxOrientationAcceleration);
115 cartesianVelocityRamp.setMaxPositionAcceleration(maxPositionAcceleration);
116 nullSpaceVelocityRamp.setMaxAccelaration(maxNullspaceAcceleration);
117 }
118
119 float
121 {
122 return cartesianVelocityRamp.getMaxOrientationAcceleration();
123 }
124
125 float
127 {
128 return cartesianVelocityRamp.getMaxPositionAcceleration();
129 }
130
131 float
133 {
134 return nullSpaceVelocityRamp.getMaxAccelaration();
135 }
136} // namespace armarx
constexpr T dt
Eigen::VectorXf calculate(const Eigen::VectorXf &cartesianVel, float jointLimitAvoidanceScale, float dt)
void setCurrentJointVelocity(const Eigen::Ref< const Eigen::VectorXf > &currentJointVelocity)
void setMaxAccelerations(float maxPositionAcceleration, float maxOrientationAcceleration, float maxNullspaceAcceleration)
VirtualRobot::IKSolver::CartesianSelection getMode()
CartesianVelocityControllerWithRamp(const VirtualRobot::RobotNodeSetPtr &rns, const Eigen::VectorXf &currentJointVelocity, VirtualRobot::IKSolver::CartesianSelection mode, float maxPositionAcceleration, float maxOrientationAcceleration, float maxNullspaceAcceleration, const VirtualRobot::RobotNodePtr &tcp=nullptr)
void switchMode(const Eigen::VectorXf &currentJointVelocity, VirtualRobot::IKSolver::CartesianSelection mode)
This file offers overloads of toIce() and fromIce() functions for STL container types.
#define ARMARX_TRACE
Definition trace.h:77