@@ -4,41 +4,25 @@ namespace lbr_fri_ros2 {
4
4
FTEstimator::FTEstimator (const std::string &robot_description, const std::string &chain_root,
5
5
const std::string &chain_tip, const_cart_array_t_ref f_ext_th)
6
6
: f_ext_th_(f_ext_th) {
7
- if (!kdl_parser::treeFromString (robot_description, tree_)) {
8
- std::string err = " Failed to construct kdl tree from robot description." ;
9
- RCLCPP_ERROR (rclcpp::get_logger (LOGGER_NAME), err.c_str ());
10
- throw std::runtime_error (err);
11
- }
12
- if (!tree_.getChain (chain_root, chain_tip, chain_)) {
13
- std::string err = " Failed to construct kdl chain from robot description." ;
14
- RCLCPP_ERROR (rclcpp::get_logger (LOGGER_NAME), err.c_str ());
15
- throw std::runtime_error (err);
16
- }
17
- jacobian_solver_ = std::make_unique<KDL::ChainJntToJacSolver>(chain_);
18
- fk_solver_ = std::make_unique<KDL::ChainFkSolverPos_recursive>(chain_);
19
- jacobian_.resize (KUKA::FRI::LBRState::NUMBER_OF_JOINTS);
20
- q_.resize (KUKA::FRI::LBRState::NUMBER_OF_JOINTS);
21
-
7
+ kinematics_ = std::make_unique<Kinematics>(robot_description, chain_root, chain_tip);
22
8
reset ();
23
9
}
24
10
25
11
void FTEstimator::compute (const_jnt_pos_array_t_ref measured_joint_position,
26
12
const_ext_tau_array_t_ref external_torque, cart_array_t_ref f_ext,
27
13
const double &damping) {
28
- q_.data = Eigen::Map<const Eigen::Matrix<double , KUKA::FRI::LBRState::NUMBER_OF_JOINTS, 1 >>(
29
- measured_joint_position.data ());
30
14
tau_ext_ = Eigen::Map<const Eigen::Matrix<double , KUKA::FRI::LBRState::NUMBER_OF_JOINTS, 1 >>(
31
15
external_torque.data ());
32
- jacobian_solver_-> JntToJac (q_, jacobian_ );
33
- jacobian_inv_ = pinv (jacobian_ .data , damping);
16
+ auto jacobian = kinematics_-> compute_jacobian (measured_joint_position );
17
+ jacobian_inv_ = pinv (jacobian .data , damping);
34
18
f_ext_ = jacobian_inv_.transpose () * tau_ext_;
35
19
36
20
// rotate into chain tip frame
37
- fk_solver_-> JntToCart (q_, chain_tip_frame_ );
38
- f_ext_.topRows (3 ) = Eigen::Matrix3d::Map (chain_tip_frame_ .M .data ) * f_ext_.topRows (3 );
39
- f_ext_.bottomRows (3 ) = Eigen::Matrix3d::Map (chain_tip_frame_ .M .data ) * f_ext_.bottomRows (3 );
21
+ auto chain_tip_frame = kinematics_-> compute_fk (measured_joint_position );
22
+ f_ext_.topRows (3 ) = Eigen::Matrix3d::Map (chain_tip_frame .M .data ) * f_ext_.topRows (3 );
23
+ f_ext_.bottomRows (3 ) = Eigen::Matrix3d::Map (chain_tip_frame .M .data ) * f_ext_.bottomRows (3 );
40
24
41
- Eigen::Map<Eigen::Matrix<double , CARTESIAN_DOF, 1 >>(f_ext.data ()) = f_ext_;
25
+ Eigen::Map<Eigen::Matrix<double , Kinematics:: CARTESIAN_DOF, 1 >>(f_ext.data ()) = f_ext_;
42
26
43
27
// threshold force-torque
44
28
std::transform (f_ext.begin (), f_ext.end (), f_ext_th_.begin (), f_ext.begin (),
@@ -52,7 +36,6 @@ void FTEstimator::compute(const_jnt_pos_array_t_ref measured_joint_position,
52
36
}
53
37
54
38
void FTEstimator::reset () {
55
- q_.data .setZero ();
56
39
tau_ext_.setZero ();
57
40
f_ext_.setZero ();
58
41
}
0 commit comments