NJointBimanualObjLevelController.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 // armarx
16 
17 // control
18 #include <armarx/control/deprecated_njoint_mp_controller/bimanual/ObjLevelControllerInterface.h>
20 
21 
23 {
25 
26  TYPEDEF_PTRS_HANDLE(NJointBimanualObjLevelController);
27  TYPEDEF_PTRS_HANDLE(NJointBimanualObjLevelControlData);
28 
30  {
31  public:
32  // control target from Movement Primitives
34  Eigen::VectorXf boxTwist;
35  };
36 
37 
39  public NJointControllerWithTripleBuffer<NJointBimanualObjLevelControlData>,
41  {
42  public:
43  // using ConfigPtrT = BimanualForceControllerConfigPtr;
44  NJointBimanualObjLevelController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, 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, const IceUtil::Time& timeSinceLastIteration);
52 
53  // NJointCCDMPControllerInterface interface
54  void learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&);
55  bool isFinished(const Ice::Current&)
56  {
57  return finished;
58  }
59  Eigen::Matrix3f skew(Eigen::Vector3f vec)
60  {
61  Eigen::Matrix3f mat = Eigen::MatrixXf::Zero(3, 3);
62  mat(1, 2) = -vec(0);
63  mat(0, 2) = vec(1);
64  mat(0, 1) = -vec(2);
65  mat(2, 1) = vec(0);
66  mat(2, 0) = -vec(1);
67  mat(1, 0) = vec(2);
68  return mat;
69  }
70 
71  // void runDMP(const Ice::DoubleSeq& goals, Ice::Double tau, const Ice::Current&);
72  void runDMP(const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&);
73  void runDMPWithVirtualStart(const Ice::DoubleSeq& starts, const Ice::DoubleSeq& goals, Ice::Double timeDuration, const Ice::Current&);
74 
75  void setGoals(const Ice::DoubleSeq& goals, const Ice::Current&);
76  void setViaPoints(Ice::Double u, const Ice::DoubleSeq& viapoint, const Ice::Current&);
77  void removeAllViaPoints(const Ice::Current&);
78 
79  double getVirtualTime(const Ice::Current&)
80  {
81  return virtualtimer;
82  }
83 
84  void setKpImpedance(const Ice::FloatSeq& value, const Ice::Current&);
85  void setKdImpedance(const Ice::FloatSeq& value, const Ice::Current&);
86  void setKmAdmittance(const Ice::FloatSeq& value, const Ice::Current&);
87  void setKpAdmittance(const Ice::FloatSeq& value, const Ice::Current&);
88  void setKdAdmittance(const Ice::FloatSeq& value, const Ice::Current&);
89 
90  std::vector<float> getCurrentObjVel(const Ice::Current&);
91  std::vector<float> getCurrentObjForce(const Ice::Current&);
92 
93  void setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&);
94  DoubleSeqSeq getMPWeights(const Ice::Current&);
95 
96  void setMPRotWeights(const DoubleSeqSeq& weights, const Ice::Current&);
97  DoubleSeqSeq getMPRotWeights(const Ice::Current&);
98  protected:
100 
101  void onInitNJointController();
103  void controllerRun();
104 
105  private:
106  Eigen::VectorXf targetWrench;
107  struct DebugBufferData
108  {
109  StringFloatDictionary desired_torques;
110 
111  float virtualPose_x;
112  float virtualPose_y;
113  float virtualPose_z;
114 
115  float objPose_x;
116  float objPose_y;
117  float objPose_z;
118 
119  float objForce_x;
120  float objForce_y;
121  float objForce_z;
122  float objTorque_x;
123  float objTorque_y;
124  float objTorque_z;
125 
126  float deltaPose_x;
127  float deltaPose_y;
128  float deltaPose_z;
129  float deltaPose_rx;
130  float deltaPose_ry;
131  float deltaPose_rz;
132 
133  float objVel_x;
134  float objVel_y;
135  float objVel_z;
136  float objVel_rx;
137  float objVel_ry;
138  float objVel_rz;
139 
140  float modifiedPoseRight_x;
141  float modifiedPoseRight_y;
142  float modifiedPoseRight_z;
143  float currentPoseLeft_x;
144  float currentPoseLeft_y;
145  float currentPoseLeft_z;
146  float leftQuat_w;
147  float leftQuat_x;
148  float leftQuat_y;
149  float leftQuat_z;
150  float rightQuat_w;
151  float rightQuat_x;
152  float rightQuat_y;
153  float rightQuat_z;
154 
155  float modifiedPoseLeft_x;
156  float modifiedPoseLeft_y;
157  float modifiedPoseLeft_z;
158  float currentPoseRight_x;
159  float currentPoseRight_y;
160  float currentPoseRight_z;
161 
162  float dmpBoxPose_x;
163  float dmpBoxPose_y;
164  float dmpBoxPose_z;
165 
166  float dmpTwist_x;
167  float dmpTwist_y;
168  float dmpTwist_z;
169 
170  float modifiedTwist_lx;
171  float modifiedTwist_ly;
172  float modifiedTwist_lz;
173  float modifiedTwist_rx;
174  float modifiedTwist_ry;
175  float modifiedTwist_rz;
176 
177  float rx;
178  float ry;
179  float rz;
180 
181  Eigen::VectorXf wrenchDMP;
182  Eigen::VectorXf computedBoxWrench;
183 
184  Eigen::VectorXf forceImpedance;
185  Eigen::VectorXf forcePID;
186  Eigen::VectorXf forcePIDControlValue;
187  Eigen::VectorXf poseError;
188  Eigen::VectorXf wrenchesConstrained;
189  Eigen::VectorXf wrenchesMeasuredInRoot;
190  };
191  TripleBuffer<DebugBufferData> debugOutputData;
192 
193  struct rt2ControlData
194  {
195  double currentTime;
196  double deltaT;
197  Eigen::Matrix4f currentPose;
198  Eigen::VectorXf currentTwist;
199  };
200  TripleBuffer<rt2ControlData> rt2ControlBuffer;
201 
202  struct ControlInterfaceData
203  {
204  Eigen::Matrix4f currentLeftPose;
205  Eigen::Matrix4f currentRightPose;
206  Eigen::Matrix4f currentObjPose;
207  Eigen::Vector3f currentObjVel;
208  Eigen::Vector3f currentObjForce;
209  };
210 
211  TripleBuffer<ControlInterfaceData> controlInterfaceBuffer;
212 
213  struct Inferface2rtData
214  {
215  Eigen::VectorXf KpImpedance;
216  Eigen::VectorXf KdImpedance;
217  Eigen::VectorXf KmAdmittance;
218  Eigen::VectorXf KpAdmittance;
219  Eigen::VectorXf KdAdmittance;
220  };
221  TripleBuffer<Inferface2rtData> interface2rtBuffer;
222 
223 
224 
225  std::vector<ControlTarget1DoFActuatorTorque*> leftTargets;
226  std::vector<const SensorValue1DoFActuatorAcceleration*> leftAccelerationSensors;
227  std::vector<const SensorValue1DoFActuatorVelocity*> leftVelocitySensors;
228  std::vector<const SensorValue1DoFActuatorPosition*> leftPositionSensors;
229 
230  std::vector<ControlTarget1DoFActuatorTorque*> rightTargets;
231  std::vector<const SensorValue1DoFActuatorAcceleration*> rightAccelerationSensors;
232  std::vector<const SensorValue1DoFActuatorVelocity*> rightVelocitySensors;
233  std::vector<const SensorValue1DoFActuatorPosition*> rightPositionSensors;
234 
235  const SensorValueForceTorque* rightForceTorque;
236  const SensorValueForceTorque* leftForceTorque;
237 
238  NJointBimanualObjLevelControllerConfigPtr cfg;
239  VirtualRobot::DifferentialIKPtr leftIK;
240  VirtualRobot::DifferentialIKPtr rightIK;
241 
243 
244  double virtualtimer;
245 
246  mutable MutexType controllerMutex;
247  mutable MutexType interfaceDataMutex;
248  Eigen::VectorXf leftDesiredJointValues;
249  Eigen::VectorXf rightDesiredJointValues;
250 
251  Eigen::Matrix4f leftInitialPose;
252  Eigen::Matrix4f rightInitialPose;
253  Eigen::Matrix4f boxInitialPose;
254 
255  Eigen::VectorXf KpImpedance;
256  Eigen::VectorXf KdImpedance;
257  Eigen::VectorXf KpAdmittance;
258  Eigen::VectorXf KdAdmittance;
259  Eigen::VectorXf KmAdmittance;
260  Eigen::VectorXf KmPID;
261 
262  Eigen::VectorXf virtualAcc;
263  Eigen::VectorXf virtualVel;
264  Eigen::Matrix4f virtualPose;
265 
266  Eigen::Matrix4f sensorFrame2TcpFrameLeft;
267  Eigen::Matrix4f sensorFrame2TcpFrameRight;
268 
269  //static compensation
270  float massLeft;
271  Eigen::Vector3f CoMVecLeft;
272  Eigen::Vector3f forceOffsetLeft;
273  Eigen::Vector3f torqueOffsetLeft;
274 
275  float massRight;
276  Eigen::Vector3f CoMVecRight;
277  Eigen::Vector3f forceOffsetRight;
278  Eigen::Vector3f torqueOffsetRight;
279 
280  // float knull;
281  // float dnull;
282 
283  std::vector<std::string> leftJointNames;
284  std::vector<std::string> rightJointNames;
285 
286  // float torqueLimit;
287  VirtualRobot::RobotNodeSetPtr leftRNS;
288  VirtualRobot::RobotNodeSetPtr rightRNS;
289  VirtualRobot::RobotNodePtr tcpLeft;
290  VirtualRobot::RobotNodePtr tcpRight;
291 
292  std::vector<PIDControllerPtr> forcePIDControllers;
293 
294  // filter parameters
295  float filterCoeff;
296  Eigen::VectorXf filteredOldValue;
297  bool finished;
298  bool dmpStarted;
299  double ftcalibrationTimer;
300  Eigen::VectorXf ftOffset;
301 
302  Eigen::Matrix3f fixedLeftRightRotOffset;
303  Eigen::Vector3f objCom2TCPLeftInObjFrame, objCom2TCPRightInObjFrame;
304 
305  protected:
307  bool firstLoop;
308  };
309 
310 } // namespace armarx
311 
MathUtils.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setKpImpedance
void setKpImpedance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:868
armarx::NJointControllerWithTripleBuffer
Definition: NJointControllerWithTripleBuffer.h:10
RobotUnit.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setKdAdmittance
void setKdAdmittance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:918
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setKmAdmittance
void setKmAdmittance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:948
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::onDisconnectNJointController
void onDisconnectNJointController()
Definition: NJointBimanualObjLevelController.cpp:1135
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setKdImpedance
void setKdImpedance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:886
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::skew
Eigen::Matrix3f skew(Eigen::Vector3f vec)
Definition: NJointBimanualObjLevelController.h:59
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelControlData::boxPose
Eigen::Matrix4f boxPose
Definition: NJointBimanualObjLevelController.h:33
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::NJointBimanualObjLevelController
NJointBimanualObjLevelController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointBimanualObjLevelController.cpp:10
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::onInitNJointController
void onInitNJointController()
Definition: NJointBimanualObjLevelController.cpp:1115
SensorValueForceTorque.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelControlData::boxTwist
Eigen::VectorXf boxTwist
Definition: NJointBimanualObjLevelController.h:34
armarx::NJointBimanualObjLevelControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration)
TODO make protected and use attorneys.
Definition: NJointBimanualObjLevelController.cpp:374
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelControlData
Definition: NJointBimanualObjLevelController.h:29
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::isFinished
bool isFinished(const Ice::Current &)
Definition: NJointBimanualObjLevelController.h:55
armarx::NJointBimanualObjLevelControllerInterface::getCurrentObjVel
Ice::FloatSeq getCurrentObjVel()
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::runDMPWithVirtualStart
void runDMPWithVirtualStart(const Ice::DoubleSeq &starts, const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:839
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:791
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:856
armarx::NJointBimanualObjLevelControllerInterface::getMPRotWeights
DoubleSeqSeq getMPRotWeights()
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController
Definition: NJointBimanualObjLevelController.h:38
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::controllerRun
void controllerRun()
Definition: NJointBimanualObjLevelController.cpp:345
armarx::NJointBimanualObjLevelControllerInterface::getCurrentObjForce
Ice::FloatSeq getCurrentObjForce()
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointBimanualObjLevelController.cpp:965
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::getClassName
std::string getClassName(const Ice::Current &) const
Definition: NJointBimanualObjLevelController.cpp:340
TaskSpaceVMP.h
PIDController.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setKpAdmittance
void setKpAdmittance(const Ice::FloatSeq &value, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:902
NJointController.h
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerPtr
std::shared_ptr< TaskSpaceDMPController > TaskSpaceDMPControllerPtr
Definition: NJointTaskSpaceImpedanceDMPController.h:24
armarx::NJointBimanualObjLevelControllerInterface::removeAllViaPoints
void removeAllViaPoints()
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::NJointControllerWithTripleBuffer< NJointBimanualObjLevelControlData >::MutexType
std::recursive_mutex MutexType
Definition: NJointControllerWithTripleBuffer.h:13
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::getVirtualTime
double getVirtualTime(const Ice::Current &)
Definition: NJointBimanualObjLevelController.h:79
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::firstLoop
bool firstLoop
Definition: NJointBimanualObjLevelController.h:307
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:797
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:805
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setMPRotWeights
void setMPRotWeights(const DoubleSeqSeq &weights, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:302
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: NJointBimanualObjLevelController.cpp:324
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualObjLevelController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &)
Definition: NJointBimanualObjLevelController.cpp:280
SensorValue1DoFActuator.h
armarx::NJointBimanualObjLevelControllerInterface
Definition: ObjLevelControllerInterface.ice:102
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)