NJointTaskSpaceImpedanceDMPController.h
Go to the documentation of this file.
1 #pragma once
2 // DMP
3 #include <dmp/representation/dmp/umidmp.h>
4 
5 // armarx
8 
9 // control
10 #include <armarx/control/deprecated_njoint_mp_controller/task_space/TaskSpaceImpedanceDMPControllerInterface.h>
11 
12 
13 namespace armarx
14 {
15  class SensorValueForceTorque;
16 
17  class ControlTarget1DoFActuatorTorque;
18 
19 
20  namespace control::deprecated_njoint_mp_controller::tsvmp
21  {
23 
24  using TaskSpaceDMPControllerPtr = std::shared_ptr<TaskSpaceDMPController>;
25  }
26 }
28 {
30 
31  TYPEDEF_PTRS_HANDLE(NJointTaskSpaceImpedanceDMPController);
32  TYPEDEF_PTRS_HANDLE(NJointTaskSpaceImpedanceDMPControllerControlData);
33 
35  {
36  public:
37  Eigen::VectorXf targetVel;
39  Eigen::VectorXf desiredNullSpaceJointValues;
40  double canVal;
41  double mpcFactor;
42  };
43 
44 
45 
46  /**
47  * @brief The NJointTaskSpaceImpedanceDMPController class
48  * @ingroup Library-RobotUnit-NJointControllers
49  */
51  public NJointControllerWithTripleBuffer<NJointTaskSpaceImpedanceDMPControllerControlData>,
53  {
54  public:
55  using ConfigPtrT = NJointTaskSpaceImpedanceDMPControllerConfigPtr;
56  NJointTaskSpaceImpedanceDMPController(const RobotUnitPtr& robotUnit, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
57 
58  // NJointControllerInterface interface
59  std::string getClassName(const Ice::Current&) const override;
60 
61  // NJointController interface
62 
63  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override;
64 
65  // NJointTaskSpaceImpedanceDMPControllerInterface interface
66  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
67  bool isFinished(const Ice::Current&) override
68  {
69  return finished;
70  }
71 
72  bool isDMPRunning(const Ice::Current&) override
73  {
74  return started;
75  }
76 
77  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&) override;
78  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
79 
80  void learnJointDMPFromFiles(const std::string& fileName, const Ice::FloatSeq& currentJVS, const Ice::Current&) override;
81  void runDMP(const Ice::DoubleSeq& goals, const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
82  void runDMPWithTime(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&) override;
83 
84  Ice::Double getVirtualTime(const Ice::Current&) override;
85 
86  void stopDMP(const Ice::Current&) override;
87  void resumeDMP(const Ice::Current&) override;
88  void resetDMP(const Ice::Current&) override;
89 
90  void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&) override;
91  DoubleSeqSeq getMPWeights(const Ice::Current&) override;
92 
93  void removeAllViaPoints(const Ice::Current&) override;
94 
95  void setLinearVelocityKd(const Eigen::Vector3f& kd, const Ice::Current&) override;
96  void setLinearVelocityKp(const Eigen::Vector3f& kp, const Ice::Current&) override;
97  void setAngularVelocityKd(const Eigen::Vector3f& kd, const Ice::Current&) override;
98  void setAngularVelocityKp(const Eigen::Vector3f& kp, const Ice::Current&) override;
99  void setNullspaceVelocityKd(const Eigen::VectorXf& kd, const Ice::Current&) override;
100  void setNullspaceVelocityKp(const Eigen::VectorXf& kp, const Ice::Current&) override;
101  void setUseNullSpaceJointDMP(bool enable, const Ice::Current&) override;
102  void setDefaultNullSpaceJointValues(const Eigen::VectorXf& jointValues, const Ice::Current&) override;
103 
104  void enableForceStop(const Ice::Current&) override
105  {
106  useForceStop = true;
107  }
108  void disableForceStop(const Ice::Current&) override
109  {
110  useForceStop = false;
111  }
112 
113  void setForceThreshold(const Eigen::Vector3f& f, const Ice::Current& current) override
114  {
115  forceThreshold.getWriteBuffer() = f;
116  forceThreshold.commitWrite();
117  }
118  protected:
119  virtual void onPublish(const SensorAndControl&, const DebugDrawerInterfacePrx&, const DebugObserverInterfacePrx&) override;
120 
121  void onInitNJointController() override;
122  void onDisconnectNJointController() override;
123  void controllerRun();
124 
125  private:
126  struct DebugBufferData
127  {
128  double currentCanVal;
129  double mpcfactor;
130  float targetPose_x;
131  float targetPose_y;
132  float targetPose_z;
133  float targetPose_qw;
134  float targetPose_qx;
135  float targetPose_qy;
136  float targetPose_qz;
137 
138  float currentPose_x;
139  float currentPose_y;
140  float currentPose_z;
141  float currentPose_qw;
142  float currentPose_qx;
143  float currentPose_qy;
144  float currentPose_qz;
145 
146  float currentKpos_x;
147  float currentKpos_y;
148  float currentKpos_z;
149  float currentKori_x;
150  float currentKori_y;
151  float currentKori_z;
152  float currentKnull_x;
153  float currentKnull_y;
154  float currentKnull_z;
155 
156  float currentDpos_x;
157  float currentDpos_y;
158  float currentDpos_z;
159  float currentDori_x;
160  float currentDori_y;
161  float currentDori_z;
162  float currentDnull_x;
163  float currentDnull_y;
164  float currentDnull_z;
165 
166  StringFloatDictionary desired_torques;
167  StringFloatDictionary desired_nullspaceJoint;
168  float forceDesired_x;
169  float forceDesired_y;
170  float forceDesired_z;
171  float forceDesired_rx;
172  float forceDesired_ry;
173  float forceDesired_rz;
174 
175  float deltaT;
176 
177 
178 
179  };
180 
182 
183  struct NJointTaskSpaceImpedanceDMPControllerSensorData
184  {
185  double currentTime;
186  double deltaT;
187  Eigen::Matrix4f currentPose;
188  Eigen::VectorXf currentTwist;
189  };
191 
192  struct NJointTaskSpaceImpedanceDMPControllerInterfaceData
193  {
194  Eigen::Matrix4f currentTcpPose;
195  };
196 
198 
199  struct CtrlParams
200  {
201  Eigen::Vector3f kpos;
202  Eigen::Vector3f dpos;
203  Eigen::Vector3f kori;
204  Eigen::Vector3f dori;
205  Eigen::VectorXf knull;
206  Eigen::VectorXf dnull;
207  };
208 
209  WriteBufferedTripleBuffer<CtrlParams> ctrlParams;
210 
211 
212 
213  DMP::Vec<DMP::DMPState> currentJointState;
214  DMP::UMIDMPPtr nullSpaceJointDMPPtr;
215 
217 
218  std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors;
219  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
220  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
221  std::vector<ControlTarget1DoFActuatorTorque*> targets;
222 
223  // velocity ik controller parameters
224  // dmp parameters
225  double timeDuration;
226  bool finished;
227  VirtualRobot::RobotNodeSetPtr rns;
228 
229  // phaseStop parameters
230  double phaseL;
231  double phaseK;
232  double phaseDist0;
233  double phaseDist1;
234  double posToOriRatio;
235 
236 
237  NJointTaskSpaceImpedanceDMPControllerConfigPtr cfg;
238  VirtualRobot::DifferentialIKPtr ik;
239  VirtualRobot::RobotNodePtr tcp;
240 
241  float torqueLimit;
242 
243  // Eigen::Vector3f kpos;
244  // Eigen::Vector3f kori;
245  // Eigen::Vector3f dpos;
246  // Eigen::Vector3f dori;
247  // Eigen::VectorXf knull;
248  // Eigen::VectorXf dnull;
249  int numOfJoints;
250 
251  std::atomic_bool useNullSpaceJointDMP;
252  bool isNullSpaceJointDMPLearned;
253 
254 
255  WriteBufferedTripleBuffer<Eigen::VectorXf> defaultNullSpaceJointValues;
256  std::vector<std::string> jointNames;
257  mutable MutexType controllerMutex;
259  std::atomic_bool firstRun;
260  std::atomic_bool started = false;
261  std::atomic_bool stopped = false;
262  std::atomic_bool prematurely_stopped = false;
263 
264  Eigen::Matrix4f stopPose;
265 
266  Eigen::Vector3f filteredForce;
267  Eigen::Vector3f forceOffset;
268  Eigen::Vector3f filteredForceInRoot;
269  WriteBufferedTripleBuffer<Eigen::Vector3f> forceThreshold;
270  std::atomic<bool> useForceStop;
271  std::atomic<float> timeForCalibration;
272  const SensorValueForceTorque* forceSensor;
273 
274  Eigen::Matrix4f oldPose;
275  // NJointController interface
276  protected:
278  };
279 
280 } // namespace armarx
281 
armarx::NJointTaskSpaceImpedanceDMPControllerInterface::getVirtualTime
double getVirtualTime()
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::disableForceStop
void disableForceStop(const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.h:108
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.h:67
armarx::NJointTaskSpaceImpedanceDMPControllerInterface::resumeDMP
void resumeDMP()
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::WriteBufferedTripleBuffer::commitWrite
void commitWrite()
Definition: TripleBuffer.h:326
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:507
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:6
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
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::NJointTaskSpaceImpedanceDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:517
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:499
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointTaskSpaceImpedanceDMPController.cpp:272
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::NJointTaskSpaceImpedanceDMPController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:779
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setAngularVelocityKp
void setAngularVelocityKp(const Eigen::Vector3f &kp, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:845
armarx::NJointTaskSpaceImpedanceDMPControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController
The NJointTaskSpaceImpedanceDMPController class.
Definition: NJointTaskSpaceImpedanceDMPController.h:50
armarx::NJointTaskSpaceImpedanceDMPControllerInterface::resetDMP
void resetDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPControllerControlData::desiredNullSpaceJointValues
Eigen::VectorXf desiredNullSpaceJointValues
Definition: NJointTaskSpaceImpedanceDMPController.h:39
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::runDMPWithTime
void runDMPWithTime(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:590
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::isDMPRunning
bool isDMPRunning(const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.h:72
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setForceThreshold
void setForceThreshold(const Eigen::Vector3f &f, const Ice::Current &current) override
Definition: NJointTaskSpaceImpedanceDMPController.h:113
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPControllerControlData
Definition: NJointTaskSpaceImpedanceDMPController.h:34
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::onInitNJointController
void onInitNJointController() override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:752
armarx::WriteBufferedTripleBuffer::getWriteBuffer
T & getWriteBuffer()
Definition: TripleBuffer.h:280
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPControllerControlData::targetPose
Eigen::Matrix4f targetPose
Definition: NJointTaskSpaceImpedanceDMPController.h:38
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setLinearVelocityKd
void setLinearVelocityKd(const Eigen::Vector3f &kd, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:812
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setAngularVelocityKd
void setAngularVelocityKd(const Eigen::Vector3f &kd, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:834
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::learnJointDMPFromFiles
void learnJointDMPFromFiles(const std::string &fileName, const Ice::FloatSeq &currentJVS, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:524
NJointController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setUseNullSpaceJointDMP
void setUseNullSpaceJointDMP(bool enable, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:584
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPControllerControlData::targetVel
Eigen::VectorXf targetVel
Definition: NJointTaskSpaceImpedanceDMPController.h:37
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:157
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::controllerRun
void controllerRun()
Definition: NJointTaskSpaceImpedanceDMPController.cpp:175
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::enableForceStop
void enableForceStop(const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.h:104
armarx::NJointControllerWithTripleBuffer< NJointTaskSpaceImpedanceDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setLinearVelocityKp
void setLinearVelocityKp(const Eigen::Vector3f &kp, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:823
armarx::NJointTaskSpaceImpedanceDMPControllerInterface::removeAllViaPoints
void removeAllViaPoints()
armarx::control::deprecated_njoint_mp_controller::task_space::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantController)
armarx::WriteBufferedTripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:773
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:601
armarx::NJointTaskSpaceImpedanceDMPControllerInterface
Definition: TaskSpaceImpedanceDMPControllerInterface.ice:71
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setNullspaceVelocityKd
void setNullspaceVelocityKd(const Eigen::VectorXf &kd, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:856
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setNullspaceVelocityKp
void setNullspaceVelocityKp(const Eigen::VectorXf &kp, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:867
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: NJointTaskSpaceImpedanceDMPController.cpp:163
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:645
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPControllerControlData::canVal
double canVal
Definition: NJointTaskSpaceImpedanceDMPController.h:40
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController
Brief description of class TaskSpaceDMPController.
Definition: TaskSpaceVMP.h:83
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::NJointTaskSpaceImpedanceDMPControllerInterface::stopDMP
void stopDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::setDefaultNullSpaceJointValues
void setDefaultNullSpaceJointValues(const Eigen::VectorXf &jointValues, const Ice::Current &) override
Definition: NJointTaskSpaceImpedanceDMPController.cpp:878
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPController::NJointTaskSpaceImpedanceDMPController
NJointTaskSpaceImpedanceDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointTaskSpaceImpedanceDMPController.cpp:26
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTaskSpaceImpedanceDMPControllerControlData::mpcFactor
double mpcFactor
Definition: NJointTaskSpaceImpedanceDMPController.h:41