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