NJointBimanualCartesianAdmittanceController.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/CartesianAdmittanceControllerInterface.h>
20 
21 
23 {
25 
26  TYPEDEF_PTRS_HANDLE(NJointBimanualCartesianAdmittanceController);
27  TYPEDEF_PTRS_HANDLE(NJointBimanualObjLevelControlData);
28 
29 
31  public NJointController,
33  {
34  public:
35  NJointBimanualCartesianAdmittanceController(const RobotUnitPtr&, const NJointControllerConfigPtr& config, const VirtualRobot::RobotPtr&);
36 
37  // NJointController interface
38  std::string getClassName(const Ice::Current&) const override;
39  void rtRun(const IceUtil::Time& sensorValuesTimestamp, const IceUtil::Time& timeSinceLastIteration) override;
40 
41  //set config
42  void setConfig(const NJointBimanualCartesianAdmittanceControllerConfigPtr& ptr, const Ice::Current& = Ice::emptyCurrent) override;
43  void setDesiredJointValuesLeft(const Ice::FloatSeq& vals, const Ice::Current& = Ice::emptyCurrent) override;
44  void setDesiredJointValuesRight(const Ice::FloatSeq& vals, const Ice::Current& = Ice::emptyCurrent) override;
45  void setNullspaceConfig(const detail::NJBmanCartAdmCtrl::Nullspace& nullspace, const Ice::Current& = Ice::emptyCurrent) override;
46  void setAdmittanceConfig(const detail::NJBmanCartAdmCtrl::Admittance& admittanceObject, const Ice::Current& = Ice::emptyCurrent) override;
47  void setForceConfig(const detail::NJBmanCartAdmCtrl::Force& left, const detail::NJBmanCartAdmCtrl::Force& right, const Ice::Current& = Ice::emptyCurrent) override;
48  void setImpedanceConfig(const detail::NJBmanCartAdmCtrl::Impedance& left, const detail::NJBmanCartAdmCtrl::Impedance& right, const Ice::Current& = Ice::emptyCurrent) override;
49  //control
50  Eigen::Matrix4f getBoxPose(const Ice::Current& = Ice::emptyCurrent) const override;
51  void setBoxPose(const Eigen::Matrix4f& pose, const Ice::Current& = Ice::emptyCurrent) override;
52  void setBoxWidth(float w, const Ice::Current& = Ice::emptyCurrent) override;
53  void setBoxVelocity(
54  const Eigen::Vector3f& velXYZ,
55  const Eigen::Vector3f& velRPY,
56  const Ice::Current& = Ice::emptyCurrent) override;
57  void setBoxPoseAndVelocity(const Eigen::Matrix4f& pose,
58  const Eigen::Vector3f& velXYZ,
59  const Eigen::Vector3f& velRPY,
60  const Ice::Current& = Ice::emptyCurrent) override;
61  void moveBoxPose(const Eigen::Matrix4f& pose, const Ice::Current& = Ice::emptyCurrent) override;
62  void moveBoxPosition(const Eigen::Vector3f& pos, const Ice::Current& = Ice::emptyCurrent) override;
63  protected:
65  void updateDesiredJointValuesLeft(const Ice::FloatSeq& cfg);
66  void updateDesiredJointValuesRight(const Ice::FloatSeq& cfg);
71  protected:
73 
74  // void onInitNJointController();
75  // void onDisconnectNJointController();
76  // void controllerRun(); //runs dmp controller
77 
78  private:
79  struct Target
80  {
81  Eigen::Matrix4f pose;
82  Eigen::Vector6f vel;
83  };
84  mutable std::recursive_mutex targBufWriteMutex;
86 
87 
88  struct PreprocessedCfg
89  {
90  float boxWidth;
91 
92  Eigen::Vector6f KmAdmittance;
93  Eigen::Vector6f KpAdmittance;
94  Eigen::Vector6f KdAdmittance;
95 
96  float ftCalibrationTime;
97 
98  Eigen::Vector12f KpImpedance;
99  Eigen::Vector12f KdImpedance;
100 
101  float massLeft;
102  Eigen::Vector3f CoMVecLeft;
103  Eigen::Vector3f forceOffsetLeft;
104  Eigen::Vector3f torqueOffsetLeft;
105 
106  float massRight;
107  Eigen::Vector3f CoMVecRight;
108  Eigen::Vector3f forceOffsetRight;
109  Eigen::Vector3f torqueOffsetRight;
110 
111  Eigen::VectorXf desiredJointValuesLeft;
112  Eigen::VectorXf desiredJointValuesRight;
113 
114  float knull;
115  float dnull;
116 
117  float torqueLimit;
118 
119  Eigen::Vector12f targetWrench;
120 
121  float filterCoeff;
122 
123  Eigen::Vector6f forceThreshold;
124  };
125  mutable std::recursive_mutex cfgBufWriteMutex;
127 
128  struct RTData
129  {
130  struct Arm
131  {
132  std::vector<ControlTarget1DoFActuatorTorque*> targets;
133  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors;
134  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors;
136  VirtualRobot::DifferentialIKPtr IK;
137 
138  std::vector<std::string> jointNames;
139  VirtualRobot::RobotNodeSetPtr rns;
140  VirtualRobot::RobotNodePtr tcp;
141  VirtualRobot::RobotNodePtr frameFTSensor;
142 
144  };
145  Arm left;
146  Arm right;
147 
148  double ftcalibrationTimer = 0;
149  // Eigen::Vector12f ftOffset = Eigen::Vector12f::Zero();
150  bool firstLoop = true;
151 
152  Eigen::Vector6f virtualAcc = Eigen::Vector6f::Zero();
153  Eigen::Vector6f virtualVel = Eigen::Vector6f::Zero();
155 
156  Eigen::Vector12f filteredOldValue = Eigen::Vector12f::Zero();
157  };
158  RTData rt;
159 
160 
161  struct DebugBufferData
162  {
163  Eigen::Matrix4f currentBoxPose;
164 
165  StringFloatDictionary desired_torques;
166 
167  float virtualPose_x;
168  float virtualPose_y;
169  float virtualPose_z;
170 
171  float objPose_x;
172  float objPose_y;
173  float objPose_z;
174 
175  float objForce_x;
176  float objForce_y;
177  float objForce_z;
178  float objTorque_x;
179  float objTorque_y;
180  float objTorque_z;
181 
182  float deltaPose_x;
183  float deltaPose_y;
184  float deltaPose_z;
185  float deltaPose_rx;
186  float deltaPose_ry;
187  float deltaPose_rz;
188 
189  float objVel_x;
190  float objVel_y;
191  float objVel_z;
192  float objVel_rx;
193  float objVel_ry;
194  float objVel_rz;
195 
196  float modifiedPoseRight_x;
197  float modifiedPoseRight_y;
198  float modifiedPoseRight_z;
199  float currentPoseLeft_x;
200  float currentPoseLeft_y;
201  float currentPoseLeft_z;
202 
203  float modifiedPoseLeft_x;
204  float modifiedPoseLeft_y;
205  float modifiedPoseLeft_z;
206  float currentPoseRight_x;
207  float currentPoseRight_y;
208  float currentPoseRight_z;
209 
210  float dmpBoxPose_x;
211  float dmpBoxPose_y;
212  float dmpBoxPose_z;
213 
214  float dmpTwist_x;
215  float dmpTwist_y;
216  float dmpTwist_z;
217 
218  float modifiedTwist_lx;
219  float modifiedTwist_ly;
220  float modifiedTwist_lz;
221  float modifiedTwist_rx;
222  float modifiedTwist_ry;
223  float modifiedTwist_rz;
224 
225  float rx;
226  float ry;
227  float rz;
228 
229  // Eigen::VectorXf wrenchDMP;
230  // Eigen::VectorXf computedBoxWrench;
231 
232  Eigen::VectorXf forceImpedance;
233  Eigen::VectorXf forcePID;
234  Eigen::VectorXf forcePIDControlValue;
235  Eigen::VectorXf poseError;
236  Eigen::VectorXf wrenchesConstrained;
237  Eigen::VectorXf wrenchesMeasuredInRoot;
238  };
239 
240  mutable std::recursive_mutex debugOutputDataReadMutex;
241  TripleBuffer<DebugBufferData> debugOutputData;
242 
243  // struct rt2ControlData
244  // {
245  // double currentTime;
246  // double deltaT;
247  // Eigen::Matrix4f currentPose;
248  // Eigen::VectorXf currentTwist;
249  // };
250  // TripleBuffer<rt2ControlData> rt2ControlBuffer;
251 
252  // struct ControlInterfaceData
253  // {
254  // Eigen::Matrix4f currentLeftPose;
255  // Eigen::Matrix4f currentRightPose;
256  // };
257 
258  // TripleBuffer<ControlInterfaceData> controlInterfaceBuffer;
259 
260  // float torqueLimit;
261 
262 
263 
264  // TaskSpaceDMPControllerPtr objectDMP;
265 
266 
267  // Eigen::Matrix4f leftInitialPose;
268  // Eigen::Matrix4f rightInitialPose;
269  // Eigen::Matrix4f boxInitialPose;
270 
271 
272  // std::vector<PIDControllerPtr> forcePIDControllers;
273 
274  // filter parameters
275  // bool finished;
276  // bool dmpStarted;
277  protected:
279  };
280 
281 } // namespace armarx
282 
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::positionSensors
std::vector< const SensorValue1DoFActuatorPosition * > positionSensors
Definition: NJointBimanualCartesianAdmittanceController.h:134
armarx::navigation::platform_controller::platform_global_trajectory::Target
Twist2D Target
Definition: PlatformGlobalTrajectoryController.h:72
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointBimanualCartesianAdmittanceController.cpp:167
armarx::detail::NJBmanCartAdmCtrl::Nullspace
Definition: CartesianAdmittanceControllerInterface.ice:44
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::rtPreActivateController
void rtPreActivateController()
This function is called before the controller is activated.
Definition: NJointBimanualCartesianAdmittanceController.cpp:132
armarx::detail::NJBmanCartAdmCtrl::Admittance
Definition: CartesianAdmittanceControllerInterface.ice:58
MathUtils.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setImpedanceConfig
void setImpedanceConfig(const detail::NJBmanCartAdmCtrl::Impedance &left, const detail::NJBmanCartAdmCtrl::Impedance &right, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:782
RobotUnit.h
armarx::NJointBimanualCartesianAdmittanceControllerConfig
Definition: CartesianAdmittanceControllerInterface.ice:83
armarx::SynchronousNJointController
Definition: NJointControllerBase.h:1145
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::rns
VirtualRobot::RobotNodeSetPtr rns
Definition: NJointBimanualCartesianAdmittanceController.h:139
armarx::NJointBimanualCartesianAdmittanceControllerInterface
Definition: CartesianAdmittanceControllerInterface.ice:105
armarx::NJointBimanualCartesianAdmittanceControllerInterface::getBoxPose
Eigen::Matrix4f getBoxPose()
SensorValueForceTorque.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateDesiredJointValuesLeft
void updateDesiredJointValuesLeft(const Ice::FloatSeq &cfg)
Definition: NJointBimanualCartesianAdmittanceController.cpp:802
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateConfig
void updateConfig(const NJointBimanualCartesianAdmittanceControllerConfig &cfg)
Definition: NJointBimanualCartesianAdmittanceController.cpp:789
armarx::detail::NJBmanCartAdmCtrl::Force
Definition: CartesianAdmittanceControllerInterface.ice:67
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setBoxPose
void setBoxPose(const Eigen::Matrix4f &pose, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:685
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::moveBoxPose
void moveBoxPose(const Eigen::Matrix4f &pose, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:727
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setDesiredJointValuesRight
void setDesiredJointValuesRight(const Ice::FloatSeq &vals, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:758
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setForceConfig
void setForceConfig(const detail::NJBmanCartAdmCtrl::Force &left, const detail::NJBmanCartAdmCtrl::Force &right, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:776
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::sensorFrame2TcpFrame
Eigen::Matrix4f sensorFrame2TcpFrame
Definition: NJointBimanualCartesianAdmittanceController.h:143
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::frameFTSensor
VirtualRobot::RobotNodePtr frameFTSensor
Definition: NJointBimanualCartesianAdmittanceController.h:141
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::jointNames
std::vector< std::string > jointNames
Definition: NJointBimanualCartesianAdmittanceController.h:138
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateAdmittanceConfig
void updateAdmittanceConfig(const detail::NJBmanCartAdmCtrl::Admittance admittanceObject)
Definition: NJointBimanualCartesianAdmittanceController.cpp:827
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setNullspaceConfig
void setNullspaceConfig(const detail::NJBmanCartAdmCtrl::Nullspace &nullspace, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:764
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm
Definition: NJointBimanualCartesianAdmittanceController.h:130
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateForceConfig
void updateForceConfig(const detail::NJBmanCartAdmCtrl::Force &left, const detail::NJBmanCartAdmCtrl::Force &right)
Definition: NJointBimanualCartesianAdmittanceController.cpp:840
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::NJointBimanualCartesianAdmittanceController
NJointBimanualCartesianAdmittanceController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointBimanualCartesianAdmittanceController.cpp:13
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointBimanualCartesianAdmittanceController.cpp:201
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::moveBoxPosition
void moveBoxPosition(const Eigen::Vector3f &pos, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:735
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateImpedanceConfig
void updateImpedanceConfig(const detail::NJBmanCartAdmCtrl::Impedance &left, const detail::NJBmanCartAdmCtrl::Impedance &right)
Definition: NJointBimanualCartesianAdmittanceController.cpp:861
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setBoxWidth
void setBoxWidth(float w, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:693
ControlTarget1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::tsvmp
Definition: NJointTaskSpaceImpedanceDMPController.h:20
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &)
Definition: NJointBimanualCartesianAdmittanceController.cpp:587
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::tcp
VirtualRobot::RobotNodePtr tcp
Definition: NJointBimanualCartesianAdmittanceController.h:140
armarx::detail::NJBmanCartAdmCtrl::Impedance
Definition: CartesianAdmittanceControllerInterface.ice:51
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
TaskSpaceVMP.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateDesiredJointValuesRight
void updateDesiredJointValuesRight(const Ice::FloatSeq &cfg)
Definition: NJointBimanualCartesianAdmittanceController.cpp:810
PIDController.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController
Definition: NJointBimanualCartesianAdmittanceController.h:30
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setConfig
void setConfig(const NJointBimanualCartesianAdmittanceControllerConfigPtr &ptr, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:743
NJointController.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::forceTorque
const SensorValueForceTorque * forceTorque
Definition: NJointBimanualCartesianAdmittanceController.h:135
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setBoxVelocity
void setBoxVelocity(const Eigen::Vector3f &velXYZ, const Eigen::Vector3f &velRPY, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:700
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::Arm
Definition: RobotNameHelper.h:41
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setBoxPoseAndVelocity
void setBoxPoseAndVelocity(const Eigen::Matrix4f &pose, const Eigen::Vector3f &velXYZ, const Eigen::Vector3f &velRPY, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:713
armarx::WriteBufferedTripleBuffer< Target >
Eigen::Matrix< float, 6, 1 >
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:31
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setDesiredJointValuesLeft
void setDesiredJointValuesLeft(const Ice::FloatSeq &vals, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:752
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::IK
VirtualRobot::DifferentialIKPtr IK
Definition: NJointBimanualCartesianAdmittanceController.h:136
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::updateNullspaceConfig
void updateNullspaceConfig(const detail::NJBmanCartAdmCtrl::Nullspace &nullspace)
Definition: NJointBimanualCartesianAdmittanceController.cpp:818
SensorValue1DoFActuator.h
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::setAdmittanceConfig
void setAdmittanceConfig(const detail::NJBmanCartAdmCtrl::Admittance &admittanceObject, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointBimanualCartesianAdmittanceController.cpp:770
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::control::deprecated_njoint_mp_controller::bimanual
Definition: NJointBimanualCartesianAdmittanceController.cpp:9
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::targets
std::vector< ControlTarget1DoFActuatorTorque * > targets
Definition: NJointBimanualCartesianAdmittanceController.h:132
armarx::TripleBuffer< DebugBufferData >
armarx::control::deprecated_njoint_mp_controller::bimanual::NJointBimanualCartesianAdmittanceController::RTData::Arm::velocitySensors
std::vector< const SensorValue1DoFActuatorVelocity * > velocitySensors
Definition: NJointBimanualCartesianAdmittanceController.h:133
armarx::control::deprecated_njoint_mp_controller::bimanual::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointBimanualCartesianAdmittanceController)