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 <memory>
27
28#include <RobotAPI/interface/aron.h>
29#include <RobotAPI/interface/units/RobotUnit/NJointCartesianNaturalPositionController.h>
30#include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
31
32#include "NaturalIK.h"
33
34namespace armarx
35{
36 typedef std::shared_ptr<class CartesianNaturalPositionControllerProxy>
38
40 {
41 public:
42 struct DynamicKp
43 {
44 bool enabled = false;
45 float maxKp = 1;
46 float sigmaMM = 50;
47 void calculate(float error, float& KpElb, float& KpJla);
48 };
49
61
63 {
64 float scaleTcpPosVel = 1;
65 float scaleTcpOriVel = 1;
66 float scaleElbPosVel = 1;
69
70 Ice::FloatSeq baseJointVelocity;
73 };
74
76 {
79 float rad2mmFactor = 100 / M_PI;
80 //float thresholdTcpOriReached;
81 };
82
84 {
85 Eigen::Matrix4f tcpTarget;
87 std::optional<float> minElbowHeight = std::nullopt;
88 std::vector<float> userNullspaceTargets;
89 };
90
91 //typedef std::shared_ptr<class Waypoint> WaypointPtr;
93 {
94 public:
97 //bool offsetFTonEnter = false;
98 //bool resetFTonExit = false;
99 //float forceTheshold = -1;
100
101 bool reached(const VirtualRobot::RobotNodePtr& tcp);
103 Waypoint& setNullspaceTargets(const std::vector<float>& userNullspaceTargets);
104
105 //aron::AronObjectPtr toAron();
106 //void fromAron(aron::AronObjectPtr aron);
107 };
108
110 {
111 public:
112 ScopedJointValueRestore(const VirtualRobot::RobotNodeSetPtr& rns);
114
115 private:
116 std::vector<float> jointValues;
117 VirtualRobot::RobotNodeSetPtr rns;
118 };
119
121 const NaturalIK& _ik,
122 const NaturalIK::ArmJoints& arm,
123 const RobotUnitInterfacePrx& _robotUnit,
124 const std::string& _controllerName,
125 NJointCartesianNaturalPositionControllerConfigPtr _config);
126 static NJointCartesianNaturalPositionControllerConfigPtr
127 MakeConfig(const std::string& rns, const std::string& elbowNode);
128
129 void init();
130
131 bool setTarget(const Eigen::Matrix4f& tcpTarget,
132 NaturalDiffIK::Mode setOri,
133 std::optional<float> minElbowHeight = std::nullopt);
134 void setNullspaceTarget(const std::vector<float>& nullspaceTargets);
135
136 Eigen::Vector3f getCurrentTargetPosition();
137 Eigen::Vector3f getCurrentElbowTargetPosition();
138
139 float getTcpPositionError();
141 float getElbPositionError();
142
144
146 void enableFTLimit(float force, float torque, bool useCurrentFTasOffset);
147 void disableFTLimit();
148 FTSensorValue getCurrentFTValue(bool substactOffset);
149 FTSensorValue getAverageFTValue(bool substactOffset);
150 void stopClear();
151
152
153 void setRuntimeConfig(CartesianNaturalPositionControllerConfig runCfg);
154 CartesianNaturalPositionControllerConfig getRuntimeConfig();
155
156 void addWaypoint(const Waypoint& waypoint);
157 Waypoint createWaypoint(const Eigen::Vector3f& tcpTarget,
158 const std::vector<float>& userNullspaceTargets,
159 std::optional<float> minElbowHeight = std::nullopt);
160 Waypoint createWaypoint(const Eigen::Vector3f& tcpTarget,
161 std::optional<float> minElbowHeight = std::nullopt);
162 Waypoint createWaypoint(const Eigen::Matrix4f& tcpTarget,
163 std::optional<float> minElbowHeight = std::nullopt);
164 void clearWaypoints();
165 void setDefaultWaypointConfig(const WaypointConfig& config);
166
167
168 std::string getStatusText();
169
170 //void setTargetVelocity(const Eigen::VectorXf& cv);
171
172 //void setNullSpaceControl(bool enabled);
173
174 static std::vector<float>
175 CalculateMaxJointVelocity(const VirtualRobot::RobotNodeSetPtr& rns, float maxPosVel);
176
177 void setMaxVelocities(float referencePosVel);
178 void updateBaseKpValues(const CartesianNaturalPositionControllerConfig& runCfg);
179
180 bool update();
182 bool isLastWaypoint();
183
184 void cleanup();
185
186
187 NJointCartesianNaturalPositionControllerInterfacePrx getInternalController();
188
189 void setDynamicKp(DynamicKp dynamicKp);
191 static std::vector<float> ScaleVec(const std::vector<float>& vec, float scale);
192
193 void setActivateControllerOnInit(bool value);
194
195 private:
196 void updateDynamicKp();
197 void updateNullspaceTargets();
198
199 bool onWaypointChanged();
200
201 NaturalIK _ik;
202 RobotUnitInterfacePrx _robotUnit;
203 std::string _side;
204 std::string _controllerName;
205 NJointCartesianNaturalPositionControllerConfigPtr _config;
206 CartesianNaturalPositionControllerConfig _runCfg;
207 bool _controllerCreated = false;
208 NJointCartesianNaturalPositionControllerInterfacePrx _controller;
209 DynamicKp _dynamicKp;
210 Eigen::Matrix4f _tcpTarget;
211 Eigen::Matrix4f _elbTarget;
212 NaturalDiffIK::Mode _setOri;
214 VelocityBaseSettings _velocityBaseSettings;
215 KpBaseSettings _kpBaseSettings;
217 std::vector<Waypoint> _waypoints;
218 size_t _currentWaypointIndex = 0;
219 NaturalIK::Parameters _natikParams;
220 std::vector<float> _userNullspaceTargets;
221 std::vector<float> _naturalNullspaceTargets;
222 std::vector<VirtualRobot::RobotNodePtr> _rnsToElb;
223 bool _setJointNullspaceFromNaturalIK = true;
224
225 std::map<std::string, WaypointConfig> _defaultWaypointConfigs;
226 bool _waypointChanged = false;
227 FTSensorValue _ftOffset;
228 bool _activateControllerOnInit = false;
229 };
230} // namespace armarx
#define M_PI
Definition MathTools.h:17
Waypoint & setNullspaceTargets(const std::vector< float > &userNullspaceTargets)
static NJointCartesianNaturalPositionControllerConfigPtr MakeConfig(const std::string &rns, const std::string &elbowNode)
void setRuntimeConfig(CartesianNaturalPositionControllerConfig runCfg)
static std::vector< float > CalculateMaxJointVelocity(const VirtualRobot::RobotNodeSetPtr &rns, float maxPosVel)
void updateBaseKpValues(const CartesianNaturalPositionControllerConfig &runCfg)
void enableFTLimit(float force, float torque, bool useCurrentFTasOffset)
static std::vector< float > ScaleVec(const std::vector< float > &vec, float scale)
bool setTarget(const Eigen::Matrix4f &tcpTarget, NaturalDiffIK::Mode setOri, std::optional< float > minElbowHeight=std::nullopt)
void setNullspaceTarget(const std::vector< float > &nullspaceTargets)
CartesianNaturalPositionControllerProxy(const NaturalIK &_ik, const NaturalIK::ArmJoints &arm, const RobotUnitInterfacePrx &_robotUnit, const std::string &_controllerName, NJointCartesianNaturalPositionControllerConfigPtr _config)
NJointCartesianNaturalPositionControllerInterfacePrx getInternalController()
Waypoint createWaypoint(const Eigen::Vector3f &tcpTarget, const std::vector< float > &userNullspaceTargets, std::optional< float > minElbowHeight=std::nullopt)
The NaturalIK class.
Definition NaturalIK.h:53
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface > RobotUnitInterfacePrx
std::shared_ptr< class CartesianNaturalPositionControllerProxy > CartesianNaturalPositionControllerProxyPtr