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 <Eigen/Core>
25 
26 #include <VirtualRobot/VirtualRobot.h>
27 
29 
30 #include <armarx/control/common/ft/aron/FTConfig.aron.generated.h>
31 
32 namespace armarx
33 {
36 } // namespace armarx
37 
39 {
40  /// TODO: this has to be moved to the robot model (e.g. the corresponding hand model)
41  /// The values below corresponds to the Armar-6 hands,
42  /// keep it here for now to continue working on controllers
44  {
45  float tcpMassRight = 1.16064;
46  Eigen::Vector3f tcpCoMInFTFrameRight{-0.00258287, -0.00108265, 0.09719};
47  float tcpMassLeft = 1.14715;
48  Eigen::Vector3f tcpCoMInFTFrameLeft{-0.00330519, 0.000470962, 0.100648};
49  };
50 
51  class FTSensor
52  {
53  public:
54  using FTConfig = arondto::FTConfig;
55 
56  FTSensor(){};
57  ~FTSensor(){};
58 
59  void initialize(const VirtualRobot::RobotNodeSetPtr& rns,
60  const armarx::RobotUnitPtr& robotUnit,
61  const FTConfig& c);
62  void reset();
63  void
64  updateStatus(const FTConfig& c, Eigen::Vector6f& currentFT, double deltaT, bool firstRun);
65  void resetSafeGuardOffset(const FTConfig& c);
66  void enableSafeGuard(bool enableForceGuard, bool enableTorqueGuard);
67  bool isForceGuardEnabled();
68  bool isTorqueGuardEnabled();
69  // bool isForceGuardEnabled();
70  // bool isTorqueGuardEnabled();
71  bool isSafe(const FTConfig& c);
72  bool calibrate(const FTConfig& c, double deltaT);
75 
76  std::atomic_bool calibrated{false};
77  std::atomic_bool ftSafe{true};
78 
79  Eigen::Vector3f& getSafeGuardForceOffset();
80 
81  private:
82  std::string sensorName;
83  std::string sensorFrame;
84 
85  FTCalibrateDefaultValue calibDefaults;
86 
87  const SensorValueForceTorque* forceSensor;
88  VirtualRobot::RobotNodePtr sensorNode;
89 
90  Eigen::Vector6f tcpGravityCompensation;
91  Eigen::Vector6f ft;
92 
93  /// local variables
94  float tcpMass = 0.0f;
95  Eigen::Vector3f tcpCoMInFTSensorFrame;
96 
97  Eigen::Matrix3f sensorOriInRoot;
98 
99  /// for filtering and calibration
100  Eigen::Vector3f forceOffset;
101  Eigen::Vector3f torqueOffset;
102  Eigen::Vector3f filteredForce;
103  Eigen::Vector3f filteredTorque;
104  Eigen::Vector3f rawForce;
105  Eigen::Vector3f rawTorque;
106  Eigen::Vector3f filteredForceInRoot;
107  Eigen::Vector3f filteredTorqueInRoot;
108  Eigen::Vector3f safeGuardForceOffset;
109  Eigen::Vector3f safeGuardTorqueOffset;
110  std::atomic_bool safeGuardEnabledForce{false};
111  std::atomic_bool safeGuardEnabledTorque{false};
112  std::atomic_bool resetForceGuard{false};
113  std::atomic_bool resetTorqueGuard{false};
114  float timeForCalibration;
115 
116 
117  /// for gravity compensation
118  Eigen::Vector3f gravity{0.0, 0.0, -9.8};
119  Eigen::Vector3f tcpGravForceVec;
120  Eigen::Vector3f tcpGravTorqueVec;
121 
122  Eigen::Matrix4f forceFrameInTCP = Eigen::Matrix4f::Identity();
123  Eigen::Vector3f tcpCoMInTCPFrame;
124  };
125 } // 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:23
armarx::control::common::ft::FTSensor::isSafe
bool isSafe(const FTConfig &c)
Definition: FTSensor.cpp:198
armarx::control::common::ft::FTSensor::resetSafeGuardOffset
void resetSafeGuardOffset(const FTConfig &c)
Definition: FTSensor.cpp:154
armarx::control::common::ft::FTCalibrateDefaultValue::tcpMassRight
float tcpMassRight
Definition: FTSensor.h:45
armarx::control::common::ft::FTSensor::getSafeGuardForceOffset
Eigen::Vector3f & getSafeGuardForceOffset()
Definition: FTSensor.cpp:332
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::common::ft::FTSensor::FTConfig
arondto::FTConfig FTConfig
Definition: FTSensor.h:54
armarx::control::common::ft::FTSensor::enableSafeGuard
void enableSafeGuard(bool enableForceGuard, bool enableTorqueGuard)
Definition: FTSensor.cpp:173
armarx::control::common::ft
This file is part of ArmarX.
Definition: aron_conversions.cpp:29
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::control::common::ft::FTSensor::isForceGuardEnabled
bool isForceGuardEnabled()
Definition: FTSensor.cpp:186
armarx::control::common::ft::FTCalibrateDefaultValue::tcpCoMInFTFrameRight
Eigen::Vector3f tcpCoMInFTFrameRight
Definition: FTSensor.h:46
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::control::common::ft::FTSensor::FTSensor
FTSensor()
Definition: FTSensor.h:56
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::control::common::ft::FTSensor::ftSafe
std::atomic_bool ftSafe
Definition: FTSensor.h:77
armarx::control::common::ft::FTSensor::calibrated
std::atomic_bool calibrated
Definition: FTSensor.h:76
armarx::control::common::ft::FTCalibrateDefaultValue::tcpCoMInFTFrameLeft
Eigen::Vector3f tcpCoMInFTFrameLeft
Definition: FTSensor.h:48
armarx::control::common::ft::FTCalibrateDefaultValue
TODO: this has to be moved to the robot model (e.g.
Definition: FTSensor.h:43
armarx::control::common::ft::FTSensor::reset
void reset()
Definition: FTSensor.cpp:91
armarx::control::common::ft::FTSensor::updateStatus
void updateStatus(const FTConfig &c, Eigen::Vector6f &currentFT, double deltaT, bool firstRun)
Definition: FTSensor.cpp:119
armarx::control::common::ft::FTSensor::getFilteredForceTorque
Eigen::Vector6f & getFilteredForceTorque(const FTConfig &data)
Definition: FTSensor.cpp:293
IceUtil::Handle< class RobotUnit >
armarx::control::common::ft::FTSensor::calibrate
bool calibrate(const FTConfig &c, double deltaT)
Definition: FTSensor.cpp:211
armarx::control::common::ft::FTCalibrateDefaultValue::tcpMassLeft
float tcpMassLeft
Definition: FTSensor.h:47
Eigen::Matrix< float, 6, 1 >
armarx::control::common::ft::FTSensor::~FTSensor
~FTSensor()
Definition: FTSensor.h:57
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::SensorValueForceTorque
Definition: SensorValueForceTorque.h:32
EigenForwardDeclarations.h
armarx::control::common::ft::FTSensor
Definition: FTSensor.h:51
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::control::common::ft::FTSensor::isTorqueGuardEnabled
bool isTorqueGuardEnabled()
Definition: FTSensor.cpp:192
armarx::control::common::ft::FTSensor::compensateTCPGravity
Eigen::Vector6f & compensateTCPGravity(const FTConfig &data)
Definition: FTSensor.cpp:264