1 #include <boost/algorithm/clamp.hpp>
3 #include <SimoxUtility/json.h>
4 #include <SimoxUtility/math/compare/is_equal.h>
5 #include <SimoxUtility/math/convert/mat4f_to_pos.h>
6 #include <SimoxUtility/math/convert/mat4f_to_quat.h>
8 #include <VirtualRobot/MathTools.h>
20 const RobotUnitPtr& robotUnit,
23 ARMARX_INFO <<
"Initializing force torque sensor " <<
c.sensorName;
24 const SensorValueBase* svlf = robotUnit->getSensorDevice(
c.sensorName)->getSensorValue();
28 sensorNode = rns->getRobot()->getSensor(
c.sensorName)->getRobotNode();
30 if (
c.sensorName ==
"FT R")
35 else if (
c.sensorName ==
"FT L")
43 filteredForce.setZero();
44 filteredTorque.setZero();
45 filteredForceInRoot.setZero();
46 filteredTorqueInRoot.setZero();
48 tcpGravityCompensation.setZero();
49 tcpGravForceVec.setZero();
50 tcpGravTorqueVec.setZero();
93 forceOffset.setZero();
94 torqueOffset.setZero();
98 timeForCalibration = 0.0f;
100 safeGuardForceOffset.setZero();
101 safeGuardTorqueOffset.setZero();
103 safeGuardEnabledForce.store(
false);
104 safeGuardEnabledTorque.store(
false);
106 resetForceGuard.store(
true);
107 resetTorqueGuard.store(
true);
125 sensorOriInRoot = sensorNode->getOrientationInRootFrame();
126 rawForce = forceSensor->
force;
127 rawTorque = forceSensor->
torque;
152 if (
c.enableSafeGuardForce and resetForceGuard.load())
154 safeGuardForceOffset = filteredForceInRoot;
155 safeGuardEnabledForce.store(
true);
156 resetForceGuard.store(
false);
158 if (
c.enableSafeGuardTorque and resetTorqueGuard.load())
160 safeGuardTorqueOffset = filteredTorqueInRoot;
161 safeGuardEnabledTorque.store(
true);
162 resetTorqueGuard.store(
false);
169 if (enableForceGuard)
171 resetForceGuard.store(
true);
173 if (enableTorqueGuard)
175 resetTorqueGuard.store(
true);
182 return safeGuardEnabledForce.load();
188 return safeGuardEnabledTorque.load();
195 (
c.enableSafeGuardForce and
196 (filteredForceInRoot - safeGuardForceOffset).norm() >
c.safeGuardForceThreshold) or
197 (
c.enableSafeGuardTorque and
198 (filteredTorqueInRoot - safeGuardTorqueOffset).norm() >
c.safeGuardTorqueThreshold);
199 ftSafe.store(not unsafeFlag);
209 forceOffset = (1 -
c.ftFilter) * forceOffset +
210 c.ftFilter * (forceSensor->
force -
211 sensorOriInRoot.transpose() * tcpGravityCompensation.head(3));
212 torqueOffset = (1 -
c.ftFilter) * torqueOffset +
213 c.ftFilter * (forceSensor->
torque -
214 sensorOriInRoot.transpose() * tcpGravityCompensation.tail(3));
216 timeForCalibration = timeForCalibration + deltaT;
217 if (timeForCalibration >
c.timeLimit)
222 "FT calibration done \n"
223 "-- force offset: [%.2f, %.2f, %.2f] \n"
224 "-- torque offset: [%.2f, %.2f, %.2f] \n"
225 "-- gravity compensation: [%.2f, %.2f, %.2f, %.2f, %.2f, %.2f]",
232 tcpGravityCompensation(0),
233 tcpGravityCompensation(1),
234 tcpGravityCompensation(2),
235 tcpGravityCompensation(3),
236 tcpGravityCompensation(4),
237 tcpGravityCompensation(5));
265 if (
c.enableTCPGravityCompensation)
268 tcpGravForceVec = tcpMass * gravity.head(3);
269 tcpGravTorqueVec = (sensorOriInRoot * tcpCoMInFTSensorFrame).
cross(tcpGravForceVec);
276 tcpGravityCompensation.head(3) = tcpGravForceVec;
277 tcpGravityCompensation.tail(3) = tcpGravTorqueVec;
281 tcpGravityCompensation.setZero();
283 return tcpGravityCompensation;
289 filteredForce = (1 -
c.ftFilter) * filteredForce +
c.ftFilter * rawForce;
290 filteredTorque = (1 -
c.ftFilter) * filteredTorque +
c.ftFilter * rawTorque;
292 filteredForceInRoot = sensorOriInRoot * (filteredForce - forceOffset) -
293 tcpGravityCompensation.head(3) -
c.forceBaseline;
294 filteredTorqueInRoot = sensorOriInRoot * (filteredTorque - torqueOffset) -
295 tcpGravityCompensation.tail(3) -
c.torqueBaseline;
297 for (
size_t i = 0; i < 3; ++i)
299 if (fabs(filteredForceInRoot(i)) >
c.deadZoneForce)
301 filteredForceInRoot(i) -=
302 (filteredForceInRoot(i) / fabs(filteredForceInRoot(i))) *
c.deadZoneForce;
306 filteredForceInRoot(i) = 0;
309 if (fabs(filteredTorqueInRoot(i)) >
c.deadZoneTorque)
311 filteredTorqueInRoot(i) -=
312 (filteredTorqueInRoot(i) / fabs(filteredTorqueInRoot(i))) *
c.deadZoneTorque;
316 filteredTorqueInRoot(i) = 0;
320 ft.head(3) = filteredForceInRoot;
321 ft.tail(3) = filteredTorqueInRoot;