NJointCartesianNaturalPositionController.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <VirtualRobot/VirtualRobot.h>
4 
6 
8 #include <RobotAPI/interface/units/RobotUnit/NJointCartesianNaturalPositionController.h>
10 
11 namespace armarx
12 {
13 
14  TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController);
15 
16  /**
17  * @brief The NJointCartesianNaturalPositionController class
18  * @ingroup Library-RobotUnit-NJointControllers
19  */
21  public NJointController,
22  public NJointCartesianNaturalPositionControllerInterface
23  {
24  public:
25  using ConfigPtrT = NJointCartesianNaturalPositionControllerConfigPtr;
27  RobotUnit* robotUnit,
28  const NJointCartesianNaturalPositionControllerConfigPtr& config,
29  const VirtualRobot::RobotPtr&);
30 
31  // NJointControllerInterface interface
32  std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
33 
34  // NJointController interface
35  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
36  const IceUtil::Time& timeSinceLastIteration) override;
37 
38  void onPublish(const SensorAndControl&,
40  const DebugObserverInterfacePrx&) override;
41 
42  public:
43  //bool hasReachedTarget(const Ice::Current& = Ice::emptyCurrent) override;
44  //bool hasReachedForceLimit(const Ice::Current& = Ice::emptyCurrent) override;
45 
46  void setConfig(const CartesianNaturalPositionControllerConfig& cfg,
47  const Ice::Current& = Ice::emptyCurrent) override;
48  void setTarget(const Eigen::Matrix4f& tcpTarget,
49  const Eigen::Vector3f& elbowTarget,
50  bool setOrientation,
51  const Ice::Current& = Ice::emptyCurrent) override;
52  void setTargetFeedForward(const Eigen::Matrix4f& tcpTarget,
53  const Eigen::Vector3f& elbowTarget,
54  bool setOrientation,
55  const Eigen::Vector6f& ffVel,
56  const Ice::Current&) override;
57  void setFeedForwardVelocity(const Eigen::Vector6f& vel, const Ice::Current&) override;
58  void clearFeedForwardVelocity(const Ice::Current&) override;
59  void setNullspaceTarget(const Ice::FloatSeq& nullspaceTarget, const Ice::Current&) override;
60  void clearNullspaceTarget(const Ice::Current&) override;
61  void setNullspaceControlEnabled(bool enabled, const Ice::Current&) override;
62 
63  FTSensorValue getCurrentFTValue(const Ice::Current&) override;
64  FTSensorValue getAverageFTValue(const Ice::Current&) override;
65  void setFTOffset(const FTSensorValue& offset, const Ice::Current&) override;
66  void resetFTOffset(const Ice::Current&) override;
67  void setFTLimit(float force, float torque, const Ice::Current&) override;
68  void clearFTLimit(const Ice::Current&) override;
69  void setFakeFTValue(const FTSensorValue& ftValue, const Ice::Current&) override;
70  void clearFakeFTValue(const Ice::Current&) override;
71  bool isAtForceLimit(const Ice::Current&) override;
72 
73  void stopMovement(const Ice::Current& = Ice::emptyCurrent) override;
74 
76  const Ice::Current& = Ice::emptyCurrent) override;
77  void resetVisualizationRobotGlobalPose(const Ice::Current& = Ice::emptyCurrent) override;
78 
79  protected:
80  void rtPreActivateController() override;
81  void rtPostDeactivateController() override;
82 
83  //structs
84  private:
85  struct TB_Target
86  {
87  Eigen::Matrix4f tcpTarget;
88  Eigen::Vector3f elbowTarget;
89  bool setOrientation;
90  bool updated = false;
91  };
92 
93  struct TB_FFvel
94  {
95  Eigen::Vector6f feedForwardVelocity = Eigen::Vector6f::Zero();
96  bool use = false;
97  bool updated = false;
98  };
99 
100  struct TB_Cfg
101  {
102  CartesianNaturalPositionControllerConfig cfg;
103  bool updated = false;
104  };
105 
106  struct TB_NT
107  {
108  std::vector<float> nullspaceTarget;
109  bool clearRequested = false;
110  bool updated = false;
111  };
112 
113  struct TB_FT
114  {
115  Eigen::Vector3f force = Eigen::Vector3f::Zero();
116  Eigen::Vector3f torque = Eigen::Vector3f::Zero();
117  bool updated = false;
118  };
119 
120  struct TB_FTlimit
121  {
122  float force = -1;
123  float torque = -1;
124  bool updated = false;
125  };
126 
127  struct TB_FTfake
128  {
129  Eigen::Vector3f force = Eigen::Vector3f::Zero();
130  Eigen::Vector3f torque = Eigen::Vector3f::Zero();
131  bool use = false;
132  bool updated = false;
133  };
134 
135  struct FTval
136  {
137  Eigen::Vector3f force = Eigen::Vector3f::Zero();
138  Eigen::Vector3f torque = Eigen::Vector3f::Zero();
139  };
140 
141  struct RtToNonRtData
142  {
148 
149  FTval currentFT;
150  FTval averageFT;
151 
152  //Eigen::Matrix4f ftInRoot = Eigen::Matrix4f::Identity();
153  //Eigen::Vector3f ftUsed = Eigen::Vector3f::Zero();
154  };
155 
156  struct PublishData
157  {
158  std::atomic<float> errorPos{0};
159  std::atomic<float> errorOri{0};
160  std::atomic<float> errorPosMax{0};
161  std::atomic<float> errorOriMax{0};
162  std::atomic<float> tcpPosVel{0};
163  std::atomic<float> tcpOriVel{0};
164  std::atomic<float> elbPosVel{0};
165  //std::atomic<bool> targetReached;
166  };
167 
168  //data
169  private:
170  void setNullVelocity();
171  FTSensorValue frost(const FTval& ft);
172 
173  using Ctrl = CartesianNaturalPositionController;
174 
175  //rt data
176  VirtualRobot::RobotPtr _rtRobot;
177  VirtualRobot::RobotNodeSetPtr _rtRns;
178  VirtualRobot::RobotNodePtr _rtTcp;
179  VirtualRobot::RobotNodePtr _rtElbow;
180  VirtualRobot::RobotNodePtr _rtFT;
181  VirtualRobot::RobotNodePtr _rtRobotRoot;
182 
183  std::unique_ptr<Ctrl> _rtPosController;
184  bool _rtSetOrientation = true;
185  Eigen::VectorXf _rtJointVelocityFeedbackBuffer;
186  TB_FFvel _rtFFvel;
187  int _rtFFvelMaxAgeMS;
188  long _rtFFvelLastUpdateMS = 0;
189 
190  std::vector<const float*> _rtVelSensors;
191  std::vector<float*> _rtVelTargets;
192 
193  const Eigen::Vector3f* _rtForceSensor = nullptr;
194  const Eigen::Vector3f* _rtTorqueSensor = nullptr;
195 
196  std::vector<FTval> _rtFTHistory;
197  size_t _rtFTHistoryIndex = 0;
198 
199  TB_FT _rtFTOffset;
200  TB_FTlimit _rtFTlimit;
201  TB_FTfake _rtFTfake;
202 
203  //Eigen::Vector3f _rtForceOffset;
204 
205  //float _rtForceThreshold = -1;
206  bool _rtStopConditionReached = false;
207 
208  std::atomic_bool _nullspaceControlEnabled{true};
209 
210  //flags
211  //std::atomic_bool _publishIsAtTarget{false};
212  std::atomic_bool _publishIsAtForceLimit{false};
213  //std::atomic_bool _setFTOffset{false};
214  std::atomic_bool _stopNowRequested{false};
215 
216  //buffers
217  mutable std::recursive_mutex _mutexSetTripBuf;
218  //TripleBuffer<CtrlData> _tripBufPosCtrl;
219  TripleBuffer<TB_Target> _tripBufTarget;
220  TripleBuffer<TB_NT> _tripBufNullspaceTarget;
221  TripleBuffer<TB_FFvel> _tripBufFFvel;
222  TripleBuffer<TB_Cfg> _tripBufCfg;
223  TripleBuffer<TB_FT> _tripBufFToffset;
224  TripleBuffer<TB_FTlimit> _tripBufFTlimit;
225  TripleBuffer<TB_FTfake> _tripBufFTfake;
226 
227 
228  mutable std::recursive_mutex _tripRt2NonRtMutex;
229  TripleBuffer<RtToNonRtData> _tripRt2NonRt;
230 
231  mutable std::recursive_mutex _tripFakeRobotGPWriteMutex;
232  TripleBuffer<Eigen::Matrix4f> _tripFakeRobotGP;
233 
234  //publish data
235  PublishData _publish;
236 
237  //std::atomic<float> _publishForceThreshold{0};
238  //std::atomic<float> _publishForceCurrent{0};
239  //std::atomic_bool _publishForceThresholdInRobotRootZ{0};
240  };
241 } // namespace armarx
armarx::NJointCartesianNaturalPositionController::setNullspaceControlEnabled
void setNullspaceControlEnabled(bool enabled, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:524
armarx::NJointCartesianNaturalPositionController::NJointCartesianNaturalPositionController
NJointCartesianNaturalPositionController(RobotUnit *robotUnit, const NJointCartesianNaturalPositionControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointCartesianNaturalPositionController.cpp:68
armarx::NJointCartesianNaturalPositionController::resetFTOffset
void resetFTOffset(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:569
NJointControllerBase.h
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::NJointCartesianNaturalPositionController::stopMovement
void stopMovement(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:493
armarx::NJointCartesianNaturalPositionController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointCartesianNaturalPositionController.cpp:643
armarx::NJointCartesianNaturalPositionController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointCartesianNaturalPositionController.cpp:178
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::NJointCartesianNaturalPositionController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: NJointCartesianNaturalPositionController.cpp:63
armarx::NJointCartesianNaturalPositionController::clearFakeFTValue
void clearFakeFTValue(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:623
CartesianNaturalPositionController.h
armarx::NJointCartesianNaturalPositionController::setTarget
void setTarget(const Eigen::Matrix4f &tcpTarget, const Eigen::Vector3f &elbowTarget, bool setOrientation, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:393
use
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: license.txt:39
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::NJointCartesianNaturalPositionController::clearFeedForwardVelocity
void clearFeedForwardVelocity(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:448
armarx::NJointCartesianNaturalPositionController::setFakeFTValue
void setFakeFTValue(const FTSensorValue &ftValue, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:607
armarx::NJointCartesianNaturalPositionController::setFTLimit
void setFTLimit(float force, float torque, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:581
armarx::NJointCartesianNaturalPositionController::ConfigPtrT
NJointCartesianNaturalPositionControllerConfigPtr ConfigPtrT
Definition: NJointCartesianNaturalPositionController.h:25
armarx::NJointCartesianNaturalPositionController::setConfig
void setConfig(const CartesianNaturalPositionControllerConfig &cfg, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:380
armarx::NJointCartesianNaturalPositionController::setVisualizationRobotGlobalPose
void setVisualizationRobotGlobalPose(const Eigen::Matrix4f &p, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:475
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::NJointCartesianNaturalPositionController::clearNullspaceTarget
void clearNullspaceTarget(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:513
armarx::NJointCartesianNaturalPositionController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: NJointCartesianNaturalPositionController.cpp:375
armarx::NJointCartesianNaturalPositionController::isAtForceLimit
bool isAtForceLimit(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:636
armarx::NJointCartesianNaturalPositionController::resetVisualizationRobotGlobalPose
void resetVisualizationRobotGlobalPose(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:485
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::NJointCartesianNaturalPositionController::setFeedForwardVelocity
void setFeedForwardVelocity(const Eigen::Vector6f &vel, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:435
armarx::NJointCartesianNaturalPositionController::clearFTLimit
void clearFTLimit(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:595
armarx::NJointCartesianNaturalPositionController::getCurrentFTValue
FTSensorValue getCurrentFTValue(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:540
armarx::NJointCartesianNaturalPositionController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointCartesianNaturalPositionController.cpp:159
TripleBuffer.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::NJointCartesianNaturalPositionController::setNullspaceTarget
void setNullspaceTarget(const Ice::FloatSeq &nullspaceTarget, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:499
armarx::NJointCartesianNaturalPositionController::setFTOffset
void setFTOffset(const FTSensorValue &offset, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:554
armarx::NJointCartesianNaturalPositionController::getAverageFTValue
FTSensorValue getAverageFTValue(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:547
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
Eigen::Matrix< float, 6, 1 >
armarx::NJointCartesianNaturalPositionController
The NJointCartesianNaturalPositionController class.
Definition: NJointCartesianNaturalPositionController.h:20
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::NJointCartesianNaturalPositionController::setTargetFeedForward
void setTargetFeedForward(const Eigen::Matrix4f &tcpTarget, const Eigen::Vector3f &elbowTarget, bool setOrientation, const Eigen::Vector6f &ffVel, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:410
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18