NJointPeriodicTSDMPCompliantController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/Robot.h>
5 #include <VirtualRobot/IK/DifferentialIK.h>
6 #include <VirtualRobot/Manipulability/SingleChainManipulability.h>
7 #include <VirtualRobot/Manipulability/SingleChainManipulabilityTracking.h>
8 
10 
18 
19 // control
20 #include <armarx/control/deprecated_njoint_mp_controller/task_space/ControllerInterface.h>
22 
23 
25 {
27 
28  TYPEDEF_PTRS_HANDLE(NJointPeriodicTSDMPCompliantController);
29  TYPEDEF_PTRS_HANDLE(NJointPeriodicTSDMPCompliantControllerControlData);
30 
32  {
33  public:
34  Eigen::VectorXf targetTSVel;
35  };
36 
37  /**
38  * @brief The NJointPeriodicTSDMPCompliantController class
39  * @ingroup Library-RobotUnit-NJointControllers
40  */
42  public NJointControllerWithTripleBuffer<NJointPeriodicTSDMPCompliantControllerControlData>,
44  {
45  public:
46  using ConfigPtrT = NJointPeriodicTSDMPCompliantControllerConfigPtr;
47  NJointPeriodicTSDMPCompliantController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
48 
49  // NJointControllerInterface interface
50  std::string getClassName(const Ice::Current&) const;
51 
52  // NJointController interface
53 
54  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration);
55 
56  // NJointPeriodicTSDMPCompliantControllerInterface interface
57  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
58  void learnDMPFromTrajectory(const TrajectoryBasePtr& trajectory, const Ice::Current&);
59  bool isFinished(const Ice::Current&)
60  {
61  return false;
62  }
63 
64  void setSpeed(Ice::Double times, const Ice::Current&);
65  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
66  void setAmplitude(Ice::Double amp, const Ice::Current&);
67  void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
68  void setTargetForceInRootFrame(Ice::Float force, const Ice::Current&);
69  double getCanVal(const Ice::Current&)
70  {
71  return dmpCtrl->canVal;
72  }
73 
74  protected:
76 
79  void controllerRun();
80 
81  private:
82  struct DebugBufferData
83  {
84  StringFloatDictionary latestTargetVelocities;
85  StringFloatDictionary currentPose;
86  double currentCanVal;
87  double mpcFactor;
88  double error;
89  double phaseStop;
90  double posError;
91  double oriError;
92  double deltaT;
93  };
94 
95  TripleBuffer<DebugBufferData> debugOutputData;
96 
97 
98  struct DebugRTData
99  {
100  Eigen::Matrix4f targetPose;
101  Eigen::Vector3f filteredForce;
102  Eigen::Vector3f reactForce;
103  Eigen::Vector3f adaptK;
104  Eigen::VectorXf targetVel;
105  Eigen::Matrix4f currentPose;
106  Eigen::VectorXf currentTwist;
107  bool isPhaseStop;
108  float manidist;
109  };
111 
112  struct RTToControllerData
113  {
114  double currentTime;
115  double deltaT;
116  Eigen::Matrix4f currentPose;
117  Eigen::VectorXf currentTwist;
118  bool isPhaseStop;
119  };
121 
122  struct RTToUserData
123  {
124  Eigen::Matrix4f currentTcpPose;
125  float waitTimeForCalibration;
126  };
127  TripleBuffer<RTToUserData> rt2UserData;
128 
129  struct UserToRTData
130  {
131  float targetForce;
132  };
133  TripleBuffer<UserToRTData> user2rtData;
134 
135 
137 
138  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
139  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
140  std::vector<ControlTarget1DoFActuatorTorque*> targets;
141 
142  // velocity ik controller parameters
143  std::string nodeSetName;
144 
145  bool started;
146  bool firstRun;
147  bool dmpRunning;
148 
149  VirtualRobot::DifferentialIKPtr ik;
150  VirtualRobot::RobotNodePtr tcp;
151 
152  NJointPeriodicTSDMPCompliantControllerConfigPtr cfg;
153  mutable MutexType controllerMutex;
155  Eigen::Matrix4f targetPose;
156 
157  Eigen::Vector3f kpos;
158  Eigen::Vector3f dpos;
159  Eigen::Vector3f kori;
160  Eigen::Vector3f dori;
161  float knull;
162  float dnull;
163  float kpf;
164 
165  Eigen::VectorXf nullSpaceJointsVec;
166  const SensorValueForceTorque* forceSensor;
167 
168  Eigen::Vector3f filteredForce;
169  Eigen::Vector3f forceOffset;
170  Eigen::Vector3f filteredForceInRoot;
171 
172  Eigen::Matrix3f toolTransform;
173  Eigen::Vector3f oriToolDir;
174  Eigen::Matrix3f origHandOri;
175  Eigen::VectorXf qvel_filtered;
176 
177  Eigen::Vector3f adaptK;
178  float lastDiff;
179  Eigen::Vector2f lastPosition;
180  double changeTimer;
181 
182 
183 
184  bool isManipulability = false;
185  VirtualRobot::SingleChainManipulabilityTrackingPtr manipulabilityTracker;
186  Eigen::MatrixXd targetManipulability;
187  Eigen::MatrixXd kmani;
188 
189  };
190 
191 } // namespace armarx
192 
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::learnDMPFromTrajectory
void learnDMPFromTrajectory(const TrajectoryBasePtr &trajectory, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:587
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointPeriodicTSDMPCompliantController.cpp:214
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantControllerControlData::targetTSVel
Eigen::VectorXf targetTSVel
Definition: NJointPeriodicTSDMPCompliantController.h:34
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::NJointPeriodicTSDMPCompliantController
NJointPeriodicTSDMPCompliantController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:9
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:6
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::onInitNJointController
void onInitNJointController()
Definition: NJointPeriodicTSDMPCompliantController.cpp:169
SensorValueForceTorque.h
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantControllerControlData
Definition: NJointPeriodicTSDMPCompliantController.h:31
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::NJointPeriodicTSDMPCompliantControllerInterface
Definition: ControllerInterface.ice:286
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointPeriodicTSDMPCompliantController.cpp:731
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
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::NJointPeriodicTSDMPCompliantController
The NJointPeriodicTSDMPCompliantController class.
Definition: NJointPeriodicTSDMPCompliantController.h:41
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::getCanVal
double getCanVal(const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.h:69
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::controllerRun
void controllerRun()
Definition: NJointPeriodicTSDMPCompliantController.cpp:219
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:578
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:599
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
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:625
CartesianVelocityController.h
CycleUtil.h
NJointController.h
Trajectory.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::NJointControllerWithTripleBuffer< NJointPeriodicTSDMPCompliantControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
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:612
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:646
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setTargetForceInRootFrame
void setTargetForceInRootFrame(Ice::Float force, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:618
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.h:59
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::task_space::NJointPeriodicTSDMPCompliantController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointPeriodicTSDMPCompliantController.cpp:606
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:279