DeprecatedNJointPeriodicTSDMPCompliantController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 #include <VirtualRobot/Robot.h>
6 #include <VirtualRobot/IK/DifferentialIK.h>
7 
16 
17 #include <armarx/control/deprecated_njoint_mp_controller/task_space/ControllerInterface.h>
19 
20 
22 {
24 
25  TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantController);
26  TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantControllerControlData);
27 
29  {
30  public:
31  float targetForce;
34  Eigen::VectorXf targetNullSpaceJointValues;
35  };
36 
37  /**
38  * @brief The DeprecatedNJointPeriodicTSDMPCompliantController class
39  * @ingroup Library-RobotUnit-NJointControllers
40  */
42  public NJointControllerWithTripleBuffer<DeprecatedNJointPeriodicTSDMPCompliantControllerControlData>,
44  {
45  public:
46  using ConfigPtrT = DeprecatedNJointPeriodicTSDMPCompliantControllerConfigPtr;
47  DeprecatedNJointPeriodicTSDMPCompliantController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
48 
49  // NJointControllerInterface interface
50  std::string getClassName(const Ice::Current&) const;
51 
52  // NJointController interface
53 
54  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration);
55 
56  // DeprecatedNJointPeriodicTSDMPCompliantControllerInterface interface
57  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
58  void learnDMPFromTrajectory(const TrajectoryBasePtr& trajectory, const Ice::Current&) override;
59  bool isFinished(const Ice::Current&) override;
60 
61  void setSpeed(Ice::Double times, const Ice::Current&) override;
62  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
63  void setAmplitude(Ice::Double amp, const Ice::Current&) override;
64  void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&) override;
65 
66  void stopDMP(const Ice::Current&) override;
67  void resumeDMP(const Ice::Current&) override;
68  void pauseDMP(const Ice::Current&) override;
69  void resetDMP(const Ice::Current&) override;
70 
71  void setTargetForceInRootFrame(Ice::Float force, const Ice::Current&) override;
72  double getCanVal(const Ice::Current&) override;
73 
74  void setKpImpedance(const Eigen::Vector6f& kpImpedance, const Ice::Current&) override;
75  void setKdImpedance(const Eigen::Vector6f& kdImpedance, const Ice::Current&) override;
76 
77  Eigen::Vector6f getFilteredForceTorque(Eigen::Vector3f& forceBaseline, Eigen::Vector3f& torqueBaseline, Eigen::Vector6f& handCompensatedFT);
78  Eigen::Vector6f getTCPGravityCompensation(Eigen::Matrix4f& currentPose, float tcpMass);
79  std::string getKinematicChainName(const Ice::Current&);
80  protected:
82 
85  void controllerRun();
86 
87  private:
88  // RTController::ControllerInfo info;
89  std::string kinematic_chain;
90  // ---------------------- Buffer: control parameter ----------------------
91  struct CtrlParams
92  {
93  Eigen::Vector6f kpImpedance;
94  Eigen::Vector6f kdImpedance;
95 
96  Eigen::VectorXf knull;
97  Eigen::VectorXf dnull;
98 
99  Eigen::Vector4f pidForce;
100 
101  float tcpMass;
102  Eigen::Vector3f tcpCoMInForceSensorFrame;
103  };
105 
106  // ---------------------- Buffer: mp 2 debug data ----------------------
107  struct DebugData
108  {
109  StringFloatDictionary latestTargetVelocities;
110  StringFloatDictionary currentPose;
111  double currentCanVal;
112  double mpcFactor;
113  double error;
114  double phaseStop;
115  double posError;
116  double oriError;
117  double deltaT;
118  };
119  TripleBuffer<DebugData> debugMPBuffer;
120 
121  // ---------------------- Buffer: rt 2 debug data ----------------------
122  struct DebugRTData
123  {
124  Eigen::Matrix4f targetPose;
125  Eigen::Vector3f filteredForce;
126  Eigen::Vector3f reactForce;
127  Eigen::VectorXf targetVel;
128  Eigen::Matrix4f currentPose;
129  Eigen::Vector3f targetVelInTool;
130  bool isPhaseStop;
131  };
132  TripleBuffer<DebugRTData> debugRTBuffer;
133 
134  // ---------------------- Buffer: rt 2 MP thread data ----------------------
135  struct RT2MPData
136  {
137  double currentTime;
138  double deltaT;
139  Eigen::Matrix4f currentPose;
140  Eigen::VectorXf currentTwist;
141  bool isPhaseStop;
142  };
143  TripleBuffer<RT2MPData> rt2MPBuffer;
144 
145  // ---------------------- Buffer: rt 2 interface data ----------------------
146  struct RT2InterfaceData
147  {
148  Eigen::Matrix4f currentTcpPose;
149  float waitTimeForCalibration;
150  };
151  TripleBuffer<RT2InterfaceData> rt2InterfaceBuffer;
152 
153 
154 
155  // ---------------------- low-level control variables ----------------------
156  // device
157  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
158  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
159  std::vector<ControlTarget1DoFActuatorTorque*> targets;
160 
161  PIDControllerPtr forcePID;
162 
163  VirtualRobot::DifferentialIKPtr ik;
164  VirtualRobot::RobotNodePtr tcp;
165 
166  mutable MutexType mpMutex;
168  DeprecatedNJointPeriodicTSDMPCompliantControllerConfigPtr cfg;
170 
171  // // phaseStop parameters
172  // double phaseL;
173  // double phaseK;
174  // double phaseDist0;
175  // double phaseDist1;
176  // double posToOriRatio;
177 
178 
179  float torqueLimit;
180  int numOfJoints;
181  std::vector<std::string> jointNames;
182 
183  Eigen::VectorXf nullSpaceJointsVec;
184  // std::atomic_bool useNullSpaceJointDMP;
185  // bool isNullSpaceJointDMPLearned;
186 
187  std::atomic_bool rtFirstRun = true;
188  std::atomic_bool rtReady = false;
189  std::atomic_bool mpRunning = false;
190 
191  Eigen::Matrix4f previousTargetPose;
192  Eigen::VectorXf qvel_filtered;
193 
194  /// force torque sensor
195  const SensorValueForceTorque* forceSensor;
196  Eigen::Vector3f forceOffset;
197  Eigen::Vector3f torqueOffset;
198  Eigen::Vector3f filteredForce;
199  Eigen::Vector3f filteredTorque;
200  Eigen::Vector3f filteredForceInRoot;
201  Eigen::Vector3f filteredTorqueInRoot;
202  std::atomic<float> timeForCalibration;
203 
204  std::atomic_bool enableTCPGravityCompensation;
205  Eigen::Matrix4f forceFrameInTCP = Eigen::Matrix4f::Identity();
206  Eigen::Vector3f tcpCoMInTCPFrame;
207 
208  /// Tool setup
209  Eigen::Matrix4f toolFrameInRoot;
210  Eigen::Matrix3f toolOriInHand;
211 
212 
213  Eigen::Vector2f lastPosition;
214  double changeTimer;
215 
216  };
217 
218 } // namespace armarx
219 
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setTargetForceInRootFrame
void setTargetForceInRootFrame(Ice::Float force, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:596
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setKdImpedance
void setKdImpedance(const Eigen::Vector6f &kdImpedance, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:539
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:551
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::resetDMP
void resetDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:28
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setAmplitude
void setAmplitude(Ice::Double amp, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:590
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
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:497
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:6
armarx::PIDControllerPtr
std::shared_ptr< PIDController > PIDControllerPtr
Definition: PIDController.h:92
SensorValueForceTorque.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:264
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController
The DeprecatedNJointPeriodicTSDMPCompliantController class.
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:41
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:584
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setKpImpedance
void setKpImpedance(const Eigen::Vector6f &kpImpedance, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:532
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:658
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &) override
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:577
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetNullSpaceJointValues
Eigen::VectorXf targetNullSpaceJointValues
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:34
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:194
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::DeprecatedNJointPeriodicTSDMPCompliantController
DeprecatedNJointPeriodicTSDMPCompliantController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:10
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:603
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
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:560
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::getTCPGravityCompensation
Eigen::Vector6f getTCPGravityCompensation(Eigen::Matrix4f &currentPose, float tcpMass)
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:483
CartesianVelocityController.h
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::getKinematicChainName
string getKinematicChainName()
CycleUtil.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::controllerRun
void controllerRun()
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:199
PIDController.h
NJointController.h
Trajectory.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:738
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetTSVel
Eigen::Vector6f targetTSVel
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:32
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointPeriodicTSDMPCompliantControllerControlData::targetForce
float targetForce
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.h:31
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:33
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface
Definition: ControllerInterface.ice:622
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:144
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::stopDMP
void stopDMP()
armarx::DeprecatedNJointPeriodicTSDMPCompliantControllerInterface::isFinished
bool isFinished()
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer< DebugData >