DeprecatedNJointPeriodicTSDMPCompliantController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/VirtualRobot.h>
5 
8 
11 
13 #include <armarx/control/deprecated_njoint_mp_controller/task_space/ControllerInterface.h>
14 
15 namespace armarx
16 {
17  class SensorValue1DoFActuatorTorque;
18  class SensorValue1DoFActuatorVelocity;
19  class SensorValue1DoFActuatorPosition;
20  class ControlTarget1DoFActuatorTorque;
21  class SensorValueForceTorque;
22 } // namespace armarx
23 
25 {
27 
28  TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantController);
29  TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantControllerControlData);
30 
32  {
33  public:
34  float targetForce;
37  Eigen::VectorXf targetNullSpaceJointValues;
38  };
39 
40  /**
41  * @brief The DeprecatedNJointPeriodicTSDMPCompliantController class
42  * @ingroup Library-RobotUnit-NJointControllers
43  */
46  DeprecatedNJointPeriodicTSDMPCompliantControllerControlData>,
48  {
49  public:
50  using ConfigPtrT = DeprecatedNJointPeriodicTSDMPCompliantControllerConfigPtr;
52  const NJointControllerConfigPtr& config,
53  const VirtualRobot::RobotPtr&);
54 
55  // NJointControllerInterface interface
56  std::string getClassName(const Ice::Current&) const;
57 
58  // NJointController interface
59 
60  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
61  const IceUtil::Time& timeSinceLastIteration);
62 
63  // DeprecatedNJointPeriodicTSDMPCompliantControllerInterface interface
64  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
65  void learnDMPFromTrajectory(const TrajectoryBasePtr& trajectory,
66  const Ice::Current&) override;
67  bool isFinished(const Ice::Current&) override;
68 
69  void setSpeed(Ice::Double times, const Ice::Current&) override;
70  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
71  void setAmplitude(Ice::Double amp, const Ice::Current&) override;
72  void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&) override;
73 
74  void stopDMP(const Ice::Current&) override;
75  void resumeDMP(const Ice::Current&) override;
76  void pauseDMP(const Ice::Current&) override;
77  void resetDMP(const Ice::Current&) override;
78 
79  void setTargetForceInRootFrame(Ice::Float force, const Ice::Current&) override;
80  double getCanVal(const Ice::Current&) override;
81 
82  void setKpImpedance(const Eigen::Vector6f& kpImpedance, const Ice::Current&) override;
83  void setKdImpedance(const Eigen::Vector6f& kdImpedance, const Ice::Current&) override;
84 
85  Eigen::Vector6f getFilteredForceTorque(Eigen::Vector3f& forceBaseline,
86  Eigen::Vector3f& torqueBaseline,
87  Eigen::Vector6f& handCompensatedFT);
88  Eigen::Vector6f getTCPGravityCompensation(Eigen::Matrix4f& currentPose, float tcpMass);
89  std::string getKinematicChainName(const Ice::Current&);
90 
91  protected:
92  virtual void onPublish(const SensorAndControl&,
95 
98  void controllerRun();
99 
100  private:
101  // RTController::ControllerInfo info;
102  std::string kinematic_chain;
103 
104  // ---------------------- Buffer: control parameter ----------------------
105  struct CtrlParams
106  {
107  Eigen::Vector6f kpImpedance;
108  Eigen::Vector6f kdImpedance;
109 
110  Eigen::VectorXf knull;
111  Eigen::VectorXf dnull;
112 
113  Eigen::Vector4f pidForce;
114 
115  float tcpMass;
116  Eigen::Vector3f tcpCoMInForceSensorFrame;
117  };
118 
120 
121  // ---------------------- Buffer: mp 2 debug data ----------------------
122  struct DebugData
123  {
124  StringFloatDictionary latestTargetVelocities;
125  StringFloatDictionary currentPose;
126  double currentCanVal;
127  double mpcFactor;
128  double error;
129  double phaseStop;
130  double posError;
131  double oriError;
132  double deltaT;
133  };
134 
135  TripleBuffer<DebugData> debugMPBuffer;
136 
137  // ---------------------- Buffer: rt 2 debug data ----------------------
138  struct DebugRTData
139  {
140  Eigen::Matrix4f targetPose;
141  Eigen::Vector3f filteredForce;
142  Eigen::Vector3f reactForce;
143  Eigen::VectorXf targetVel;
144  Eigen::Matrix4f currentPose;
145  Eigen::Vector3f targetVelInTool;
146  bool isPhaseStop;
147  };
148 
149  TripleBuffer<DebugRTData> debugRTBuffer;
150 
151  // ---------------------- Buffer: rt 2 MP thread data ----------------------
152  struct RT2MPData
153  {
154  double currentTime;
155  double deltaT;
156  Eigen::Matrix4f currentPose;
157  Eigen::VectorXf currentTwist;
158  bool isPhaseStop;
159  };
160 
161  TripleBuffer<RT2MPData> rt2MPBuffer;
162 
163  // ---------------------- Buffer: rt 2 interface data ----------------------
164  struct RT2InterfaceData
165  {
166  Eigen::Matrix4f currentTcpPose;
167  float waitTimeForCalibration;
168  };
169 
170  TripleBuffer<RT2InterfaceData> rt2InterfaceBuffer;
171 
172 
173  // ---------------------- low-level control variables ----------------------
174  // device
175  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
176  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
177  std::vector<ControlTarget1DoFActuatorTorque*> targets;
178 
179  PIDControllerPtr forcePID;
180 
181  VirtualRobot::DifferentialIKPtr ik;
182  VirtualRobot::RobotNodePtr tcp;
183 
184  mutable MutexType mpMutex;
186  DeprecatedNJointPeriodicTSDMPCompliantControllerConfigPtr cfg;
188 
189  // // phaseStop parameters
190  // double phaseL;
191  // double phaseK;
192  // double phaseDist0;
193  // double phaseDist1;
194  // double posToOriRatio;
195 
196 
197  float torqueLimit;
198  int numOfJoints;
199  std::vector<std::string> jointNames;
200 
201  Eigen::VectorXf nullSpaceJointsVec;
202  // std::atomic_bool useNullSpaceJointDMP;
203  // bool isNullSpaceJointDMPLearned;
204 
205  std::atomic_bool rtFirstRun = true;
206  std::atomic_bool rtReady = false;
207  std::atomic_bool mpRunning = false;
208 
209  Eigen::Matrix4f previousTargetPose;
210  Eigen::VectorXf qvel_filtered;
211 
212  /// force torque sensor
213  const SensorValueForceTorque* forceSensor;
214  Eigen::Vector3f forceOffset;
215  Eigen::Vector3f torqueOffset;
216  Eigen::Vector3f filteredForce;
217  Eigen::Vector3f filteredTorque;
218  Eigen::Vector3f filteredForceInRoot;
219  Eigen::Vector3f filteredTorqueInRoot;
220  std::atomic<float> timeForCalibration;
221 
222  std::atomic_bool enableTCPGravityCompensation;
223  Eigen::Matrix4f forceFrameInTCP = Eigen::Matrix4f::Identity();
224  Eigen::Vector3f tcpCoMInTCPFrame;
225 
226  /// Tool setup
227  Eigen::Matrix4f toolFrameInRoot;
228  Eigen::Matrix3f toolOriInHand;
229 
230 
231  Eigen::Vector2f lastPosition;
232  double changeTimer;
233  };
234 
235 } // namespace armarx::control::deprecated_njoint_mp_controller::task_space
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setTargetForceInRootFrame
void setTargetForceInRootFrame(Ice::Float force, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:686
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setKdImpedance
void setKdImpedance(const Eigen::Vector6f &kdImpedance, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:615
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::getCanVal
double getCanVal()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:631
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::resetDMP
void resetDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:31
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
NJointControllerWithTripleBuffer.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setAmplitude
void setAmplitude(Ice::Double amp, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:678
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::getFilteredForceTorque
Eigen::Vector6f getFilteredForceTorque(Eigen::Vector3f &forceBaseline, Eigen::Vector3f &torqueBaseline, Eigen::Vector6f &handCompensatedFT)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:557
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:20
armarx::PIDControllerPtr
std::shared_ptr< PIDController > PIDControllerPtr
Definition: PIDController.h:94
PeriodicTask.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:292
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController
The DeprecatedNJointPeriodicTSDMPCompliantController class.
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:44
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:68
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:670
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setKpImpedance
void setKpImpedance(const Eigen::Vector6f &kpImpedance, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:605
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:756
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:662
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetNullSpaceJointValues
Eigen::VectorXf targetNullSpaceJointValues
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:37
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:219
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::DeprecatedNJointPeriodicTSDMPCompliantController
DeprecatedNJointPeriodicTSDMPCompliantController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:27
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::pauseDMP
void pauseDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double tau, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:695
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::learnDMPFromTrajectory
void learnDMPFromTrajectory(const TrajectoryBasePtr &trajectory, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:642
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::getTCPGravityCompensation
Eigen::Vector6f getTCPGravityCompensation(Eigen::Matrix4f &currentPose, float tcpMass)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:540
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::getKinematicChainName
string getKinematicChainName()
CycleUtil.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::controllerRun
void controllerRun()
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:225
PIDController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:31
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:838
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetTSVel
Eigen::Vector6f targetTSVel
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:35
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetForce
float targetForce
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:34
armarx::NJointControllerWithTripleBuffer< DeprecatedNJointPeriodicTSDMPCompliantControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetTSPose
Eigen::Matrix4f targetTSPose
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:36
IceUtil::Handle< class RobotUnit >
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface
Definition: ControllerInterface.ice:618
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::task_space::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantController)
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::resumeDMP
void resumeDMP()
armarx::WriteBufferedTripleBuffer< CtrlParams >
Eigen::Matrix< float, 6, 1 >
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::onInitNJointController
void onInitNJointController()
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:167
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::stopDMP
void stopDMP()
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::isFinished
bool isFinished()
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::TripleBuffer< DebugData >