NJointTaskSpaceAdaptiveDMPController.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/adaptive/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 
24 namespace DMP
25 {
26  // using UMITSMPPtr = boost::shared_ptr<class UMITSMP>;
28 } // namespace DMP
29 
31 {
33 
34  TYPEDEF_PTRS_HANDLE(NJointTaskSpaceAdaptiveDMPController);
35  TYPEDEF_PTRS_HANDLE(NJointTaskSpaceAdaptiveDMPControllerControlData);
36 
38  {
39  public:
40  Eigen::VectorXf targetVel;
42  Eigen::VectorXf desiredNullSpaceJointValues;
43  double canVal;
44  double mpcFactor;
45  };
46 
47  /**
48  * @brief The NJointTaskSpaceAdaptiveDMPController class
49  * @ingroup Library-RobotUnit-NJointControllers
50  */
52  public NJointControllerWithTripleBuffer<NJointTaskSpaceAdaptiveDMPControllerControlData>,
54  {
55  public:
56  using ConfigPtrT = NJointTaskSpaceAdaptiveDMPControllerConfigPtr;
58  const NJointControllerConfigPtr& config,
59  const VirtualRobot::RobotPtr&);
60 
61  // NJointControllerInterface interface
62  std::string getClassName(const Ice::Current&) const;
63 
64  // NJointController interface
65 
66  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
67  const IceUtil::Time& timeSinceLastIteration);
68 
69  // NJointTaskSpaceAdaptiveDMPControllerInterface interface
70  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
71 
72  bool
73  isFinished(const Ice::Current&)
74  {
75  return finished;
76  }
77 
78  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&);
79  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
80 
81  void learnJointDMPFromFiles(const std::string& fileName,
82  const Ice::FloatSeq& currentJVS,
83  const Ice::Current&);
84  void runDMP(const Ice::DoubleSeq& goals, const Ice::Current&);
85  void
86  runDMPWithTime(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&);
87 
89  getVirtualTime(const Ice::Current&)
90  {
91  return dmpCtrl->canVal;
92  }
93 
94  void stopDMP(const Ice::Current&);
95  void resumeDMP(const Ice::Current&);
96  void resetDMP(const Ice::Current&);
97 
98  void setKdImpedance(const Ice::FloatSeq& dampings, const Ice::Current&);
99  void setKpImpedance(const Ice::FloatSeq& stiffness, const Ice::Current&);
100 
101  void setKdNull(const Ice::FloatSeq& dnull, const Ice::Current&);
102  void setKpNull(const Ice::FloatSeq& knull, const Ice::Current&);
103  Ice::FloatSeq getForce(const Ice::Current&);
104  Ice::FloatSeq getVelocityInMM(const Ice::Current&);
105  void setCanVal(double canVal, const Ice::Current&);
106 
107  void removeAllViaPoints(const Ice::Current&);
108  void setUseNullSpaceJointDMP(bool useJointDMP, const Ice::Current&);
109  void setDefaultJointValues(const Ice::FloatSeq& desiredJointVals, const Ice::Current&);
110 
111  protected:
112  virtual void onPublish(const SensorAndControl&,
115 
116  void onInitNJointController();
118  void controllerRun();
119 
120  private:
121  struct DebugBufferData
122  {
123  double currentCanVal;
124  double mpcfactor;
125  float targetPose_x;
126  float targetPose_y;
127  float targetPose_z;
128  float targetPose_qw;
129  float targetPose_qx;
130  float targetPose_qy;
131  float targetPose_qz;
132 
133  float currentPose_x;
134  float currentPose_y;
135  float currentPose_z;
136  float currentPose_qw;
137  float currentPose_qx;
138  float currentPose_qy;
139  float currentPose_qz;
140 
141  StringFloatDictionary desired_torques;
142  StringFloatDictionary desired_nullspaceJoint;
143  float forceDesired_x;
144  float forceDesired_y;
145  float forceDesired_z;
146  float forceDesired_rx;
147  float forceDesired_ry;
148  float forceDesired_rz;
149 
150  float impedanceKp_x;
151  float impedanceKp_y;
152  float impedanceKp_z;
153  float impedanceKp_rx;
154  float impedanceKp_ry;
155  float impedanceKp_rz;
156 
157  float forceInRoot_x;
158  float forceInRoot_y;
159  float forceInRoot_z;
160  // float torqueInRoot_x;
161  // float torqueInRoot_y;
162  // float torqueInRoot_z;
163 
164  float vel_x;
165  float vel_y;
166  float vel_z;
167 
168  float deltaT;
169  };
170 
171  TripleBuffer<DebugBufferData> debugOutputData;
172 
173  struct NJointTaskSpaceAdaptiveDMPControllerSensorData
174  {
175  double currentTime;
176  double deltaT;
177  Eigen::Matrix4f currentPose;
178  Eigen::VectorXf currentTwist;
179  };
180 
182 
183  struct NJointTaskSpaceAdaptiveDMPControllerInterfaceData
184  {
185  Eigen::Matrix4f currentTcpPose;
186  Eigen::VectorXf currentVel;
187  Eigen::Vector3f currentForce;
188  };
189 
191 
192  struct Inferface2rtData
193  {
194  Eigen::VectorXf KpImpedance;
195  Eigen::VectorXf KdImpedance;
196  Eigen::VectorXf Knull;
197  Eigen::VectorXf Dnull;
198  };
199 
200  TripleBuffer<Inferface2rtData> interface2rtBuffer;
201 
202  struct Interface2CtrlData
203  {
204  double canVal;
205  };
206 
207  TripleBuffer<Interface2CtrlData> interface2CtrlBuffer;
208 
209 
210  DMP::Vec<DMP::DMPState> currentJointState;
211  DMP::UMIDMPPtr nullSpaceJointDMPPtr;
212 
214 
215  std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors;
216  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
217  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
218  std::vector<ControlTarget1DoFActuatorTorque*> targets;
219 
220  // velocity ik controller parameters
221  // dmp parameters
222  double timeDuration;
223  bool finished;
224  VirtualRobot::RobotNodeSetPtr rns;
225 
226  // phaseStop parameters
227  double phaseL;
228  double phaseK;
229  double phaseDist0;
230  double phaseDist1;
231  double posToOriRatio;
232 
233 
234  NJointTaskSpaceAdaptiveDMPControllerConfigPtr cfg;
235  VirtualRobot::DifferentialIKPtr ik;
236  VirtualRobot::RobotNodePtr tcp;
237 
238  float torqueLimit;
239 
240  Eigen::Vector3f kpos;
241  Eigen::Vector3f kori;
242  Eigen::Vector3f dpos;
243  Eigen::Vector3f dori;
244  Eigen::VectorXf knull;
245  Eigen::VectorXf dnull;
246  int numOfJoints;
247 
248  bool useNullSpaceJointDMP;
249  bool isNullSpaceJointDMPLearned;
250 
251 
252  Eigen::VectorXf defaultNullSpaceJointValues;
253  std::vector<std::string> jointNames;
254  mutable MutexType controllerMutex;
256  bool firstRun;
257  bool started = false;
258  bool stopped = false;
259  Eigen::Vector3f forceOffset;
260 
261  Eigen::Matrix4f oldPose;
262  const SensorValueForceTorque* forceSensor;
263  Eigen::Vector3f filteredForce;
264 
265  mutable MutexType interfaceDataMutex;
266  mutable MutexType int2ctrlMutex;
267 
268  // NJointController interface
269  protected:
271  };
272 
273 } // namespace armarx::control::deprecated_njoint_mp_controller::adaptive
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKdNull
void setKdNull(const Ice::FloatSeq &dnull, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:634
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKpImpedance
void setKpImpedance(const Ice::FloatSeq &stiffness, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:599
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:187
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:482
armarx::control::deprecated_njoint_mp_controller::adaptive::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingController)
NJointControllerWithTripleBuffer.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:490
boost::shared_ptr< class UMIDMP >
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::controllerRun
void controllerRun()
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:204
DMP
Definition: NJointTaskSpaceAdaptiveDMPController.h:24
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:721
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::stopDMP
void stopDMP()
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:193
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::resetDMP
void resetDMP()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::runDMPWithTime
void runDMPWithTime(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:692
PeriodicTask.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:500
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::targetPose
Eigen::Matrix4f targetPose
Definition: NJointTaskSpaceAdaptiveDMPController.h:41
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::adaptive::NJointTaskSpaceAdaptiveDMPController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.h:73
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::learnJointDMPFromFiles
void learnJointDMPFromFiles(const std::string &fileName, const Ice::FloatSeq &currentJVS, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:535
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::adaptive
Definition: NJointAdaptiveWipingController.cpp:21
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::canVal
double canVal
Definition: NJointTaskSpaceAdaptiveDMPController.h:43
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::mpcFactor
double mpcFactor
Definition: NJointTaskSpaceAdaptiveDMPController.h:44
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:304
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface
Definition: ControllerInterface.ice:57
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setDefaultJointValues
void setDefaultJointValues(const Ice::FloatSeq &desiredJointVals, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:522
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::resumeDMP
void resumeDMP()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData
Definition: NJointTaskSpaceAdaptiveDMPController.h:37
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:859
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::desiredNullSpaceJointValues
Eigen::VectorXf desiredNullSpaceJointValues
Definition: NJointTaskSpaceAdaptiveDMPController.h:42
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::getVelocityInMM
Ice::FloatSeq getVelocityInMM()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::onInitNJointController
void onInitNJointController()
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:838
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKdImpedance
void setKdImpedance(const Ice::FloatSeq &dampings, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:581
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKpNull
void setKpNull(const Ice::FloatSeq &knull, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:617
TaskSpaceVMP.h
CycleUtil.h
PIDController.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::targetVel
Eigen::VectorXf targetVel
Definition: NJointTaskSpaceAdaptiveDMPController.h:40
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:31
armarx::NJointControllerWithTripleBuffer< NJointTaskSpaceAdaptiveDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
IceUtil::Handle< class RobotUnit >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::getForce
Ice::FloatSeq getForce()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setCanVal
void setCanVal(double canVal, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:507
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::NJointTaskSpaceAdaptiveDMPController
NJointTaskSpaceAdaptiveDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:28
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setUseNullSpaceJointDMP
void setUseNullSpaceJointDMP(bool useJointDMP, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:515
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:745
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::removeAllViaPoints
void removeAllViaPoints()
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::getVirtualTime
Ice::Double getVirtualTime(const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.h:89
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController
The NJointTaskSpaceAdaptiveDMPController class.
Definition: NJointTaskSpaceAdaptiveDMPController.h:51