NJointTaskSpaceAdaptiveDMPController.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 #include <dmp/representation/dmp/umidmp.h>
14 
15 // control
16 #include <armarx/control/deprecated_njoint_mp_controller/adaptive/ControllerInterface.h>
18 
19 
21 {
23 
24  TYPEDEF_PTRS_HANDLE(NJointTaskSpaceAdaptiveDMPController);
25  TYPEDEF_PTRS_HANDLE(NJointTaskSpaceAdaptiveDMPControllerControlData);
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 NJointTaskSpaceAdaptiveDMPController class
41  * @ingroup Library-RobotUnit-NJointControllers
42  */
44  public NJointControllerWithTripleBuffer<NJointTaskSpaceAdaptiveDMPControllerControlData>,
46  {
47  public:
48  using ConfigPtrT = NJointTaskSpaceAdaptiveDMPControllerConfigPtr;
49  NJointTaskSpaceAdaptiveDMPController(const RobotUnitPtr& robotUnit, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
50 
51  // NJointControllerInterface interface
52  std::string getClassName(const Ice::Current&) const;
53 
54  // NJointController interface
55 
56  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration);
57 
58  // NJointTaskSpaceAdaptiveDMPControllerInterface interface
59  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
60  bool isFinished(const Ice::Current&)
61  {
62  return finished;
63  }
64 
65  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&);
66  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
67 
68  void learnJointDMPFromFiles(const std::string& fileName, const Ice::FloatSeq& currentJVS, const Ice::Current&);
69  void runDMP(const Ice::DoubleSeq& goals, const Ice::Current&);
70  void runDMPWithTime(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&);
71 
72  Ice::Double getVirtualTime(const Ice::Current&)
73  {
74  return dmpCtrl->canVal;
75  }
76 
77  void stopDMP(const Ice::Current&);
78  void resumeDMP(const Ice::Current&);
79  void resetDMP(const Ice::Current&);
80 
81  void setKdImpedance(const Ice::FloatSeq& dampings, const Ice::Current&);
82  void setKpImpedance(const Ice::FloatSeq& stiffness, const Ice::Current&);
83 
84  void setKdNull(const Ice::FloatSeq& dnull, const Ice::Current&);
85  void setKpNull(const Ice::FloatSeq& knull, const Ice::Current&);
86  Ice::FloatSeq getForce(const Ice::Current&);
87  Ice::FloatSeq getVelocityInMM(const Ice::Current&);
88  void setCanVal(double canVal, const Ice::Current&);
89 
90  void removeAllViaPoints(const Ice::Current&);
91  void setUseNullSpaceJointDMP(bool useJointDMP, const Ice::Current&);
92  void setDefaultJointValues(const Ice::FloatSeq& desiredJointVals, const Ice::Current&);
93  protected:
95 
98  void controllerRun();
99 
100  private:
101  struct DebugBufferData
102  {
103  double currentCanVal;
104  double mpcfactor;
105  float targetPose_x;
106  float targetPose_y;
107  float targetPose_z;
108  float targetPose_qw;
109  float targetPose_qx;
110  float targetPose_qy;
111  float targetPose_qz;
112 
113  float currentPose_x;
114  float currentPose_y;
115  float currentPose_z;
116  float currentPose_qw;
117  float currentPose_qx;
118  float currentPose_qy;
119  float currentPose_qz;
120 
121  StringFloatDictionary desired_torques;
122  StringFloatDictionary desired_nullspaceJoint;
123  float forceDesired_x;
124  float forceDesired_y;
125  float forceDesired_z;
126  float forceDesired_rx;
127  float forceDesired_ry;
128  float forceDesired_rz;
129 
130  float impedanceKp_x;
131  float impedanceKp_y;
132  float impedanceKp_z;
133  float impedanceKp_rx;
134  float impedanceKp_ry;
135  float impedanceKp_rz;
136 
137  float forceInRoot_x;
138  float forceInRoot_y;
139  float forceInRoot_z;
140  // float torqueInRoot_x;
141  // float torqueInRoot_y;
142  // float torqueInRoot_z;
143 
144  float vel_x;
145  float vel_y;
146  float vel_z;
147 
148  float deltaT;
149 
150  };
151 
152  TripleBuffer<DebugBufferData> debugOutputData;
153 
154  struct NJointTaskSpaceAdaptiveDMPControllerSensorData
155  {
156  double currentTime;
157  double deltaT;
158  Eigen::Matrix4f currentPose;
159  Eigen::VectorXf currentTwist;
160  };
162 
163  struct NJointTaskSpaceAdaptiveDMPControllerInterfaceData
164  {
165  Eigen::Matrix4f currentTcpPose;
166  Eigen::VectorXf currentVel;
167  Eigen::Vector3f currentForce;
168 
169  };
170 
172 
173 
174  struct Inferface2rtData
175  {
176  Eigen::VectorXf KpImpedance;
177  Eigen::VectorXf KdImpedance;
178  Eigen::VectorXf Knull;
179  Eigen::VectorXf Dnull;
180  };
181  TripleBuffer<Inferface2rtData> interface2rtBuffer;
182 
183  struct Interface2CtrlData
184  {
185  double canVal;
186  };
187  TripleBuffer<Interface2CtrlData> interface2CtrlBuffer;
188 
189 
190  DMP::Vec<DMP::DMPState> currentJointState;
191  DMP::UMIDMPPtr nullSpaceJointDMPPtr;
192 
194 
195  std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors;
196  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
197  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
198  std::vector<ControlTarget1DoFActuatorTorque*> targets;
199 
200  // velocity ik controller parameters
201  // dmp parameters
202  double timeDuration;
203  bool finished;
204  VirtualRobot::RobotNodeSetPtr rns;
205 
206  // phaseStop parameters
207  double phaseL;
208  double phaseK;
209  double phaseDist0;
210  double phaseDist1;
211  double posToOriRatio;
212 
213 
214  NJointTaskSpaceAdaptiveDMPControllerConfigPtr cfg;
215  VirtualRobot::DifferentialIKPtr ik;
216  VirtualRobot::RobotNodePtr tcp;
217 
218  float torqueLimit;
219 
220  Eigen::Vector3f kpos;
221  Eigen::Vector3f kori;
222  Eigen::Vector3f dpos;
223  Eigen::Vector3f dori;
224  Eigen::VectorXf knull;
225  Eigen::VectorXf dnull;
226  int numOfJoints;
227 
228  bool useNullSpaceJointDMP;
229  bool isNullSpaceJointDMPLearned;
230 
231 
232  Eigen::VectorXf defaultNullSpaceJointValues;
233  std::vector<std::string> jointNames;
234  mutable MutexType controllerMutex;
236  bool firstRun;
237  bool started = false;
238  bool stopped = false;
239  Eigen::Vector3f forceOffset;
240 
241  Eigen::Matrix4f oldPose;
242  const SensorValueForceTorque* forceSensor;
243  Eigen::Vector3f filteredForce;
244 
245  mutable MutexType interfaceDataMutex;
246  mutable MutexType int2ctrlMutex;
247 
248  // NJointController interface
249  protected:
251  };
252 
253 } // namespace armarx
254 
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKdNull
void setKdNull(const Ice::FloatSeq &dnull, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:621
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKpImpedance
void setKpImpedance(const Ice::FloatSeq &stiffness, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:586
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:169
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:467
armarx::control::deprecated_njoint_mp_controller::adaptive::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointAdaptiveWipingController)
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:475
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::controllerRun
void controllerRun()
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:188
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:710
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::stopDMP
void stopDMP()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:176
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:681
SensorValueForceTorque.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:485
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::targetPose
Eigen::Matrix4f targetPose
Definition: NJointTaskSpaceAdaptiveDMPController.h:31
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::adaptive::NJointTaskSpaceAdaptiveDMPController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.h:60
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:521
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::adaptive
Definition: NJointAdaptiveWipingController.cpp:5
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::canVal
double canVal
Definition: NJointTaskSpaceAdaptiveDMPController.h:33
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::mpcFactor
double mpcFactor
Definition: NJointTaskSpaceAdaptiveDMPController.h:34
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:288
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:508
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::resumeDMP
void resumeDMP()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData
Definition: NJointTaskSpaceAdaptiveDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:849
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::desiredNullSpaceJointValues
Eigen::VectorXf desiredNullSpaceJointValues
Definition: NJointTaskSpaceAdaptiveDMPController.h:32
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::getVelocityInMM
Ice::FloatSeq getVelocityInMM()
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::onInitNJointController
void onInitNJointController()
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:828
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:568
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setKpNull
void setKpNull(const Ice::FloatSeq &knull, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:604
TaskSpaceVMP.h
CycleUtil.h
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPControllerControlData::targetVel
Eigen::VectorXf targetVel
Definition: NJointTaskSpaceAdaptiveDMPController.h:30
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::NJointControllerWithTripleBuffer< NJointTaskSpaceAdaptiveDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
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:492
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::NJointTaskSpaceAdaptiveDMPController
NJointTaskSpaceAdaptiveDMPController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:11
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::setUseNullSpaceJointDMP
void setUseNullSpaceJointDMP(bool useJointDMP, const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:500
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointTaskSpaceAdaptiveDMPController.cpp:735
armarx::NJointTaskSpaceAdaptiveDMPControllerInterface::removeAllViaPoints
void removeAllViaPoints()
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController::getVirtualTime
Ice::Double getVirtualTime(const Ice::Current &)
Definition: NJointTaskSpaceAdaptiveDMPController.h:72
armarx::control::deprecated_njoint_mp_controller::adaptive::NJointTaskSpaceAdaptiveDMPController
The NJointTaskSpaceAdaptiveDMPController class.
Definition: NJointTaskSpaceAdaptiveDMPController.h:43