CartesianNaturalPositionControllerProxy.h
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 armar-user (armar-user at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 #include "NaturalIK.h"
27 
28 #include <RobotAPI/interface/units/RobotUnit/NJointCartesianNaturalPositionController.h>
29 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
30 #include <RobotAPI/interface/aron.h>
31 
32 #include <memory>
33 
34 namespace armarx
35 {
36  typedef std::shared_ptr<class CartesianNaturalPositionControllerProxy> CartesianNaturalPositionControllerProxyPtr;
37 
39  {
40  public:
41  struct DynamicKp
42  {
43  bool enabled = false;
44  float maxKp = 1;
45  float sigmaMM = 50;
46  void calculate(float error, float& KpElb, float& KpJla);
47  };
48 
50  {
51  float baseKpTcpPos;
52  float baseKpTcpOri;
53  float baseKpElbPos;
54  float baseKpJla;
55  float baseKpNs;
59  };
60 
62  {
63  float scaleTcpPosVel = 1;
64  float scaleTcpOriVel = 1;
65  float scaleElbPosVel = 1;
68 
69  Ice::FloatSeq baseJointVelocity;
70  float basePosVel;
71  float baseOriVel;
72  };
73 
75  {
78  float rad2mmFactor = 100 / M_PI;
79  //float thresholdTcpOriReached;
80  };
82  {
85  std::optional<float> minElbowHeight = std::nullopt;
86  std::vector<float> userNullspaceTargets;
87  };
88 
89  //typedef std::shared_ptr<class Waypoint> WaypointPtr;
90  class Waypoint
91  {
92  public:
95  //bool offsetFTonEnter = false;
96  //bool resetFTonExit = false;
97  //float forceTheshold = -1;
98 
99  bool reached(const VirtualRobot::RobotNodePtr& tcp);
101  Waypoint& setNullspaceTargets(const std::vector<float>& userNullspaceTargets);
102 
103  //aron::AronObjectPtr toAron();
104  //void fromAron(aron::AronObjectPtr aron);
105  };
106 
108  {
109  public:
110  ScopedJointValueRestore(const VirtualRobot::RobotNodeSetPtr& rns);
112  private:
113  std::vector<float> jointValues;
114  VirtualRobot::RobotNodeSetPtr rns;
115  };
116 
117  CartesianNaturalPositionControllerProxy(const NaturalIK& _ik, const NaturalIK::ArmJoints& arm, const RobotUnitInterfacePrx& _robotUnit, const std::string& _controllerName, NJointCartesianNaturalPositionControllerConfigPtr _config);
118  static NJointCartesianNaturalPositionControllerConfigPtr MakeConfig(const std::string& rns, const std::string& elbowNode);
119 
120  void init();
121 
122  bool setTarget(const Eigen::Matrix4f& tcpTarget, NaturalDiffIK::Mode setOri, std::optional<float> minElbowHeight = std::nullopt);
123  void setNullspaceTarget(const std::vector<float>& nullspaceTargets);
124 
125  Eigen::Vector3f getCurrentTargetPosition();
126  Eigen::Vector3f getCurrentElbowTargetPosition();
127 
128  float getTcpPositionError();
129  float getTcpOrientationError();
130  float getElbPositionError();
131 
132  bool isFinalWaypointReached();
133 
134  void useCurrentFTasOffset();
135  void enableFTLimit(float force, float torque, bool useCurrentFTasOffset);
136  void disableFTLimit();
137  FTSensorValue getCurrentFTValue(bool substactOffset);
138  FTSensorValue getAverageFTValue(bool substactOffset);
139  void stopClear();
140 
141 
142  void setRuntimeConfig(CartesianNaturalPositionControllerConfig runCfg);
143  CartesianNaturalPositionControllerConfig getRuntimeConfig();
144 
145  void addWaypoint(const Waypoint& waypoint);
146  Waypoint createWaypoint(const Eigen::Vector3f& tcpTarget, const std::vector<float>& userNullspaceTargets, std::optional<float> minElbowHeight = std::nullopt);
147  Waypoint createWaypoint(const Eigen::Vector3f& tcpTarget, std::optional<float> minElbowHeight = std::nullopt);
148  Waypoint createWaypoint(const Eigen::Matrix4f& tcpTarget, std::optional<float> minElbowHeight = std::nullopt);
149  void clearWaypoints();
150  void setDefaultWaypointConfig(const WaypointConfig& config);
151 
152 
153  std::string getStatusText();
154 
155  //void setTargetVelocity(const Eigen::VectorXf& cv);
156 
157  //void setNullSpaceControl(bool enabled);
158 
159  static std::vector<float> CalculateMaxJointVelocity(const VirtualRobot::RobotNodeSetPtr& rns, float maxPosVel);
160 
161  void setMaxVelocities(float referencePosVel);
162  void updateBaseKpValues(const CartesianNaturalPositionControllerConfig& runCfg);
163 
164  bool update();
166  bool isLastWaypoint();
167 
168  void cleanup();
169 
170 
171  NJointCartesianNaturalPositionControllerInterfacePrx getInternalController();
172 
173  void setDynamicKp(DynamicKp dynamicKp);
175  static std::vector<float> ScaleVec(const std::vector<float>& vec, float scale);
176 
178 
179  private:
180  void updateDynamicKp();
181  void updateNullspaceTargets();
182 
183  bool onWaypointChanged();
184 
185  NaturalIK _ik;
186  RobotUnitInterfacePrx _robotUnit;
187  std::string _side;
188  std::string _controllerName;
189  NJointCartesianNaturalPositionControllerConfigPtr _config;
190  CartesianNaturalPositionControllerConfig _runCfg;
191  bool _controllerCreated = false;
192  NJointCartesianNaturalPositionControllerInterfacePrx _controller;
193  DynamicKp _dynamicKp;
194  Eigen::Matrix4f _tcpTarget;
195  Eigen::Matrix4f _elbTarget;
196  NaturalDiffIK::Mode _setOri;
198  VelocityBaseSettings _velocityBaseSettings;
199  KpBaseSettings _kpBaseSettings;
201  std::vector<Waypoint> _waypoints;
202  size_t _currentWaypointIndex = 0;
203  NaturalIK::Parameters _natikParams;
204  std::vector<float> _userNullspaceTargets;
205  std::vector<float> _naturalNullspaceTargets;
206  std::vector<VirtualRobot::RobotNodePtr> _rnsToElb;
207  bool _setJointNullspaceFromNaturalIK = true;
208 
209  std::map<std::string, WaypointConfig> _defaultWaypointConfigs;
210  bool _waypointChanged = false;
211  FTSensorValue _ftOffset;
212  bool _activateControllerOnInit = false;
213  };
214 }
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::baseKpNs
float baseKpNs
Definition: CartesianNaturalPositionControllerProxy.h:55
armarx::CartesianNaturalPositionControllerProxy::setTarget
bool setTarget(const Eigen::Matrix4f &tcpTarget, NaturalDiffIK::Mode setOri, std::optional< float > minElbowHeight=std::nullopt)
Definition: CartesianNaturalPositionControllerProxy.cpp:97
armarx::CartesianNaturalPositionControllerProxy::cleanup
void cleanup()
Definition: CartesianNaturalPositionControllerProxy.cpp:395
armarx::CartesianNaturalPositionControllerProxy
Definition: CartesianNaturalPositionControllerProxy.h:38
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::maxPositionAcceleration
float maxPositionAcceleration
Definition: CartesianNaturalPositionControllerProxy.h:56
armarx::CartesianNaturalPositionControllerProxy::WaypointConfig::rad2mmFactor
float rad2mmFactor
Definition: CartesianNaturalPositionControllerProxy.h:78
armarx::NaturalIK::Parameters
Definition: NaturalIK.h:52
armarx::CartesianNaturalPositionControllerProxy::getRuntimeConfig
CartesianNaturalPositionControllerConfig getRuntimeConfig()
Definition: CartesianNaturalPositionControllerProxy.cpp:260
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::scaleTcpPosVel
float scaleTcpPosVel
Definition: CartesianNaturalPositionControllerProxy.h:63
armarx::CartesianNaturalPositionControllerProxy::enableFTLimit
void enableFTLimit(float force, float torque, bool useCurrentFTasOffset)
Definition: CartesianNaturalPositionControllerProxy.cpp:171
armarx::CartesianNaturalPositionControllerProxy::WaypointTargets::setOri
NaturalDiffIK::Mode setOri
Definition: CartesianNaturalPositionControllerProxy.h:84
armarx::CartesianNaturalPositionControllerProxy::WaypointConfig
Definition: CartesianNaturalPositionControllerProxy.h:74
armarx::CartesianNaturalPositionControllerProxy::WaypointTargets::minElbowHeight
std::optional< float > minElbowHeight
Definition: CartesianNaturalPositionControllerProxy.h:85
armarx::CartesianNaturalPositionControllerProxy::isFinalWaypointReached
bool isFinalWaypointReached()
Definition: CartesianNaturalPositionControllerProxy.cpp:160
armarx::CartesianNaturalPositionControllerProxy::getInternalController
NJointCartesianNaturalPositionControllerInterfacePrx getInternalController()
Definition: CartesianNaturalPositionControllerProxy.cpp:452
armarx::CartesianNaturalPositionControllerProxy::ScopedJointValueRestore::~ScopedJointValueRestore
~ScopedJointValueRestore()
Definition: CartesianNaturalPositionControllerProxy.cpp:528
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::basePosVel
float basePosVel
Definition: CartesianNaturalPositionControllerProxy.h:70
armarx::NaturalDiffIK::Mode
Mode
Definition: NaturalDiffIK.h:36
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::scaleNullspaceVelocities
float scaleNullspaceVelocities
Definition: CartesianNaturalPositionControllerProxy.h:67
armarx::CartesianNaturalPositionControllerProxy::DynamicKp::sigmaMM
float sigmaMM
Definition: CartesianNaturalPositionControllerProxy.h:45
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::baseJointVelocity
Ice::FloatSeq baseJointVelocity
Definition: CartesianNaturalPositionControllerProxy.h:69
armarx::CartesianNaturalPositionControllerProxy::DynamicKp::calculate
void calculate(float error, float &KpElb, float &KpJla)
Definition: CartesianNaturalPositionControllerProxy.cpp:247
armarx::CartesianNaturalPositionControllerProxy::getCurrentElbowTargetPosition
Eigen::Vector3f getCurrentElbowTargetPosition()
Definition: CartesianNaturalPositionControllerProxy.cpp:136
armarx::CartesianNaturalPositionControllerProxy::clearWaypoints
void clearWaypoints()
Definition: CartesianNaturalPositionControllerProxy.cpp:301
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings
Definition: CartesianNaturalPositionControllerProxy.h:49
armarx::NaturalIK::ArmJoints
Definition: NaturalIK.h:59
armarx::CartesianNaturalPositionControllerProxy::currentWaypoint
Waypoint & currentWaypoint()
Definition: CartesianNaturalPositionControllerProxy.cpp:441
armarx::CartesianNaturalPositionControllerProxy::DynamicKp
Definition: CartesianNaturalPositionControllerProxy.h:41
armarx::CartesianNaturalPositionControllerProxy::getCurrentTargetPosition
Eigen::Vector3f getCurrentTargetPosition()
Definition: CartesianNaturalPositionControllerProxy.cpp:131
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::scaleElbPosVel
float scaleElbPosVel
Definition: CartesianNaturalPositionControllerProxy.h:65
armarx::CartesianNaturalPositionControllerProxy::WaypointTargets
Definition: CartesianNaturalPositionControllerProxy.h:81
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::baseOriVel
float baseOriVel
Definition: CartesianNaturalPositionControllerProxy.h:71
armarx::CartesianNaturalPositionControllerProxy::Waypoint::reached
bool reached(const VirtualRobot::RobotNodePtr &tcp)
Definition: CartesianNaturalPositionControllerProxy.cpp:469
armarx::CartesianNaturalPositionControllerProxy::DynamicKp::maxKp
float maxKp
Definition: CartesianNaturalPositionControllerProxy.h:44
armarx::NaturalIK
The NaturalIK class.
Definition: NaturalIK.h:49
armarx::CartesianNaturalPositionControllerProxy::setMaxVelocities
void setMaxVelocities(float referencePosVel)
Definition: CartesianNaturalPositionControllerProxy.cpp:361
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
M_PI
#define M_PI
Definition: MathTools.h:17
armarx::CartesianNaturalPositionControllerProxy::addWaypoint
void addWaypoint(const Waypoint &waypoint)
Definition: CartesianNaturalPositionControllerProxy.cpp:265
armarx::CartesianNaturalPositionControllerProxy::Waypoint::setConfig
Waypoint & setConfig(const WaypointConfig &config)
Definition: CartesianNaturalPositionControllerProxy.cpp:474
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::scaleJointVelocities
float scaleJointVelocities
Definition: CartesianNaturalPositionControllerProxy.h:66
armarx::CartesianNaturalPositionControllerProxy::WaypointConfig::referencePosVel
float referencePosVel
Definition: CartesianNaturalPositionControllerProxy.h:76
armarx::CartesianNaturalPositionControllerProxy::updateBaseKpValues
void updateBaseKpValues(const CartesianNaturalPositionControllerConfig &runCfg)
Definition: CartesianNaturalPositionControllerProxy.cpp:383
armarx::CartesianNaturalPositionControllerProxy::getStatusText
std::string getStatusText()
Definition: CartesianNaturalPositionControllerProxy.cpp:312
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings
Definition: CartesianNaturalPositionControllerProxy.h:61
armarx::CartesianNaturalPositionControllerProxy::WaypointTargets::userNullspaceTargets
std::vector< float > userNullspaceTargets
Definition: CartesianNaturalPositionControllerProxy.h:86
armarx::CartesianNaturalPositionControllerProxy::disableFTLimit
void disableFTLimit()
Definition: CartesianNaturalPositionControllerProxy.cpp:180
armarx::CartesianNaturalPositionControllerProxy::getCurrentFTValue
FTSensorValue getCurrentFTValue(bool substactOffset)
Definition: CartesianNaturalPositionControllerProxy.cpp:186
armarx::CartesianNaturalPositionControllerProxy::update
bool update()
Definition: CartesianNaturalPositionControllerProxy.cpp:410
armarx::CartesianNaturalPositionControllerProxy::Waypoint::setNullspaceTargets
Waypoint & setNullspaceTargets(const std::vector< float > &userNullspaceTargets)
Definition: CartesianNaturalPositionControllerProxy.cpp:480
armarx::CartesianNaturalPositionControllerProxy::getDynamicKp
DynamicKp getDynamicKp()
Definition: CartesianNaturalPositionControllerProxy.cpp:463
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::baseKpElbPos
float baseKpElbPos
Definition: CartesianNaturalPositionControllerProxy.h:53
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::baseKpTcpPos
float baseKpTcpPos
Definition: CartesianNaturalPositionControllerProxy.h:51
armarx::CartesianNaturalPositionControllerProxy::createWaypoint
Waypoint createWaypoint(const Eigen::Vector3f &tcpTarget, const std::vector< float > &userNullspaceTargets, std::optional< float > minElbowHeight=std::nullopt)
Definition: CartesianNaturalPositionControllerProxy.cpp:274
armarx::CartesianNaturalPositionControllerProxy::ScaleVec
static std::vector< float > ScaleVec(const std::vector< float > &vec, float scale)
Definition: CartesianNaturalPositionControllerProxy.cpp:346
armarx::CartesianNaturalPositionControllerProxy::DynamicKp::enabled
bool enabled
Definition: CartesianNaturalPositionControllerProxy.h:43
armarx::CartesianNaturalPositionControllerProxy::getElbPositionError
float getElbPositionError()
Definition: CartesianNaturalPositionControllerProxy.cpp:155
armarx::CartesianNaturalPositionControllerProxy::setNullspaceTarget
void setNullspaceTarget(const std::vector< float > &nullspaceTargets)
Definition: CartesianNaturalPositionControllerProxy.cpp:124
armarx::CartesianNaturalPositionControllerProxy::MakeConfig
static NJointCartesianNaturalPositionControllerConfigPtr MakeConfig(const std::string &rns, const std::string &elbowNode)
Definition: CartesianNaturalPositionControllerProxy.cpp:68
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::CartesianNaturalPositionControllerProxy::getTcpOrientationError
float getTcpOrientationError()
Definition: CartesianNaturalPositionControllerProxy.cpp:146
armarx::CartesianNaturalPositionControllerProxy::Waypoint::targets
WaypointTargets targets
Definition: CartesianNaturalPositionControllerProxy.h:93
armarx::CartesianNaturalPositionControllerProxy::WaypointConfig::thresholdTcpPosReached
float thresholdTcpPosReached
Definition: CartesianNaturalPositionControllerProxy.h:77
armarx::CartesianNaturalPositionControllerProxy::useCurrentFTasOffset
void useCurrentFTasOffset()
Definition: CartesianNaturalPositionControllerProxy.cpp:165
armarx::CartesianNaturalPositionControllerProxy::VelocityBaseSettings::scaleTcpOriVel
float scaleTcpOriVel
Definition: CartesianNaturalPositionControllerProxy.h:64
armarx::CartesianNaturalPositionControllerProxy::stopClear
void stopClear()
Definition: CartesianNaturalPositionControllerProxy.cpp:207
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::maxNullspaceAcceleration
float maxNullspaceAcceleration
Definition: CartesianNaturalPositionControllerProxy.h:58
armarx::CartesianNaturalPositionControllerProxy::Waypoint::config
WaypointConfig config
Definition: CartesianNaturalPositionControllerProxy.h:94
armarx::CartesianNaturalPositionControllerProxy::init
void init()
Definition: CartesianNaturalPositionControllerProxy.cpp:76
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx::CartesianNaturalPositionControllerProxy::Waypoint
Definition: CartesianNaturalPositionControllerProxy.h:90
armarx::CartesianNaturalPositionControllerProxy::setDynamicKp
void setDynamicKp(DynamicKp dynamicKp)
Definition: CartesianNaturalPositionControllerProxy.cpp:457
armarx::NaturalIK::SoechtingForwardPositions
Definition: NaturalIK.h:89
armarx::CartesianNaturalPositionControllerProxy::setRuntimeConfig
void setRuntimeConfig(CartesianNaturalPositionControllerConfig runCfg)
Definition: CartesianNaturalPositionControllerProxy.cpp:254
armarx::CartesianNaturalPositionControllerProxy::setDefaultWaypointConfig
void setDefaultWaypointConfig(const WaypointConfig &config)
Definition: CartesianNaturalPositionControllerProxy.cpp:307
armarx::CartesianNaturalPositionControllerProxy::isLastWaypoint
bool isLastWaypoint()
Definition: CartesianNaturalPositionControllerProxy.cpp:447
armarx::CartesianNaturalPositionControllerProxy::getTcpPositionError
float getTcpPositionError()
Definition: CartesianNaturalPositionControllerProxy.cpp:141
armarx::CartesianNaturalPositionControllerProxyPtr
std::shared_ptr< class CartesianNaturalPositionControllerProxy > CartesianNaturalPositionControllerProxyPtr
Definition: CartesianNaturalPositionControllerProxy.h:36
armarx::CartesianNaturalPositionControllerProxy::WaypointTargets::tcpTarget
Eigen::Matrix4f tcpTarget
Definition: CartesianNaturalPositionControllerProxy.h:83
armarx::CartesianNaturalPositionControllerProxy::getAverageFTValue
FTSensorValue getAverageFTValue(bool substactOffset)
Definition: CartesianNaturalPositionControllerProxy.cpp:196
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::baseKpTcpOri
float baseKpTcpOri
Definition: CartesianNaturalPositionControllerProxy.h:52
armarx::CartesianNaturalPositionControllerProxy::CalculateMaxJointVelocity
static std::vector< float > CalculateMaxJointVelocity(const VirtualRobot::RobotNodeSetPtr &rns, float maxPosVel)
Definition: CartesianNaturalPositionControllerProxy.cpp:320
armarx::CartesianNaturalPositionControllerProxy::ScopedJointValueRestore
Definition: CartesianNaturalPositionControllerProxy.h:107
armarx::CartesianNaturalPositionControllerProxy::CartesianNaturalPositionControllerProxy
CartesianNaturalPositionControllerProxy(const NaturalIK &_ik, const NaturalIK::ArmJoints &arm, const RobotUnitInterfacePrx &_robotUnit, const std::string &_controllerName, NJointCartesianNaturalPositionControllerConfigPtr _config)
Definition: CartesianNaturalPositionControllerProxy.cpp:37
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::baseKpJla
float baseKpJla
Definition: CartesianNaturalPositionControllerProxy.h:54
armarx::CartesianNaturalPositionControllerProxy::KpBaseSettings::maxOrientationAcceleration
float maxOrientationAcceleration
Definition: CartesianNaturalPositionControllerProxy.h:57
armarx::CartesianNaturalPositionControllerProxy::setActivateControllerOnInit
void setActivateControllerOnInit(bool value)
Definition: CartesianNaturalPositionControllerProxy.cpp:356
NaturalIK.h
armarx::CartesianNaturalPositionControllerProxy::ScopedJointValueRestore::ScopedJointValueRestore
ScopedJointValueRestore(const VirtualRobot::RobotNodeSetPtr &rns)
Definition: CartesianNaturalPositionControllerProxy.cpp:523