NJointBimanualCCDMPVelocityController.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <VirtualRobot/VirtualRobot.h>
4 
7 
11 
13 #include <armarx/control/deprecated_njoint_mp_controller/bimanual/ControllerInterface.h>
14 
15 namespace armarx
16 {
17  class SensorValue1DoFActuatorTorque;
18  class SensorValue1DoFActuatorVelocity;
19  class SensorValue1DoFActuatorPosition;
20  class SensorValue1DoFActuatorAcceleration;
21  class ControlTarget1DoFActuatorVelocity;
22  class ControlTarget1DoFActuatorTorque;
23  class SensorValueForceTorque;
24 } // namespace armarx
25 
26 namespace DMP
27 {
28  // using UMITSMPPtr = boost::shared_ptr<class UMITSMP>;
30 } // namespace DMP
31 
33 {
35 
36  TYPEDEF_PTRS_HANDLE(NJointBimanualCCDMPVelocityController);
37  TYPEDEF_PTRS_HANDLE(NJointBimanualCCDMPVelocityControllerControlData);
38 
39  using ViaPoint = std::pair<double, DMP::DVec>;
40  using ViaPointsSet = std::vector<ViaPoint>;
41 
43  {
44  public:
45  Eigen::VectorXf leftTargetVel;
46  Eigen::VectorXf rightTargetVel;
47 
50 
51  double virtualTime;
52 
53  Eigen::VectorXf leftDesiredJoint;
54  Eigen::VectorXf rightDesiredJoint;
55  };
56 
57  /**
58  * @brief The NJointBimanualCCDMPVelocityController class
59  * @ingroup Library-RobotUnit-NJointControllers
60  */
62  public NJointControllerWithTripleBuffer<NJointBimanualCCDMPVelocityControllerControlData>,
64  {
65  public:
66  using ConfigPtrT = NJointBimanualCCDMPVelocityControllerConfigPtr;
68  const NJointControllerConfigPtr& config,
69  const VirtualRobot::RobotPtr&);
70 
71  // NJointControllerInterface interface
72  std::string getClassName(const Ice::Current&) const override;
73 
74  // NJointController interface
75 
76  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
77  const IceUtil::Time& timeSinceLastIteration) override;
78 
79  // NJointBimanualCCDMPVelocityControllerInterface interface
80  void
81  learnDMPFromFiles(const std::string&, const Ice::StringSeq&, const Ice::Current&) override;
82  void learnDMPFromBothFiles(const Ice::StringSeq&,
83  const Ice::StringSeq&,
84  const Ice::Current&) override;
85 
86  bool isFinished(const Ice::Current&) override;
87 
88  void setRatios(const Ice::DoubleSeq& ratios, const Ice::Current&) override;
89 
90  void runDMP(const Ice::DoubleSeq& leftGoals,
91  const Ice::DoubleSeq& rightGoals,
92  const Ice::Current&) override;
93  void
94  setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&) override;
95  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&) override;
96 
97  void changeLeader(const Ice::Current&) override;
98 
99  double getVirtualTime(const Ice::Current&) override;
100 
101  std::string getLeaderName(const Ice::Current&) override;
102 
103  protected:
104  virtual void onPublish(const SensorAndControl&,
106  const DebugObserverInterfacePrx&) override;
107 
108  void onInitNJointController() override;
109  void onDisconnectNJointController() override;
110  void controllerRun();
111 
112  private:
113  Eigen::VectorXf getControlWrench(const Eigen::VectorXf& twist,
114  const Eigen::Matrix4f& currentPose,
115  const Eigen::Matrix4f& targetPose);
116 
117  Eigen::Matrix4f getLocalPose(const Eigen::Matrix4f& newCoordinate,
118  const Eigen::Matrix4f& globalTargetPose);
119  Eigen::Matrix4f getLocalPose(const std::vector<double>& newCoordinateVec,
120  const std::vector<double>& globalTargetPoseVec);
121 
122  struct DebugBufferData
123  {
124  StringFloatDictionary desired_velocities;
125  StringFloatDictionary constrained_force;
126  float leftTargetPose_x;
127  float leftTargetPose_y;
128  float leftTargetPose_z;
129  float rightTargetPose_x;
130  float rightTargetPose_y;
131  float rightTargetPose_z;
132 
133  float leftCurrentPose_x;
134  float leftCurrentPose_y;
135  float leftCurrentPose_z;
136  float rightCurrentPose_x;
137  float rightCurrentPose_y;
138  float rightCurrentPose_z;
139 
140  float leftControlSignal_x;
141  float leftControlSignal_y;
142  float leftControlSignal_z;
143  float leftControlSignal_ro;
144  float leftControlSignal_pi;
145  float leftControlSignal_ya;
146 
147  float rightControlSignal_x;
148  float rightControlSignal_y;
149  float rightControlSignal_z;
150  float rightControlSignal_ro;
151  float rightControlSignal_pi;
152  float rightControlSignal_ya;
153 
154  double virtualTime;
155  };
156 
157  bool finished;
158  TripleBuffer<DebugBufferData> debugDataInfo;
159 
160  struct NJointBimanualCCDMPVelocityControllerSensorData
161  {
162  double currentTime;
163  double deltaT;
164  Eigen::Matrix4f currentLeftPose;
165  Eigen::Matrix4f currentRightPose;
166  Eigen::VectorXf currentLeftTwist;
167  Eigen::VectorXf currentRightTwist;
168  };
169 
171 
172  struct NJointBimanualCCDMPVelocityControllerInterfaceData
173  {
174  Eigen::Matrix4f currentLeftPose;
175  Eigen::Matrix4f currentRightPose;
176 
177  Eigen::VectorXf currentLeftJointVals;
178  Eigen::VectorXf currentRightJointVals;
179  };
180 
182 
183 
184  std::vector<ControlTarget1DoFActuatorVelocity*> leftTargets;
185  std::vector<const SensorValue1DoFActuatorAcceleration*> leftAccelerationSensors;
186  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
187  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
188 
189  std::vector<ControlTarget1DoFActuatorVelocity*> rightTargets;
190  std::vector<const SensorValue1DoFActuatorAcceleration*> rightAccelerationSensors;
191  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
192  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
193 
194  const SensorValueForceTorque* rightForceTorque;
195  const SensorValueForceTorque* leftForceTorque;
196 
197  NJointBimanualCCDMPVelocityControllerConfigPtr cfg;
198  VirtualRobot::DifferentialIKPtr leftIK;
199  VirtualRobot::DifferentialIKPtr rightIK;
200 
201  std::vector<tsvmp::TaskSpaceDMPControllerPtr> leftGroup;
202  std::vector<tsvmp::TaskSpaceDMPControllerPtr> rightGroup;
203  std::vector<tsvmp::TaskSpaceDMPControllerPtr> bothLeaderGroup;
204  DMP::UMIDMPPtr leftJointDMP;
205  DMP::UMIDMPPtr rightJointDMP;
206  bool isLeftJointLearned;
207  bool isRightJointLearned;
208 
209 
210  std::string leaderName;
211 
212  VirtualRobot::RobotNodePtr tcpLeft;
213  VirtualRobot::RobotNodePtr tcpRight;
214 
215  double virtualtimer;
216  double timeDuration;
217 
218  mutable MutexType controllerMutex;
219 
220  Eigen::VectorXf leftDesiredJointValues;
221  Eigen::VectorXf rightDesiredJointValues;
222 
223  Eigen::Vector3f leftKpos;
224  Eigen::Vector3f leftKori;
225  Eigen::Vector3f leftDpos;
226  Eigen::Vector3f leftDori;
227 
228  Eigen::Vector3f rightKpos;
229  Eigen::Vector3f rightKori;
230  Eigen::Vector3f rightDpos;
231  Eigen::Vector3f rightDori;
232 
233 
234  float knull;
235  float dnull;
236 
237  std::vector<std::string> leftJointNames;
238  std::vector<std::string> rightJointNames;
239 
240  float torqueLimit;
241  VirtualRobot::RobotNodeSetPtr leftRNS;
242  VirtualRobot::RobotNodeSetPtr rightRNS;
243 
244  Eigen::VectorXf leftNullSpaceCoefs;
245  Eigen::VectorXf rightNullSpaceCoefs;
246 
247 
248  float maxLinearVel;
249  float maxAngularVel;
250 
251 
254 
255  bool started;
256  bool isDMPRun;
257  DMP::Vec<DMP::DMPState> currentLeftJointState;
258  DMP::Vec<DMP::DMPState> currentRightJointState;
259 
260  // NJointBimanualCCDMPVelocityControllerInterface interface
261 
262  // NJointController interface
263  protected:
264  void rtPreActivateController() override;
265  };
266 
267 } // namespace armarx::control::deprecated_njoint_mp_controller::bimanual
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::learnDMPFromFiles
void learnDMPFromFiles(const std::string &, const Ice::StringSeq &, const Ice::Current &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:676
NJointControllerWithTripleBuffer.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::rightTargetVel
Eigen::VectorXf rightTargetVel
Definition: NJointBimanualCCDMPVelocityController.h:46
boost::shared_ptr< class UMIDMP >
armarx::control::deprecated_njoint_mp_controller::bimanual::ViaPointsSet
std::vector< ViaPoint > ViaPointsSet
Definition: NJointBimanualCCDMPController.h:39
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
DMP
Definition: NJointTaskSpaceAdaptiveDMPController.h:24
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: NJointBimanualCCDMPVelocityController.cpp:978
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
PeriodicTask.h
DMP::UMIDMPPtr
boost::shared_ptr< class UMIDMP > UMIDMPPtr
Definition: NJointTaskSpaceAdaptiveDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:762
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::setRatios
void setRatios(const Ice::DoubleSeq &ratios, const Ice::Current &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:752
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::leftTargetPose
Eigen::Matrix4f leftTargetPose
Definition: NJointBimanualCCDMPVelocityController.h:48
armarx::NJointBimanualCCDMPVelocityControllerInterface::changeLeader
void changeLeader()
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:587
armarx::NJointBimanualCCDMPVelocityControllerInterface::isFinished
bool isFinished()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController
The NJointBimanualCCDMPVelocityController class.
Definition: NJointBimanualCCDMPVelocityController.h:61
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::controllerRun
void controllerRun()
Definition: NJointBimanualCCDMPVelocityController.cpp:260
armarx::CartesianVelocityControllerPtr
std::shared_ptr< CartesianVelocityController > CartesianVelocityControllerPtr
Definition: CartesianVelocityController.h:34
armarx::NJointBimanualCCDMPVelocityControllerInterface
Definition: ControllerInterface.ice:134
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:182
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::leftDesiredJoint
Eigen::VectorXf leftDesiredJoint
Definition: NJointBimanualCCDMPVelocityController.h:53
armarx::control::deprecated_njoint_mp_controller::bimanual::ViaPoint
std::pair< double, DMP::DVec > ViaPoint
Definition: NJointBimanualCCDMPController.h:38
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointBimanualCCDMPVelocityController.cpp:240
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointBimanualCCDMPVelocityController.cpp:246
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::leftTargetVel
Eigen::VectorXf leftTargetVel
Definition: NJointBimanualCCDMPVelocityController.h:45
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointBimanualCCDMPVelocityController.cpp:445
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:27
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::onInitNJointController
void onInitNJointController() override
Definition: NJointBimanualCCDMPVelocityController.cpp:956
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::NJointBimanualCCDMPVelocityController
NJointBimanualCCDMPVelocityController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointBimanualCCDMPVelocityController.cpp:35
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::rightTargetPose
Eigen::Matrix4f rightTargetPose
Definition: NJointBimanualCCDMPVelocityController.h:49
TaskSpaceVMP.h
CartesianVelocityController.h
CycleUtil.h
PIDController.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::runDMP
void runDMP(const Ice::DoubleSeq &leftGoals, const Ice::DoubleSeq &rightGoals, const Ice::Current &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:812
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::rightDesiredJoint
Eigen::VectorXf rightDesiredJoint
Definition: NJointBimanualCCDMPVelocityController.h:54
armarx::NJointControllerWithTripleBuffer< NJointBimanualCCDMPVelocityControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
IceUtil::Handle< class RobotUnit >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData::virtualTime
double virtualTime
Definition: NJointBimanualCCDMPVelocityController.h:51
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:875
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityControllerControlData
Definition: NJointBimanualCCDMPVelocityController.h:42
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:778
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:32
armarx::NJointBimanualCCDMPVelocityControllerInterface::getLeaderName
string getLeaderName()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCCDMPVelocityController::learnDMPFromBothFiles
void learnDMPFromBothFiles(const Ice::StringSeq &, const Ice::StringSeq &, const Ice::Current &) override
Definition: NJointBimanualCCDMPVelocityController.cpp:726
armarx::NJointBimanualCCDMPVelocityControllerInterface::getVirtualTime
double getVirtualTime()
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::bimanual
Definition: NJointBimanualCartesianAdmittanceController.cpp:30
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::bimanual::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointBimanualCartesianAdmittanceController)