99#include < eigen3/Eigen/Geometry>
1010#include < memory>
1111#include < optional>
12- #include < string>
13-
1412#include < pinocchio/algorithm/frames.hpp>
1513#include < pinocchio/algorithm/jacobian.hpp>
1614#include < pinocchio/algorithm/joint-configuration.hpp>
1715#include < pinocchio/algorithm/kinematics.hpp>
1816#include < pinocchio/parsers/mjcf.hpp>
1917#include < pinocchio/parsers/urdf.hpp>
18+ #include < string>
2019
2120namespace rcs {
2221namespace so101 {
2322
2423class SO101IK : public rcs ::common::Kinematics {
25- private:
24+ private:
2625 const double eps = 1e-4 ;
2726 const int IT_MAX = 1000 ;
2827 const double DT = 1e-1 ;
@@ -35,7 +34,8 @@ class SO101IK : public rcs::common::Kinematics {
3534 pinocchio::Data data;
3635
3736 public:
38- SO101IK (const std::string& path, const std::string& frame_id, bool urdf = true )
37+ SO101IK (const std::string& path, const std::string& frame_id,
38+ bool urdf = true )
3939 : model() {
4040 if (urdf) {
4141 pinocchio::urdf::buildModel (path, this ->model );
@@ -53,10 +53,12 @@ class SO101IK : public rcs::common::Kinematics {
5353 const rcs::common::Pose& pose, const rcs::common::VectorXd& q0,
5454 const rcs::common::Pose& tcp_offset =
5555 rcs::common::Pose::Identity ()) override {
56- // --- Tunables (could be class members) ------------------------------------
57- const double WP = 1.0 ; // position weight
58- const double WO = 0.12 ; // orientation (pitch+yaw) weight
59- const double WO_ROLL = 0.03 ; // orientation roll weight (let it "float" more)
56+ // --- Tunables (could be class members)
57+ // ------------------------------------
58+ const double WP = 1.0 ; // position weight
59+ const double WO = 0.12 ; // orientation (pitch+yaw) weight
60+ const double WO_ROLL =
61+ 0.03 ; // orientation roll weight (let it "float" more)
6062 const double ORI_TOL = 5.0 * M_PI / 180.0 ; // 5 deg tolerance (dead-zone)
6163 const double ORI_CAP =
6264 0.6 ; // cap on |eo| scaling (rad/s-equivalent per iter)
@@ -78,7 +80,7 @@ class SO101IK : public rcs::common::Kinematics {
7880 bool success = false ;
7981
8082 // Pre-allocations
81- rcs::common::Vector6d err, err_w; // 6x1
83+ rcs::common::Vector6d err, err_w; // 6x1
8284 Eigen::Vector3d ep, eo; // position/orientation parts
8385 Eigen::VectorXd v (model.nv ); // nv x 1
8486 pinocchio::Data::Matrix6 JJt; // 6x6
@@ -106,8 +108,9 @@ class SO101IK : public rcs::common::Kinematics {
106108 ep = err.head <3 >();
107109 eo = err.tail <3 >();
108110
109- // ---- Orientation tolerance (dead-zone + soft cap) ----------------------
110- // If |eo| is small, ignore it completely (prevents twitch).
111+ // ---- Orientation tolerance (dead-zone + soft cap)
112+ // ---------------------- If |eo| is small, ignore it completely (prevents
113+ // twitch).
111114 const double eo_norm = eo.norm ();
112115 if (eo_norm < ORI_TOL ) {
113116 eo.setZero ();
@@ -140,9 +143,10 @@ class SO101IK : public rcs::common::Kinematics {
140143 pinocchio::Jlog6 (iMd.inverse (), Jlog);
141144 J = -Jlog * J; // tangent-space Jacobian for the error you’re minimizing
142145
143- // ---- Weighted damped least-squares -------------------------------------
144- // Apply sqrt-weights on rows: this prioritizes translation > orientation,
145- // and de-weights tool roll further.
146+ // ---- Weighted damped least-squares
147+ // ------------------------------------- Apply sqrt-weights on rows: this
148+ // prioritizes translation > orientation, and de-weights tool roll
149+ // further.
146150 const auto Jw = Wsqrt * J; // 6xnv
147151 err_w = Wsqrt * err; // 6x1
148152
@@ -168,10 +172,11 @@ class SO101IK : public rcs::common::Kinematics {
168172 v.noalias () = -Jw.transpose () * JJt.ldlt ().solve (err_w);
169173 // ------------------------------------------------------------------------
170174
171- // ---- Step-size limiter in task space to avoid sudden jumps -------------
172- // Predict task step and scale if too large
175+ // ---- Step-size limiter in task space to avoid sudden jumps
176+ // ------------- Predict task step and scale if too large
173177 Eigen::Matrix<double , 6 , 1 > task_step = J * v * this ->DT ;
174- double step_norm = task_step.head <3 >().norm () + task_step.tail <3 >().norm ();
178+ double step_norm =
179+ task_step.head <3 >().norm () + task_step.tail <3 >().norm ();
175180 if (step_norm > STEP_CAP && step_norm > 1e-9 ) {
176181 const double scale = STEP_CAP / step_norm;
177182 v *= scale;
@@ -199,7 +204,7 @@ class SO101IK : public rcs::common::Kinematics {
199204 q.head (q0.size ()) = q0;
200205 pinocchio::framesForwardKinematics (model, data, q);
201206 rcs::common::Pose pose (data.oMf [this ->FRAME_ID ].rotation (),
202- data.oMf [this ->FRAME_ID ].translation ());
207+ data.oMf [this ->FRAME_ID ].translation ());
203208
204209 // apply the tcp offset
205210 return pose * tcp_offset.inverse ();
0 commit comments