DeprecatedNJointTaskSpaceImpedanceDMPController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/Robot.h>
5 #include <VirtualRobot/IK/DifferentialIK.h>
7 
13 
14 #include <dmp/representation/dmp/umidmp.h>
15 
16 #include <armarx/control/deprecated_njoint_mp_controller/task_space/ControllerInterface.h>
18 
19 
21 {
23 
24  TYPEDEF_PTRS_HANDLE(DeprecatedNJointTaskSpaceImpedanceDMPController);
25  TYPEDEF_PTRS_HANDLE(DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData);
26 
28  {
29  public:
30  Eigen::VectorXf targetVel;
32  Eigen::VectorXf desiredNullSpaceJointValues;
33  double canVal;
34  double mpcFactor;
35  };
36 
37 
38 
39  /**
40  * @brief The DeprecatedNJointTaskSpaceImpedanceDMPController class
41  * @ingroup Library-RobotUnit-NJointControllers
42  */
44  public NJointControllerWithTripleBuffer<DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData>,
46  {
47  public:
48  using ConfigPtrT = DeprecatedNJointTaskSpaceImpedanceDMPControllerConfigPtr;
49  DeprecatedNJointTaskSpaceImpedanceDMPController(const RobotUnitPtr& robotUnit, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
50 
51  // NJointControllerInterface interface
52  std::string getClassName(const Ice::Current&) const override;
53 
54  // NJointController interface
55 
56  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override;
57 
58  // DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface interface
59  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&) override;
60  bool isFinished(const Ice::Current&) override
61  {
62  return finished;
63  }
64 
65  bool isDMPRunning(const Ice::Current&) override
66  {
67  return started;
68  }
69 
70  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&) override;
71  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
72 
73  void learnJointDMPFromFiles(const std::string& fileName, const Ice::FloatSeq& currentJVS, const Ice::Current&) override;
74  void runDMP(const Ice::DoubleSeq& goals, const Ice::Current& iceCurrent = Ice::emptyCurrent) override;
75  void runDMPWithTime(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&) override;
76 
77  Ice::Double getVirtualTime(const Ice::Current&) override
78  {
79  return dmpCtrl->canVal;
80  }
81 
82  void stopDMP(const Ice::Current&) override;
83  void resumeDMP(const Ice::Current&) override;
84  void resetDMP(const Ice::Current&) override;
85 
86  void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&) override;
87  DoubleSeqSeq getMPWeights(const Ice::Current&) override;
88 
89  void removeAllViaPoints(const Ice::Current&) override;
90 
91  void setLinearVelocityKd(const Eigen::Vector3f& kd, const Ice::Current&) override;
92  void setLinearVelocityKp(const Eigen::Vector3f& kp, const Ice::Current&) override;
93  void setAngularVelocityKd(const Eigen::Vector3f& kd, const Ice::Current&) override;
94  void setAngularVelocityKp(const Eigen::Vector3f& kp, const Ice::Current&) override;
95  void setNullspaceVelocityKd(const Eigen::VectorXf& kd, const Ice::Current&) override;
96  void setNullspaceVelocityKp(const Eigen::VectorXf& kp, const Ice::Current&) override;
97  void setUseNullSpaceJointDMP(bool enable, const Ice::Current&) override;
98  void setDefaultNullSpaceJointValues(const Eigen::VectorXf& jointValues, const Ice::Current&) override;
99 
100  void enableForceStop(const Ice::Current&) override
101  {
102  useForceStop = true;
103  }
104  void disableForceStop(const Ice::Current&) override
105  {
106  useForceStop = false;
107  }
108 
109  void setForceThreshold(const Eigen::Vector3f& f, const Ice::Current& current) override
110  {
111  forceThreshold.getWriteBuffer() = f;
112  forceThreshold.commitWrite();
113  }
114  std::string getDMPAsString(const Ice::Current&) override;
115  Ice::DoubleSeq createDMPFromString(const std::string&, const Ice::Current&) override;
116  Ice::Double getCanVal(const Ice::Current&);
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  Eigen::Vector3f filteredForceInRoot;
176 
177  float deltaT;
178 
179 
180 
181  };
182 
184 
185  struct DeprecatedNJointTaskSpaceImpedanceDMPControllerSensorData
186  {
187  double currentTime;
188  double deltaT;
189  Eigen::Matrix4f currentPose;
190  Eigen::VectorXf currentTwist;
191  };
193 
194  struct DeprecatedNJointTaskSpaceImpedanceDMPControllerInterfaceData
195  {
196  Eigen::Matrix4f currentTcpPose;
197  };
198 
200 
201  struct CtrlParams
202  {
203  Eigen::Vector3f kpos;
204  Eigen::Vector3f dpos;
205  Eigen::Vector3f kori;
206  Eigen::Vector3f dori;
207  Eigen::VectorXf knull;
208  Eigen::VectorXf dnull;
209  };
210 
211  WriteBufferedTripleBuffer<CtrlParams> ctrlParams;
212 
213 
214 
215  DMP::Vec<DMP::DMPState> currentJointState;
216  DMP::UMIDMPPtr nullSpaceJointDMPPtr;
217 
219 
220  std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors;
221  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
222  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
223  std::vector<ControlTarget1DoFActuatorTorque*> targets;
224 
225  // velocity ik controller parameters
226  // dmp parameters
227  double timeDuration;
228  bool finished;
229  VirtualRobot::RobotNodeSetPtr rns;
230 
231  // phaseStop parameters
232  double phaseL;
233  double phaseK;
234  double phaseDist0;
235  double phaseDist1;
236  double posToOriRatio;
237 
238 
239  DeprecatedNJointTaskSpaceImpedanceDMPControllerConfigPtr cfg;
240  VirtualRobot::DifferentialIKPtr ik;
241  VirtualRobot::RobotNodePtr tcp;
242 
243  float torqueLimit;
244 
245  // Eigen::Vector3f kpos;
246  // Eigen::Vector3f kori;
247  // Eigen::Vector3f dpos;
248  // Eigen::Vector3f dori;
249  // Eigen::VectorXf knull;
250  // Eigen::VectorXf dnull;
251  int numOfJoints;
252 
253  std::atomic_bool useNullSpaceJointDMP;
254  bool isNullSpaceJointDMPLearned;
255 
256 
257  WriteBufferedTripleBuffer<Eigen::VectorXf> defaultNullSpaceJointValues;
258  std::vector<std::string> jointNames;
259  mutable MutexType controllerMutex;
261  bool firstRun;
262  bool started = false;
263  bool stopped = false;
264 
265  Eigen::Matrix4f stopPose;
266 
267  Eigen::Vector3f filteredForce;
268  Eigen::Vector3f forceOffset;
269  Eigen::Vector3f filteredForceInRoot;
270  WriteBufferedTripleBuffer<Eigen::Vector3f> forceThreshold;
271  std::atomic<bool> useForceStop;
272  std::atomic<float> timeForCalibration;
273  const SensorValueForceTorque* forceSensor;
274 
275  // Eigen::Matrix4f oldPose;
276  // NJointController interface
277  protected:
279  };
280 
281 } // namespace armarx
282 
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::stopDMP
void stopDMP()
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::getCanVal
double getCanVal()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData::desiredNullSpaceJointValues
Eigen::VectorXf desiredNullSpaceJointValues
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:32
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:482
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::DeprecatedNJointTaskSpaceImpedanceDMPController
DeprecatedNJointTaskSpaceImpedanceDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:13
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:709
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::createDMPFromString
Ice::DoubleSeq createDMPFromString(const std::string &, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:546
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::resumeDMP
void resumeDMP()
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:577
armarx::WriteBufferedTripleBuffer::commitWrite
void commitWrite()
Definition: TripleBuffer.h:326
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::runDMPWithTime
void runDMPWithTime(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:568
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:144
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::getVirtualTime
Ice::Double getVirtualTime(const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:77
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:6
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::isDMPRunning
bool isDMPRunning(const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:65
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:473
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface
Definition: ControllerInterface.ice:428
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setUseNullSpaceJointDMP
void setUseNullSpaceJointDMP(bool enable, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:562
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData::targetVel
Eigen::VectorXf targetVel
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:30
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setNullspaceVelocityKp
void setNullspaceVelocityKp(const Eigen::VectorXf &kp, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:786
SensorValueForceTorque.h
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:704
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::resetDMP
void resetDMP()
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::DeprecatedNJointTaskSpaceImpedanceDMPController::setAngularVelocityKd
void setAngularVelocityKd(const Eigen::Vector3f &kd, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:757
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setLinearVelocityKp
void setLinearVelocityKp(const Eigen::Vector3f &kp, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:748
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::isFinished
bool isFinished(const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:60
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData::mpcFactor
double mpcFactor
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:34
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::disableForceStop
void disableForceStop(const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:104
ControlTarget1DoFActuator.h
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::removeAllViaPoints
void removeAllViaPoints()
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::DeprecatedNJointTaskSpaceImpedanceDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:250
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::learnJointDMPFromFiles
void learnJointDMPFromFiles(const std::string &fileName, const Ice::FloatSeq &currentJVS, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:488
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
CycleUtil.h
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setForceThreshold
void setForceThreshold(const Eigen::Vector3f &f, const Ice::Current &current) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:109
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::DeprecatedNJointTaskSpaceImpedanceDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:614
armarx::NJointControllerWithTripleBuffer< DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setLinearVelocityKd
void setLinearVelocityKd(const Eigen::Vector3f &kd, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:738
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::onInitNJointController
void onInitNJointController() override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:685
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController
The DeprecatedNJointTaskSpaceImpedanceDMPController class.
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:43
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
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::DeprecatedNJointTaskSpaceImpedanceDMPController::setDefaultNullSpaceJointValues
void setDefaultNullSpaceJointValues(const Eigen::VectorXf &jointValues, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:796
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:467
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::controllerRun
void controllerRun()
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:158
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData::targetPose
Eigen::Matrix4f targetPose
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:31
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setAngularVelocityKp
void setAngularVelocityKp(const Eigen::Vector3f &kp, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:766
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::enableForceStop
void enableForceStop(const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:100
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::setNullspaceVelocityKd
void setNullspaceVelocityKd(const Eigen::VectorXf &kd, const Ice::Current &) override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:777
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPControllerControlData::canVal
double canVal
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.h:33
armarx::DeprecatedNJointTaskSpaceImpedanceDMPControllerInterface::getDMPAsString
string getDMPAsString()
armarx::control::deprecated_njoint_mp_controller::task_space::DeprecatedNJointTaskSpaceImpedanceDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: DeprecatedNJointTaskSpaceImpedanceDMPController.cpp:137
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18