@@ -63,15 +63,20 @@ CartesianController::update(const rclcpp::Time &time,
6363 model_.getJointId (joint_name); // pinocchio joind id might be different
6464 auto joint = model_.joints [joint_id];
6565
66+ /* q[i] = exponential_moving_average(q[i], state_interfaces_[i].get_value(),*/
67+ /* params_.filter.q);*/
6668 q[i] = state_interfaces_[i].get_value ();
67- if (continous_joint_types.count (joint.shortname ())) {
68- // Then we are handling a continous joint that is SO(2)
69+ if (continous_joint_types.count (
70+ joint.shortname ())) { // Then we are handling a continous
71+ // joint that is SO(2)
6972 q_pin[joint.idx_q ()] = std::cos (q[i]);
7073 q_pin[joint.idx_q () + 1 ] = std::sin (q[i]);
71- } else {
72- // simple revolute joint case
74+ } else { // simple revolute joint case
7375 q_pin[joint.idx_q ()] = q[i];
7476 }
77+ /* dq[i] = exponential_moving_average(*/
78+ /* dq[i], state_interfaces_[num_joints + i].get_value(),*/
79+ /* params_.filter.dq);*/
7580 dq[i] = state_interfaces_[num_joints + i].get_value ();
7681 }
7782
@@ -89,16 +94,24 @@ CartesianController::update(const rclcpp::Time &time,
8994 pinocchio::log6 (target_pose_), pinocchio::log6 (new_target_pose),
9095 params_.filter .target_pose ));
9196
97+ /* target_pose_ = pinocchio::SE3(target_orientation_.toRotationMatrix(),
98+ * target_position_);*/
9299 end_effector_pose = data_.oMf [end_effector_frame_id];
93- const pinocchio::SE3 base_frame_pose = data_.oMf [base_frame_id];
94-
95- end_effector_pose_b = base_frame_pose.inverse () * end_effector_pose;
96100
97101 // We consider translation and rotation separately to avoid unatural screw
98102 // motions
99- error.head (3 ) = target_pose_.translation () - end_effector_pose_b.translation ();
100- error.tail (3 ) = pinocchio::log3 (target_pose_.rotation () * end_effector_pose_b.rotation ().transpose ());
101-
103+ if (params_.use_local_jacobian ) {
104+ error.head (3 ) =
105+ end_effector_pose.rotation ().transpose () *
106+ (target_pose_.translation () - end_effector_pose.translation ());
107+ error.tail (3 ) = pinocchio::log3 (end_effector_pose.rotation ().transpose () *
108+ target_pose_.rotation ());
109+ } else {
110+ error.head (3 ) =
111+ target_pose_.translation () - end_effector_pose.translation ();
112+ error.tail (3 ) = pinocchio::log3 (target_pose_.rotation () *
113+ end_effector_pose.rotation ().transpose ());
114+ }
102115
103116 if (params_.limit_error ) {
104117 max_delta_ << params_.task .error_clip .x , params_.task .error_clip .y , params_.task .error_clip .z ,
@@ -107,19 +120,11 @@ CartesianController::update(const rclcpp::Time &time,
107120 }
108121
109122 J.setZero ();
110- if (params_.use_local_jacobian ) {
111- Eigen::MatrixXd J_local (6 , model_.nv );
112- pinocchio::computeFrameJacobian (model_, data_, q_pin, end_effector_frame_id,
113- pinocchio::ReferenceFrame::LOCAL, J_local);
114- const Eigen::Matrix<double ,6 ,6 > Ad_be = end_effector_pose_b.toActionMatrix ();
115- J.noalias () = Ad_be * J_local;
116- } else {
117- Eigen::MatrixXd J_world (6 , model_.nv );
118- pinocchio::computeFrameJacobian (model_, data_, q_pin, end_effector_frame_id,
119- pinocchio::ReferenceFrame::WORLD, J_world);
120- const Eigen::Matrix<double ,6 ,6 > Ad_bw = base_frame_pose.inverse ().toActionMatrix ();
121- J.noalias () = Ad_bw * J_world;
122- }
123+ auto reference_frame = params_.use_local_jacobian
124+ ? pinocchio::ReferenceFrame::LOCAL
125+ : pinocchio::ReferenceFrame::WORLD;
126+ pinocchio::computeFrameJacobian (model_, data_, q_pin, end_effector_frame_id,
127+ reference_frame, J);
123128
124129 Eigen::MatrixXd J_pinv (model_.nv , 6 );
125130 J_pinv = pseudo_inverse (J, params_.nullspace .regularization );
@@ -154,7 +159,7 @@ CartesianController::update(const rclcpp::Time &time,
154159 }
155160
156161 if (model_.nq != model_.nv ) {
157- // TODO: Joint liimits for continous joints not implemented yet
162+ // TODO: Then we have some continouts joints, not being handled for now
158163 tau_joint_limits = Eigen::VectorXd::Zero (model_.nv );
159164 } else {
160165 tau_joint_limits = get_joint_limit_torque (q, model_.lowerPositionLimit ,
@@ -192,6 +197,8 @@ CartesianController::update(const rclcpp::Time &time,
192197 if (params_.limit_torques ) {
193198 tau_d = saturateTorqueRate (tau_d, tau_previous, params_.max_delta_tau );
194199 }
200+ /* tau_d = exponential_moving_average(tau_d, tau_previous,*/
201+ /* params_.filter.output_torque);*/
195202
196203 if (not params_.stop_commands ) {
197204 for (size_t i = 0 ; i < num_joints; ++i) {
@@ -301,7 +308,6 @@ CallbackReturn CartesianController::on_configure(
301308 }
302309
303310 end_effector_frame_id = model_.getFrameId (params_.end_effector_frame );
304- base_frame_id = model_.getFrameId (params_.base_frame );
305311 q = Eigen::VectorXd::Zero (model_.nv );
306312 q_pin = Eigen::VectorXd::Zero (model_.nq );
307313 dq = Eigen::VectorXd::Zero (model_.nv );
@@ -471,13 +477,8 @@ CallbackReturn CartesianController::on_activate(
471477
472478 end_effector_pose = data_.oMf [end_effector_frame_id];
473479
474- const pinocchio::SE3 T_wb = data_.oMf [base_frame_id];
475- const pinocchio::SE3 T_bw = T_wb.inverse ();
476-
477- end_effector_pose_b = T_bw * end_effector_pose;
478-
479- target_position_ = end_effector_pose_b.translation ();
480- target_orientation_ = Eigen::Quaterniond (end_effector_pose_b.rotation ());
480+ target_position_ = end_effector_pose.translation ();
481+ target_orientation_ = Eigen::Quaterniond (end_effector_pose.rotation ());
481482 target_pose_ =
482483 pinocchio::SE3 (target_orientation_.toRotationMatrix (), target_position_);
483484
0 commit comments