common.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
17  * @date 2022
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <VirtualRobot/Robot.h>
25 
27 {
28 
29  struct RobotStatus
30  {
31  // TODO, remove std vector version
32  std::vector<float> jointPosition;
33  std::vector<float> jointVelocity;
34  std::vector<float> jointTorque;
35  Eigen::VectorXf jointPos;
36  Eigen::VectorXf jointVel;
37  Eigen::VectorXf jointTor;
38  double deltaT = 0;
39  unsigned int numJoints;
40  };
41 
43  {
45  std::vector<float> jointValuesFullRobot;
46  };
47 
49  {
50  std::vector<float> targets;
51  };
52 
53  inline Eigen::MatrixXf
54  computeJointLimitWeightMatrix(const Eigen::Ref<const Eigen::VectorXf>& jointAngles,
55  const Eigen::Ref<const Eigen::VectorXf>& jointLimitsLow,
56  const Eigen::Ref<const Eigen::VectorXf>& jointLimitsHigh,
57  Eigen::VectorXf& jointAngleLimitGradient)
58  {
59  // temporally copied from simox control
60  // Based on "A weighted least-norm solution based scheme for avoiding joint limits for redundant joint manipulators", T.F.Chan (1995)
61  int nbJoints = jointAngles.size();
62  Eigen::VectorXf weights(nbJoints);
63  Eigen::VectorXf gradient = Eigen::VectorXf::Zero(nbJoints);
64 
65  if (jointAngleLimitGradient.rows() == 0)
66  {
67  jointAngleLimitGradient = Eigen::VectorXf::Zero(nbJoints);
68  }
69 
70  for (int i = 0; i < nbJoints; i++)
71  {
72  if ((jointLimitsLow(i) == 0 && jointLimitsHigh(i) == 0) || jointLimitsHigh(i) > 1e8)
73  {
74  // Joint is limitless
75  weights(i) = 1.;
76  }
77  else
78  {
79  gradient(i) = std::pow(jointLimitsHigh(i) - jointLimitsLow(i), 2) *
80  (2 * jointAngles(i) - jointLimitsHigh(i) - jointLimitsLow(i)) /
81  (4 * std::pow(jointLimitsHigh(i) - jointAngles(i), 2) *
82  std::pow(jointAngles(i) - jointLimitsLow(i), 2));
83 
84  if ((std::abs(gradient(i)) - std::abs(jointAngleLimitGradient(i))) >= 0.)
85  {
86  // Joint going towards limits
87  weights(i) = 1. / std::sqrt((1. + std::abs(gradient(i))));
88  }
89  else
90  {
91  // Joint going towards the center
92  weights(i) = 1.;
93  }
94  }
95  }
96  jointAngleLimitGradient = gradient;
97  return weights.asDiagonal();
98  }
99 
100 
101 } // namespace armarx::control::common::control_law
armarx::control::common::control_law::RobotStatus::jointTor
Eigen::VectorXf jointTor
Definition: common.h:37
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
armarx::control::common::control_law::ControlTarget::targets
std::vector< float > targets
Definition: common.h:50
armarx::control::common::control_law::RobotStatus::jointTorque
std::vector< float > jointTorque
Definition: common.h:34
armarx::control::common::control_law::RobotStatus::jointPos
Eigen::VectorXf jointPos
Definition: common.h:35
armarx::control::common::control_law::RobotStatus::jointVelocity
std::vector< float > jointVelocity
Definition: common.h:33
armarx::control::common::control_law::VirtualRobotStatus::globalPose
Eigen::Matrix4f globalPose
Definition: common.h:44
armarx::control::common::control_law::VirtualRobotStatus::jointValuesFullRobot
std::vector< float > jointValuesFullRobot
Definition: common.h:45
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::control::common::control_law::RobotStatus
Definition: common.h:29
armarx::control::common::control_law::VirtualRobotStatus
Definition: common.h:42
armarx::control::common::control_law::RobotStatus::jointVel
Eigen::VectorXf jointVel
Definition: common.h:36
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::common::control_law::RobotStatus::jointPosition
std::vector< float > jointPosition
Definition: common.h:32
armarx::channels::KinematicUnitObserver::jointAngles
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::common::control_law::computeJointLimitWeightMatrix
Eigen::MatrixXf computeJointLimitWeightMatrix(const Eigen::Ref< const Eigen::VectorXf > &jointAngles, const Eigen::Ref< const Eigen::VectorXf > &jointLimitsLow, const Eigen::Ref< const Eigen::VectorXf > &jointLimitsHigh, Eigen::VectorXf &jointAngleLimitGradient)
Definition: common.h:54
armarx::control::common::control_law::RobotStatus::numJoints
unsigned int numJoints
Definition: common.h:39
armarx::control::common::control_law::ControlTarget
Definition: common.h:48
armarx::control::common::control_law::RobotStatus::deltaT
double deltaT
Definition: common.h:38