CartesianVelocityRamp.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/Robot.h>
28
30
31namespace armarx
32{
36
37 void
38 CartesianVelocityRamp::setState(const Eigen::VectorXf& state,
39 VirtualRobot::IKSolver::CartesianSelection mode)
40 {
41 this->state = state;
42 this->mode = mode;
43 }
44
45 Eigen::VectorXf
46 CartesianVelocityRamp::update(const Eigen::VectorXf& target, float dt)
47 {
48 if (dt <= 0)
49 {
50 return state;
51 }
52 Eigen::VectorXf delta = target - state;
53 int i = 0;
54 float factor = 1;
55
56 if (mode & VirtualRobot::IKSolver::Position)
57 {
58 Eigen::Vector3f posDelta = delta.block<3, 1>(i, 0);
59 float posFactor = posDelta.norm() / maxPositionAcceleration / dt;
60 factor = std::max(factor, posFactor);
61 i += 3;
62 }
63
64 if (mode & VirtualRobot::IKSolver::Orientation)
65 {
66 Eigen::Vector3f oriDelta = delta.block<3, 1>(i, 0);
67 float oriFactor = oriDelta.norm() / maxOrientationAcceleration / dt;
68 factor = std::max(factor, oriFactor);
69 }
70
71 state += delta / factor;
72 // ARMARX_IMPORTANT << "CartRamp state " << state;
73 return state;
74 }
75
76 void
78 {
79 this->maxPositionAcceleration = maxPositionAcceleration;
80 }
81
82 void
84 {
85 this->maxOrientationAcceleration = maxOrientationAcceleration;
86 }
87
88 float
90 {
91 return maxPositionAcceleration;
92 }
93
94 float
96 {
97 return maxOrientationAcceleration;
98 }
99} // namespace armarx
constexpr T dt
Eigen::VectorXf update(const Eigen::VectorXf &target, float dt)
void setMaxOrientationAcceleration(float maxOrientationAcceleration)
void setMaxPositionAcceleration(float maxPositionAcceleration)
void setState(const Eigen::VectorXf &state, VirtualRobot::IKSolver::CartesianSelection mode)
This file offers overloads of toIce() and fromIce() functions for STL container types.