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 
27 
28 namespace armarx
29 {
30  CartesianVelocityControllerWithRamp::CartesianVelocityControllerWithRamp(const VirtualRobot::RobotNodeSetPtr& rns, const Eigen::VectorXf& currentJointVelocity, VirtualRobot::IKSolver::CartesianSelection mode,
31  float maxPositionAcceleration, float maxOrientationAcceleration, float maxNullspaceAcceleration, const VirtualRobot::RobotNodePtr& tcp)
32  : controller(rns, tcp), mode(mode)
33  {
34  setMaxAccelerations(maxPositionAcceleration, maxOrientationAcceleration, maxNullspaceAcceleration);
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
37  setCurrentJointVelocity(currentJointVelocity);
38 #pragma GCC diagnostic pop
39  }
40 
41  void CartesianVelocityControllerWithRamp::setCurrentJointVelocity(const Eigen::Ref<const Eigen::VectorXf>& currentJointVelocity)
42  {
43  Eigen::MatrixXf jacobi = controller.ik->getJacobianMatrix(controller._tcp, mode);
44  //Eigen::MatrixXf inv = controller.ik->computePseudoInverseJacobianMatrix(jacobi, controller.ik->getJacobiRegularization(mode));
45 
46 
47  Eigen::FullPivLU<Eigen::MatrixXf> lu_decomp(jacobi);
48  Eigen::MatrixXf nullspace = lu_decomp.kernel();
49  Eigen::VectorXf nsv = Eigen::VectorXf::Zero(nullspace.rows());
50 
51  for (int i = 0; i < nullspace.cols(); i++)
52  {
53  nsv += nullspace.col(i) * nullspace.col(i).dot(currentJointVelocity) / nullspace.col(i).squaredNorm();
54  }
55  cartesianVelocityRamp.setState(jacobi * currentJointVelocity, mode);
56  nullSpaceVelocityRamp.setState(nsv);
57 
58  }
59 
61  {
62  Eigen::MatrixXf jacobi = controller.ik->getJacobianMatrix(controller._tcp, mode);
63  cartesianVelocityRamp.setState(jacobi * currentJointVelocity, mode);
64  this->mode = mode;
65  }
66 
68  {
69  return mode;
70  }
71 
72  Eigen::VectorXf CartesianVelocityControllerWithRamp::calculate(const Eigen::VectorXf& cartesianVel, float jointLimitAvoidanceScale, float dt)
73  {
74  Eigen::VectorXf nullspaceVel = controller.calculateNullspaceVelocity(cartesianVel, jointLimitAvoidanceScale, mode);
75  return calculate(cartesianVel, nullspaceVel, dt);
76  }
77 
78  Eigen::VectorXf CartesianVelocityControllerWithRamp::calculate(const Eigen::VectorXf& cartesianVel, const Eigen::VectorXf& nullspaceVel, float dt)
79  {
81  return controller.calculate(cartesianVelocityRamp.update(cartesianVel, dt), nullSpaceVelocityRamp.update(nullspaceVel, dt), mode);
82  }
83 
84  void CartesianVelocityControllerWithRamp::setMaxAccelerations(float maxPositionAcceleration, float maxOrientationAcceleration, float maxNullspaceAcceleration)
85  {
86  cartesianVelocityRamp.setMaxOrientationAcceleration(maxOrientationAcceleration);
87  cartesianVelocityRamp.setMaxPositionAcceleration(maxPositionAcceleration);
88  nullSpaceVelocityRamp.setMaxAccelaration(maxNullspaceAcceleration);
89  }
90 
92  {
93  return cartesianVelocityRamp.getMaxOrientationAcceleration();
94  }
95 
97  {
98  return cartesianVelocityRamp.getMaxPositionAcceleration();
99  }
100 
102  {
103  return nullSpaceVelocityRamp.getMaxAccelaration();
104  }
105 }
armarx::CartesianVelocityRamp::setState
void setState(const Eigen::VectorXf &state, VirtualRobot::IKSolver::CartesianSelection mode)
Definition: CartesianVelocityRamp.cpp:33
armarx::CartesianVelocityRamp::setMaxPositionAcceleration
void setMaxPositionAcceleration(float maxPositionAcceleration)
Definition: CartesianVelocityRamp.cpp:69
armarx::JointVelocityRamp::setMaxAccelaration
void setMaxAccelaration(float maxAcceleration)
Definition: JointVelocityRamp.cpp:55
armarx::CartesianVelocityControllerWithRamp::getMaxPositionAcceleration
float getMaxPositionAcceleration()
Definition: CartesianVelocityControllerWithRamp.cpp:96
armarx::JointVelocityRamp::update
Eigen::VectorXf update(const Eigen::VectorXf &target, float dt)
Definition: JointVelocityRamp.cpp:37
armarx::CartesianVelocityRamp::setMaxOrientationAcceleration
void setMaxOrientationAcceleration(float maxOrientationAcceleration)
Definition: CartesianVelocityRamp.cpp:75
armarx::CartesianVelocityRamp::update
Eigen::VectorXf update(const Eigen::VectorXf &target, float dt)
Definition: CartesianVelocityRamp.cpp:39
CartesianVelocityControllerWithRamp.h
armarx::CartesianVelocityControllerWithRamp::setMaxAccelerations
void setMaxAccelerations(float maxPositionAcceleration, float maxOrientationAcceleration, float maxNullspaceAcceleration)
Definition: CartesianVelocityControllerWithRamp.cpp:84
armarx::JointVelocityRamp::setState
void setState(const Eigen::VectorXf &state)
Definition: JointVelocityRamp.cpp:32
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::CartesianVelocityControllerWithRamp::getMaxNullspaceAcceleration
float getMaxNullspaceAcceleration()
Definition: CartesianVelocityControllerWithRamp.cpp:101
armarx::CartesianVelocityControllerWithRamp::getMode
VirtualRobot::IKSolver::CartesianSelection getMode()
Definition: CartesianVelocityControllerWithRamp.cpp:67
controller
Definition: AddOperation.h:39
armarx::CartesianVelocityControllerWithRamp::calculate
Eigen::VectorXf calculate(const Eigen::VectorXf &cartesianVel, float jointLimitAvoidanceScale, float dt)
Definition: CartesianVelocityControllerWithRamp.cpp:72
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
armarx::CartesianVelocityControllerWithRamp::setCurrentJointVelocity
void setCurrentJointVelocity(const Eigen::Ref< const Eigen::VectorXf > &currentJointVelocity)
Definition: CartesianVelocityControllerWithRamp.cpp:41
armarx::CartesianVelocityRamp::getMaxPositionAcceleration
float getMaxPositionAcceleration()
Definition: CartesianVelocityRamp.cpp:81
armarx::CartesianVelocityControllerWithRamp::switchMode
void switchMode(const Eigen::VectorXf &currentJointVelocity, VirtualRobot::IKSolver::CartesianSelection mode)
Definition: CartesianVelocityControllerWithRamp.cpp:60
armarx::CartesianVelocityRamp::getMaxOrientationAcceleration
float getMaxOrientationAcceleration()
Definition: CartesianVelocityRamp.cpp:86
armarx::CartesianVelocityControllerWithRamp::getMaxOrientationAcceleration
float getMaxOrientationAcceleration()
Definition: CartesianVelocityControllerWithRamp.cpp:91
armarx::JointVelocityRamp::getMaxAccelaration
float getMaxAccelaration()
Definition: JointVelocityRamp.cpp:61
Logging.h
armarx::CartesianVelocityControllerWithRamp::CartesianVelocityControllerWithRamp
CartesianVelocityControllerWithRamp(const VirtualRobot::RobotNodeSetPtr &rns, const Eigen::VectorXf &currentJointVelocity, VirtualRobot::IKSolver::CartesianSelection mode, float maxPositionAcceleration, float maxOrientationAcceleration, float maxNullspaceAcceleration, const VirtualRobot::RobotNodePtr &tcp=nullptr)
Definition: CartesianVelocityControllerWithRamp.cpp:30
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:42