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