FTSensor.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
17  * @date 2022
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <VirtualRobot/IK/DifferentialIK.h>
25 #include <VirtualRobot/Robot.h>
26 
29 
30 #include <armarx/control/common/ft/aron/FTConfig.aron.generated.h>
31 
33 {
34  /// TODO: this has to be moved to the robot model (e.g. the corresponding hand model)
35  /// The values below corresponds to the Armar-6 hands,
36  /// keep it here for now to continue working on controllers
38  {
39  float tcpMassRight = 1.16064;
40  Eigen::Vector3f tcpCoMInFTFrameRight{-0.00258287, -0.00108265, 0.09719};
41  float tcpMassLeft = 1.14715;
42  Eigen::Vector3f tcpCoMInFTFrameLeft{-0.00330519, 0.000470962, 0.100648};
43  };
44 
45  class FTSensor
46  {
47  public:
48  using FTConfig = arondto::FTConfig;
49 
50  FTSensor(){};
51  ~FTSensor(){};
52 
53  void initialize(const VirtualRobot::RobotNodeSetPtr& rns,
54  const armarx::RobotUnitPtr& robotUnit,
55  const FTConfig& c);
56  void reset();
57  void
58  updateStatus(const FTConfig& c, Eigen::Vector6f& currentFT, double deltaT, bool firstRun);
59  void resetSafeGuardOffset(const FTConfig& c);
60  void enableSafeGuard(bool enableForceGuard, bool enableTorqueGuard);
61  bool isForceGuardEnabled();
62  bool isTorqueGuardEnabled();
63  // bool isForceGuardEnabled();
64  // bool isTorqueGuardEnabled();
65  bool isSafe(const FTConfig& c);
66  bool calibrate(const FTConfig& c, double deltaT);
69 
70  std::atomic_bool calibrated{false};
71  std::atomic_bool ftSafe{true};
72 
73  private:
74  std::string sensorName;
75  std::string sensorFrame;
76 
77  FTCalibrateDefaultValue calibDefaults;
78 
79  const SensorValueForceTorque* forceSensor;
80  VirtualRobot::RobotNodePtr sensorNode;
81 
82  Eigen::Vector6f tcpGravityCompensation;
83  Eigen::Vector6f ft;
84 
85  /// local variables
86  float tcpMass = 0.0f;
87  Eigen::Vector3f tcpCoMInFTSensorFrame;
88 
89  Eigen::Matrix3f sensorOriInRoot;
90 
91  /// for filtering and calibration
92  Eigen::Vector3f forceOffset;
93  Eigen::Vector3f torqueOffset;
94  Eigen::Vector3f filteredForce;
95  Eigen::Vector3f filteredTorque;
96  Eigen::Vector3f rawForce;
97  Eigen::Vector3f rawTorque;
98  Eigen::Vector3f filteredForceInRoot;
99  Eigen::Vector3f filteredTorqueInRoot;
100  Eigen::Vector3f safeGuardForceOffset;
101  Eigen::Vector3f safeGuardTorqueOffset;
102  std::atomic_bool safeGuardEnabledForce{false};
103  std::atomic_bool safeGuardEnabledTorque{false};
104  std::atomic_bool resetForceGuard{false};
105  std::atomic_bool resetTorqueGuard{false};
106  float timeForCalibration;
107 
108 
109  /// for gravity compensation
110  Eigen::Vector3f gravity{0.0, 0.0, -9.8};
111  Eigen::Vector3f tcpGravForceVec;
112  Eigen::Vector3f tcpGravTorqueVec;
113 
114  Eigen::Matrix4f forceFrameInTCP = Eigen::Matrix4f::Identity();
115  Eigen::Vector3f tcpCoMInTCPFrame;
116  };
117 } // namespace armarx::control::common::ft
armarx::control::common::ft::FTSensor::initialize
void initialize(const VirtualRobot::RobotNodeSetPtr &rns, const armarx::RobotUnitPtr &robotUnit, const FTConfig &c)
Definition: FTSensor.cpp:19
armarx::control::common::ft::FTSensor::isSafe
bool isSafe(const FTConfig &c)
Definition: FTSensor.cpp:192
armarx::control::common::ft::FTSensor::resetSafeGuardOffset
void resetSafeGuardOffset(const FTConfig &c)
Definition: FTSensor.cpp:150
armarx::control::common::ft::FTCalibrateDefaultValue::tcpMassRight
float tcpMassRight
Definition: FTSensor.h:39
RobotUnit.h
armarx::control::common::ft::FTSensor::FTConfig
arondto::FTConfig FTConfig
Definition: FTSensor.h:48
armarx::control::common::ft::FTSensor::enableSafeGuard
void enableSafeGuard(bool enableForceGuard, bool enableTorqueGuard)
Definition: FTSensor.cpp:167
armarx::control::common::ft
This file is part of ArmarX.
Definition: aron_conversions.cpp:29
SensorValueForceTorque.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::control::common::ft::FTSensor::isForceGuardEnabled
bool isForceGuardEnabled()
Definition: FTSensor.cpp:180
armarx::control::common::ft::FTCalibrateDefaultValue::tcpCoMInFTFrameRight
Eigen::Vector3f tcpCoMInFTFrameRight
Definition: FTSensor.h:40
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::control::common::ft::FTSensor::FTSensor
FTSensor()
Definition: FTSensor.h:50
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::control::common::ft::FTSensor::ftSafe
std::atomic_bool ftSafe
Definition: FTSensor.h:71
armarx::control::common::ft::FTSensor::calibrated
std::atomic_bool calibrated
Definition: FTSensor.h:70
armarx::control::common::ft::FTCalibrateDefaultValue::tcpCoMInFTFrameLeft
Eigen::Vector3f tcpCoMInFTFrameLeft
Definition: FTSensor.h:42
armarx::control::common::ft::FTCalibrateDefaultValue
TODO: this has to be moved to the robot model (e.g.
Definition: FTSensor.h:37
armarx::control::common::ft::FTSensor::reset
void reset()
Definition: FTSensor.cpp:87
armarx::control::common::ft::FTSensor::updateStatus
void updateStatus(const FTConfig &c, Eigen::Vector6f &currentFT, double deltaT, bool firstRun)
Definition: FTSensor.cpp:115
armarx::control::common::ft::FTSensor::getFilteredForceTorque
Eigen::Vector6f & getFilteredForceTorque(const FTConfig &data)
Definition: FTSensor.cpp:287
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::common::ft::FTSensor::calibrate
bool calibrate(const FTConfig &c, double deltaT)
Definition: FTSensor.cpp:205
armarx::control::common::ft::FTCalibrateDefaultValue::tcpMassLeft
float tcpMassLeft
Definition: FTSensor.h:41
Eigen::Matrix< float, 6, 1 >
armarx::control::common::ft::FTSensor::~FTSensor
~FTSensor()
Definition: FTSensor.h:51
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:31
armarx::control::common::ft::FTSensor
Definition: FTSensor.h:45
armarx::control::common::ft::FTSensor::isTorqueGuardEnabled
bool isTorqueGuardEnabled()
Definition: FTSensor.cpp:186
armarx::control::common::ft::FTSensor::compensateTCPGravity
Eigen::Vector6f & compensateTCPGravity(const FTConfig &data)
Definition: FTSensor.cpp:258