NJointPeriodicTSDMPCompliantController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/VirtualRobot.h>
5 
8 
10 
11 // control
13 #include <armarx/control/deprecated_njoint_mp_controller/task_space/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 VirtualRobot
25 {
27  std::shared_ptr<class SingleChainManipulabilityTracking>;
28 }
29 
31 {
33 
34  TYPEDEF_PTRS_HANDLE(NJointPeriodicTSDMPCompliantController);
35  TYPEDEF_PTRS_HANDLE(NJointPeriodicTSDMPCompliantControllerControlData);
36 
38  {
39  public:
40  Eigen::VectorXf targetTSVel;
41  };
42 
43  /**
44  * @brief The NJointPeriodicTSDMPCompliantController class
45  * @ingroup Library-RobotUnit-NJointControllers
46  */
48  public NJointControllerWithTripleBuffer<NJointPeriodicTSDMPCompliantControllerControlData>,
50  {
51  public:
52  using ConfigPtrT = NJointPeriodicTSDMPCompliantControllerConfigPtr;
54  const NJointControllerConfigPtr& config,
55  const VirtualRobot::RobotPtr&);
56 
57  // NJointControllerInterface interface
58  std::string getClassName(const Ice::Current&) const;
59 
60  // NJointController interface
61 
62  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
63  const IceUtil::Time& timeSinceLastIteration);
64 
65  // NJointPeriodicTSDMPCompliantControllerInterface interface
66  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
67  void learnDMPFromTrajectory(const TrajectoryBasePtr& trajectory, const Ice::Current&);
68 
69  bool
70  isFinished(const Ice::Current&)
71  {
72  return false;
73  }
74 
75  void setSpeed(Ice::Double times, const Ice::Current&);
76  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
77  void setAmplitude(Ice::Double amp, const Ice::Current&);
78  void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
79  void setTargetForceInRootFrame(Ice::Float force, const Ice::Current&);
80 
81  double
82  getCanVal(const Ice::Current&)
83  {
84  return dmpCtrl->canVal;
85  }
86 
87  protected:
88  virtual void onPublish(const SensorAndControl&,
91 
94  void controllerRun();
95 
96  private:
97  struct DebugBufferData
98  {
99  StringFloatDictionary latestTargetVelocities;
100  StringFloatDictionary currentPose;
101  double currentCanVal;
102  double mpcFactor;
103  double error;
104  double phaseStop;
105  double posError;
106  double oriError;
107  double deltaT;
108  };
109 
110  TripleBuffer<DebugBufferData> debugOutputData;
111 
112  struct DebugRTData
113  {
114  Eigen::Matrix4f targetPose;
115  Eigen::Vector3f filteredForce;
116  Eigen::Vector3f reactForce;
117  Eigen::Vector3f adaptK;
118  Eigen::VectorXf targetVel;
119  Eigen::Matrix4f currentPose;
120  Eigen::VectorXf currentTwist;
121  bool isPhaseStop;
122  float manidist;
123  };
124 
126 
127  struct RTToControllerData
128  {
129  double currentTime;
130  double deltaT;
131  Eigen::Matrix4f currentPose;
132  Eigen::VectorXf currentTwist;
133  bool isPhaseStop;
134  };
135 
137 
138  struct RTToUserData
139  {
140  Eigen::Matrix4f currentTcpPose;
141  float waitTimeForCalibration;
142  };
143 
144  TripleBuffer<RTToUserData> rt2UserData;
145 
146  struct UserToRTData
147  {
148  float targetForce;
149  };
150 
151  TripleBuffer<UserToRTData> user2rtData;
152 
153 
155 
156  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
157  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
158  std::vector<ControlTarget1DoFActuatorTorque*> targets;
159 
160  // velocity ik controller parameters
161  std::string nodeSetName;
162 
163  bool started;
164  bool firstRun;
165  bool dmpRunning;
166 
167  VirtualRobot::DifferentialIKPtr ik;
168  VirtualRobot::RobotNodePtr tcp;
169 
170  NJointPeriodicTSDMPCompliantControllerConfigPtr cfg;
171  mutable MutexType controllerMutex;
173  Eigen::Matrix4f targetPose;
174 
175  Eigen::Vector3f kpos;
176  Eigen::Vector3f dpos;
177  Eigen::Vector3f kori;
178  Eigen::Vector3f dori;
179  float knull;
180  float dnull;
181  float kpf;
182 
183  Eigen::VectorXf nullSpaceJointsVec;
184  const SensorValueForceTorque* forceSensor;
185 
186  Eigen::Vector3f filteredForce;
187  Eigen::Vector3f forceOffset;
188  Eigen::Vector3f filteredForceInRoot;
189 
190  Eigen::Matrix3f toolTransform;
191  Eigen::Vector3f oriToolDir;
192  Eigen::Matrix3f origHandOri;
193  Eigen::VectorXf qvel_filtered;
194 
195  Eigen::Vector3f adaptK;
196  float lastDiff;
197  Eigen::Vector2f lastPosition;
198  double changeTimer;
199 
200 
201  bool isManipulability = false;
203  Eigen::MatrixXd targetManipulability;
204  Eigen::MatrixXd kmani;
205  };
206 
207 } // namespace armarx::control::deprecated_njoint_mp_controller::task_space
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
NJointControllerWithTripleBuffer.h
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::learnDMPFromTrajectory
void learnDMPFromTrajectory(const TrajectoryBasePtr &trajectory, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:627
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointPeriodicTSDMPCompliantController.cpp:245
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantControllerControlData::targetTSVel
Eigen::VectorXf targetTSVel
Definition: NJointPeriodicTSDMPCompliantController.h:40
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
VirtualRobot
Definition: FramedPose.h:42
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::NJointPeriodicTSDMPCompliantController
NJointPeriodicTSDMPCompliantController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:28
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:20
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::onInitNJointController
void onInitNJointController()
Definition: NJointPeriodicTSDMPCompliantController.cpp:199
PeriodicTask.h
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantControllerControlData
Definition: NJointPeriodicTSDMPCompliantController.h:37
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::NJointPeriodicTSDMPCompliantControllerInterface
Definition: ControllerInterface.ice:281
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointPeriodicTSDMPCompliantController.cpp:782
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:68
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController
The NJointPeriodicTSDMPCompliantController class.
Definition: NJointPeriodicTSDMPCompliantController.h:47
VirtualRobot::SingleChainManipulabilityTrackingPtr
std::shared_ptr< class SingleChainManipulabilityTracking > SingleChainManipulabilityTrackingPtr
Definition: NJointPeriodicTSDMPCompliantController.h:27
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::getCanVal
double getCanVal(const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.h:82
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::controllerRun
void controllerRun()
Definition: NJointPeriodicTSDMPCompliantController.cpp:251
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:617
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:641
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double tau, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:672
CycleUtil.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:31
armarx::NJointControllerWithTripleBuffer< NJointPeriodicTSDMPCompliantControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
IceUtil::Handle< class RobotUnit >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::task_space::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(DeprecatedNJointPeriodicTSDMPCompliantController)
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setAmplitude
void setAmplitude(Ice::Double amp, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:656
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:696
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setTargetForceInRootFrame
void setTargetForceInRootFrame(Ice::Float force, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:663
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.h:70
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::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:648
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointPeriodicTSDMPCompliantController.cpp:312