NJointCartesianWaypointController.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/NJointCartesianWaypointController.h>
10 
11 namespace armarx
12 {
13 
14  TYPEDEF_PTRS_HANDLE(NJointCartesianWaypointController);
15 
16  /**
17  * @brief The NJointCartesianWaypointController class
18  * @ingroup Library-RobotUnit-NJointControllers
19  */
21  public NJointController,
22  public NJointCartesianWaypointControllerInterface
23  {
24  public:
25  using ConfigPtrT = NJointCartesianWaypointControllerConfigPtr;
27  const NJointCartesianWaypointControllerConfigPtr& config,
28  const VirtualRobot::RobotPtr&);
29 
30  // NJointControllerInterface interface
31  std::string getClassName(const Ice::Current& = Ice::emptyCurrent) const override;
32  // WidgetDescription::StringWidgetDictionary getFunctionDescriptions(const Ice::Current& = Ice::emptyCurrent) const override;
33  // void callDescribedFunction(const std::string& name, const StringVariantBaseMap& valueMap, const Ice::Current& = Ice::emptyCurrent) override;
34 
35  // NJointController interface
36  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
37  const IceUtil::Time& timeSinceLastIteration) override;
38  // static WidgetDescription::WidgetPtr GenerateConfigDescription(
39  // const VirtualRobot::RobotPtr&,
40  // const std::map<std::string, ConstControlDevicePtr>&,
41  // const std::map<std::string, ConstSensorDevicePtr>&);
42 
43  // static NJointCartesianWaypointControllerConfigPtr GenerateConfigFromVariants(const StringVariantBaseMap& values);
44  // NJointCartesianWaypointController(
45  // RobotUnitPtr prov,
46  // NJointCartesianWaypointControllerConfigPtr config,
47  // const VirtualRobot::RobotPtr& r);
48 
49  void onPublish(const SensorAndControl&,
51  const DebugObserverInterfacePrx&) override;
52 
53  public:
54  bool hasReachedTarget(const Ice::Current& = Ice::emptyCurrent) override;
55  bool hasReachedForceLimit(const Ice::Current& = Ice::emptyCurrent) override;
56  int getCurrentWaypointIndex(const Ice::Current& = Ice::emptyCurrent) override;
57 
58  void setConfig(const NJointCartesianWaypointControllerRuntimeConfig& cfg,
59  const Ice::Current& = Ice::emptyCurrent) override;
60  void setWaypoints(const std::vector<Eigen::Matrix4f>& wps,
61  const Ice::Current& = Ice::emptyCurrent) override;
62  void setWaypointAx(const Ice::FloatSeq& data,
63  const Ice::Current& = Ice::emptyCurrent) override;
64  void setWaypoint(const Eigen::Matrix4f& wp,
65  const Ice::Current& = Ice::emptyCurrent) override;
66  void setConfigAndWaypoints(const NJointCartesianWaypointControllerRuntimeConfig& cfg,
67  const std::vector<Eigen::Matrix4f>& wps,
68  const Ice::Current& = Ice::emptyCurrent) override;
69  void setConfigAndWaypoint(const NJointCartesianWaypointControllerRuntimeConfig& cfg,
70  const Eigen::Matrix4f& wp,
71  const Ice::Current& = Ice::emptyCurrent) override;
72  void stopMovement(const Ice::Current& = Ice::emptyCurrent) override;
73 
74  FTSensorValue getFTSensorValue(const Ice::Current& = Ice::emptyCurrent) override;
75  void setCurrentFTAsOffset(const Ice::Current& = Ice::emptyCurrent) override;
76 
78  const Ice::Current& = Ice::emptyCurrent) override;
79  void resetVisualizationRobotGlobalPose(const Ice::Current& = Ice::emptyCurrent) override;
80 
81  protected:
82  void rtPreActivateController() override;
83  void rtPostDeactivateController() override;
84 
85  //structs
86  private:
87  struct CtrlData
88  {
89  std::vector<Eigen::Matrix4f> wps;
90  NJointCartesianWaypointControllerRuntimeConfig cfg;
91  float skipRad2mmFactor = 500;
92  bool wpsUpdated = false;
93  bool cfgUpdated = false;
94  bool skipToClosestWaypoint = true;
95  };
96 
97  struct RtToNonRtData
98  {
99  FTSensorValue ft;
104  Eigen::Vector3f ftUsed = Eigen::Vector3f::Zero();
105  };
106 
107  //data
108  private:
109  void setNullVelocity();
110 
111  using Ctrl = CartesianWaypointController;
112 
113  //rt data
114  VirtualRobot::RobotPtr _rtRobot;
115  VirtualRobot::RobotNodeSetPtr _rtRns;
116  VirtualRobot::RobotNodePtr _rtTcp;
117  VirtualRobot::RobotNodePtr _rtFT;
118  VirtualRobot::RobotNodePtr _rtRobotRoot;
119 
120  std::unique_ptr<Ctrl> _rtWpController;
121  Eigen::VectorXf _rtJointVelocityFeedbackBuffer;
122 
123  std::vector<const float*> _rtVelSensors;
124  std::vector<float*> _rtVelTargets;
125 
126  const Eigen::Vector3f* _rtForceSensor = nullptr;
127  const Eigen::Vector3f* _rtTorqueSensor = nullptr;
128 
129  Eigen::Vector3f _rtForceOffset;
130 
131  float _rtForceThreshold = -1;
132  bool _rtOptimizeNullspaceIfTargetWasReached = false;
133  bool _rtForceThresholdInRobotRootZ = true;
134  bool _rtHasWps = false;
135  bool _rtStopConditionReached = false;
136 
137  //flags
138  std::atomic_bool _publishIsAtTarget{false};
139  std::atomic_bool _publishIsAtForceLimit{false};
140  std::atomic_bool _setFTOffset{false};
141 
142  //buffers
143  mutable std::recursive_mutex _tripBufWpCtrlMut;
144  WriteBufferedTripleBuffer<CtrlData> _tripBufWpCtrl;
145 
146  mutable std::recursive_mutex _tripRt2NonRtMutex;
147  TripleBuffer<RtToNonRtData> _tripRt2NonRt;
148 
149  TripleBuffer<Eigen::Matrix4f> _tripRt2NonRtRobotGP;
150 
151  //publish data
152  std::atomic_size_t _publishWpsNum{0};
153  std::atomic_size_t _publishWpsCur{0};
154  std::atomic<float> _publishErrorPos{0};
155  std::atomic<float> _publishErrorOri{0};
156  std::atomic<float> _publishErrorPosMax{0};
157  std::atomic<float> _publishErrorOriMax{0};
158  std::atomic<float> _publishForceThreshold{0};
159  std::atomic<float> _publishForceCurrent{0};
160  std::atomic_bool _publishForceThresholdInRobotRootZ{0};
161  };
162 } // namespace armarx
armarx::NJointCartesianWaypointController::setCurrentFTAsOffset
void setCurrentFTAsOffset(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:408
NJointControllerBase.h
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::NJointCartesianWaypointController::NJointCartesianWaypointController
NJointCartesianWaypointController(RobotUnit *robotUnit, const NJointCartesianWaypointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointCartesianWaypointController.cpp:51
CartesianWaypointController.h
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::NJointCartesianWaypointController::setWaypoint
void setWaypoint(const Eigen::Matrix4f &wp, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:326
armarx::NJointCartesianWaypointController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointCartesianWaypointController.cpp:138
armarx::NJointCartesianWaypointController::setVisualizationRobotGlobalPose
void setVisualizationRobotGlobalPose(const Eigen::Matrix4f &p, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:415
armarx::NJointCartesianWaypointController::resetVisualizationRobotGlobalPose
void resetVisualizationRobotGlobalPose(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:422
armarx::NJointCartesianWaypointController::hasReachedForceLimit
bool hasReachedForceLimit(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:393
armarx::NJointCartesianWaypointController::getCurrentWaypointIndex
int getCurrentWaypointIndex(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:524
armarx::NJointCartesianWaypointController::setConfigAndWaypoint
void setConfigAndWaypoint(const NJointCartesianWaypointControllerRuntimeConfig &cfg, const Eigen::Matrix4f &wp, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:367
armarx::NJointCartesianWaypointController::setConfigAndWaypoints
void setConfigAndWaypoints(const NJointCartesianWaypointControllerRuntimeConfig &cfg, const std::vector< Eigen::Matrix4f > &wps, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:351
armarx::NJointCartesianWaypointController::ConfigPtrT
NJointCartesianWaypointControllerConfigPtr ConfigPtrT
Definition: NJointCartesianWaypointController.h:25
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::NJointCartesianWaypointController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: NJointCartesianWaypointController.cpp:290
armarx::NJointCartesianWaypointController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointCartesianWaypointController.cpp:440
armarx::NJointCartesianWaypointController::stopMovement
void stopMovement(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:428
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::NJointCartesianWaypointController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: NJointCartesianWaypointController.cpp:46
armarx::NJointCartesianWaypointController::setWaypoints
void setWaypoints(const std::vector< Eigen::Matrix4f > &wps, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:314
armarx::NJointCartesianWaypointController::setConfig
void setConfig(const NJointCartesianWaypointControllerRuntimeConfig &cfg, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:301
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::NJointCartesianWaypointController
The NJointCartesianWaypointController class.
Definition: NJointCartesianWaypointController.h:20
TripleBuffer.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::NJointCartesianWaypointController::getFTSensorValue
FTSensorValue getFTSensorValue(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:400
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::NJointCartesianWaypointController::setWaypointAx
void setWaypointAx(const Ice::FloatSeq &data, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:338
armarx::NJointCartesianWaypointController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointCartesianWaypointController.cpp:164
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::NJointCartesianWaypointController::hasReachedTarget
bool hasReachedTarget(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianWaypointController.cpp:295