NJointBimanualDMPForceController.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <VirtualRobot/IK/DifferentialIK.h>
5 #include <VirtualRobot/Robot.h>
6 
12 #include <RobotAPI/interface/units/RobotUnit/NJointTaskSpaceDMPController.h>
13 #include <RobotAPI/libraries/DMPController/TaskSpaceDMPController.h>
16 
17 #include <dmp/representation/dmp/umitsmp.h>
18 
19 namespace armarx
20 {
21  TYPEDEF_PTRS_HANDLE(NJointBimanualCCDMPController);
22  TYPEDEF_PTRS_HANDLE(NJointBimanualCCDMPControllerControlData);
23 
24  using ViaPoint = std::pair<double, DMP::DVec>;
25  using ViaPointsSet = std::vector<ViaPoint>;
27  {
28  public:
29  Eigen::VectorXf leftTargetVel;
30  Eigen::VectorXf rightTargetVel;
31 
34  };
35 
37  public NJointControllerWithTripleBuffer<NJointBimanualCCDMPControllerControlData>,
39  {
40  public:
41  using ConfigPtrT = NJointBimanualCCDMPControllerConfigPtr;
42  NJointBimanualCCDMPController(NJointControllerDescriptionProviderInterfacePtr prov,
43  const NJointControllerConfigPtr& config,
44  const VirtualRobot::RobotPtr&);
45 
46  // NJointControllerInterface interface
47  std::string getClassName(const Ice::Current&) const;
48 
49  // NJointController interface
50 
51  void rtRun(const IceUtil::Time& sensorValuesTimestamp,
52  const IceUtil::Time& timeSinceLastIteration);
53 
54  // NJointBimanualCCDMPControllerInterface interface
55  void learnDMPFromFiles(const std::string&, const Ice::StringSeq&, const Ice::Current&);
56  bool
57  isFinished(const Ice::Current&)
58  {
59  return false;
60  }
61 
62  void runDMP(const Ice::DoubleSeq& leftGoals,
63  const Ice::DoubleSeq& rightGoals,
64  const Ice::Current&);
65  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&);
66  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
67 
68  void changeLeader(const Ice::Current&);
69 
70  double
71  getVirtualTime(const Ice::Current&)
72  {
73  return virtualtimer;
74  }
75 
76  std::string
77  getLeaderName(const Ice::Current&)
78  {
79  return leaderName;
80  }
81 
82  protected:
83  virtual void onPublish(const SensorAndControl&,
86 
87  void onInitComponent();
88  void onDisconnectComponent();
89  void controllerRun();
90 
91  private:
92  Eigen::VectorXf getControlWrench(const Eigen::VectorXf& twist,
93  const Eigen::Matrix4f& currentPose,
94  const Eigen::Matrix4f& targetPose);
95 
96  Eigen::Matrix4f getLocalPose(const Eigen::Matrix4f& newCoordinate,
97  const Eigen::Matrix4f& globalTargetPose);
99  getLocalPose(const std::vector<double>& newCoordinateVec,
100  const std::vector<double>& globalTargetPoseVec)
101  {
102  Eigen::Matrix4f newCoordinate =
103  VirtualRobot::MathTools::quat2eigen4f(newCoordinateVec.at(4),
104  newCoordinateVec.at(5),
105  newCoordinateVec.at(6),
106  newCoordinateVec.at(3));
107  newCoordinate(0, 3) = newCoordinateVec.at(0);
108  newCoordinate(1, 3) = newCoordinateVec.at(1);
109  newCoordinate(2, 3) = newCoordinateVec.at(2);
110 
111  Eigen::Matrix4f globalTargetPose =
112  VirtualRobot::MathTools::quat2eigen4f(globalTargetPoseVec.at(4),
113  globalTargetPoseVec.at(5),
114  globalTargetPoseVec.at(6),
115  globalTargetPoseVec.at(3));
116  globalTargetPose(0, 3) = globalTargetPoseVec.at(0);
117  globalTargetPose(1, 3) = globalTargetPoseVec.at(1);
118  globalTargetPose(2, 3) = globalTargetPoseVec.at(2);
119 
120  return getLocalPose(newCoordinate, globalTargetPose);
121  }
122 
123  struct DebugBufferData
124  {
125  StringFloatDictionary desired_torques;
126  StringFloatDictionary constrained_force;
127  float leftTargetPose_x;
128  float leftTargetPose_y;
129  float leftTargetPose_z;
130  float rightTargetPose_x;
131  float rightTargetPose_y;
132  float rightTargetPose_z;
133 
134  float leftCurrentPose_x;
135  float leftCurrentPose_y;
136  float leftCurrentPose_z;
137  float rightCurrentPose_x;
138  float rightCurrentPose_y;
139  float rightCurrentPose_z;
140 
141  // StringFloatDictionary latestTargetVelocities;
142  // StringFloatDictionary dmpTargets;
143  // StringFloatDictionary currentPose;
144 
145  // double leadermpcFactor;
146  // double leadererror;
147  // double leaderposError;
148  // double leaderoriError;
149  // double leaderCanVal;
150 
151  // double followermpcFactor;
152  // double followererror;
153  // double followerposError;
154  // double followeroriError;
155  // double followerCanVal;
156  };
157 
158  TripleBuffer<DebugBufferData> debugDataInfo;
159 
160  struct NJointBimanualCCDMPControllerSensorData
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  TripleBuffer<NJointBimanualCCDMPControllerSensorData> controllerSensorData;
170 
171 
172  std::vector<ControlTarget1DoFActuatorTorque*> leftTargets;
173  std::vector<const SensorValue1DoFActuatorAcceleration*> leftAccelerationSensors;
174  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
175  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
176 
177  std::vector<ControlTarget1DoFActuatorTorque*> rightTargets;
178  std::vector<const SensorValue1DoFActuatorAcceleration*> rightAccelerationSensors;
179  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
180  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
181 
182  const SensorValueForceTorque* rightForceTorque;
183  const SensorValueForceTorque* leftForceTorque;
184 
185  NJointBimanualCCDMPControllerConfigPtr cfg;
186  VirtualRobot::DifferentialIKPtr leftIK;
187  VirtualRobot::DifferentialIKPtr rightIK;
188 
189  std::vector<TaskSpaceDMPControllerPtr> leftGroup;
190  std::vector<TaskSpaceDMPControllerPtr> rightGroup;
191  std::vector<TaskSpaceDMPControllerPtr> bothLeaderGroup;
192 
193 
194  std::string leaderName;
195 
196  VirtualRobot::RobotNodePtr tcpLeft;
197  VirtualRobot::RobotNodePtr tcpRight;
198 
199  double virtualtimer;
200 
201  mutable MutexType controllerMutex;
203 
204  Eigen::VectorXf leftDesiredJointValues;
205  Eigen::VectorXf rightDesiredJointValues;
206 
207  float KoriFollower;
208  float KposFollower;
209  float DposFollower;
210  float DoriFollower;
211 
212  Eigen::VectorXf forceC_des;
213  float boxWidth;
214 
215  Eigen::Vector3f kpos;
216  Eigen::Vector3f kori;
217  Eigen::Vector3f dpos;
218  Eigen::Vector3f dori;
219  Eigen::VectorXf kpf;
220  Eigen::VectorXf kif;
221 
222  float knull;
223  float dnull;
224 
225  std::vector<std::string> leftJointNames;
226  std::vector<std::string> rightJointNames;
227 
228  float torqueLimit;
229  VirtualRobot::RobotNodeSetPtr leftRNS;
230  VirtualRobot::RobotNodeSetPtr rightRNS;
231  VirtualRobot::RobotNodeSetPtr rnsLeftBody;
232  VirtualRobot::RobotNodeSetPtr rnsRightBody;
233 
234  Eigen::Vector3f filtered_leftForce;
235  Eigen::Vector3f filtered_leftTorque;
236  Eigen::Vector3f filtered_rightForce;
237  Eigen::Vector3f filtered_rightTorque;
238  float filterTimeConstant;
239 
240  std::vector<PIDControllerPtr> ftPIDController;
241 
242  Eigen::Vector3f offset_leftForce;
243  Eigen::Vector3f offset_leftTorque;
244  Eigen::Vector3f offset_rightForce;
245  Eigen::Vector3f offset_rightTorque;
246 
247  bool isForceCompensateDone;
248 
249  // NJointBimanualCCDMPControllerInterface interface
250  };
251 
252 } // namespace armarx
armarx::NJointBimanualCCDMPController::learnDMPFromFiles
void learnDMPFromFiles(const std::string &, const Ice::StringSeq &, const Ice::Current &)
Definition: NJointBimanualDMPForceController.cpp:984
armarx::NJointBimanualCCDMPControllerControlData
Definition: NJointBimanualDMPForceController.h:26
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::NJointBimanualCCDMPControllerControlData::leftTargetPose
Eigen::Matrix4f leftTargetPose
Definition: NJointBimanualDMPForceController.h:32
armarx::NJointBimanualCCDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &)
Definition: NJointBimanualDMPForceController.cpp:1008
armarx::NJointBimanualCCDMPControllerControlData::leftTargetVel
Eigen::VectorXf leftTargetVel
Definition: NJointBimanualDMPForceController.h:29
armarx::NJointBimanualCCDMPControllerInterface::changeLeader
void changeLeader()
SensorValueForceTorque.h
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
armarx::NJointBimanualCCDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointBimanualDMPForceController.cpp:500
armarx::NJointBimanualCCDMPController::runDMP
void runDMP(const Ice::DoubleSeq &leftGoals, const Ice::DoubleSeq &rightGoals, const Ice::Current &)
Definition: NJointBimanualDMPForceController.cpp:1058
armarx::NJointBimanualCCDMPController::getVirtualTime
double getVirtualTime(const Ice::Current &)
Definition: NJointBimanualDMPForceController.h:71
armarx::NJointBimanualCCDMPController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointBimanualDMPForceController.h:57
armarx::NJointBimanualCCDMPController::NJointBimanualCCDMPController
NJointBimanualCCDMPController(NJointControllerDescriptionProviderInterfacePtr prov, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
armarx::NJointBimanualCCDMPController
Definition: NJointBimanualDMPForceController.h:36
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
armarx::NJointBimanualCCDMPController::getLeaderName
std::string getLeaderName(const Ice::Current &)
Definition: NJointBimanualDMPForceController.h:77
armarx::NJointBimanualCCDMPController::onDisconnectComponent
void onDisconnectComponent()
Definition: NJointBimanualDMPForceController.cpp:1186
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::NJointBimanualCCDMPController::onInitComponent
void onInitComponent()
Definition: NJointBimanualDMPForceController.cpp:1178
armarx::NJointBimanualCCDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointBimanualDMPForceController.cpp:1024
armarx::NJointBimanualCCDMPController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointBimanualDMPForceController.cpp:247
ControlTarget1DoFActuator.h
armarx::NJointBimanualCCDMPControllerInterface
Definition: ControllerInterface.ice:87
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
CartesianVelocityController.h
armarx::NJointBimanualCCDMPController::controllerRun
void controllerRun()
Definition: NJointBimanualDMPForceController.cpp:253
PIDController.h
NJointController.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ViaPointsSet
std::vector< ViaPoint > ViaPointsSet
Definition: NJointBimanualDMPForceController.h:25
armarx::NJointControllerWithTripleBuffer< NJointBimanualCCDMPControllerControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::ViaPoint
std::pair< double, DMP::DVec > ViaPoint
Definition: NJointBimanualDMPForceController.h:24
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::NJointBimanualCCDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointBimanualDMPForceController.cpp:1097
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::NJointBimanualCCDMPControllerControlData::rightTargetPose
Eigen::Matrix4f rightTargetPose
Definition: NJointBimanualDMPForceController.h:33
SensorValue1DoFActuator.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::NJointBimanualCCDMPControllerControlData::rightTargetVel
Eigen::VectorXf rightTargetVel
Definition: NJointBimanualDMPForceController.h:30