Skip to content

Commit 10f8029

Browse files
committed
Damp z-axis rotation only, controller works
1 parent bf6bbd0 commit 10f8029

4 files changed

+18
-40
lines changed

robot_controller.cpp

+12-36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ BaseController::BaseController()
66
updateFreq = 10;
77
qEpsilon = 1e-5;
88
maxTimestep = 1e4;
9+
lambda_zero = 1000;
10+
manipul_th = 0.01;
911
PGain = 5e-3;
1012
}
1113

@@ -66,38 +68,26 @@ bool BaseController::PathPlanning(TendonRobot & robot, const Eigen::MatrixXd & t
6668
J_body.col(i) = J_bi;
6769
}
6870

69-
/* single segment */
70-
// assert(J_body.cols() == 3);
71-
// Eigen::MatrixXd J_body_pos = J_body.block(3, 0, 3, 3); // Position part only
72-
// Eigen::MatrixXd J_body_inv = J_body_pos.inverse();
73-
74-
/* 6dof robot, 6dof pose, using Damped Least Squares Method */
75-
// Note: Not calculating inverse directly, because Jacobian is in singularity for z-axis rotation at initial pose
76-
// Citation for damping factor calculation method:
77-
// Y. Nakamura and H. Hanafusa, Inverse kinematics solutions with singularity robustness for robot manipulator control
71+
/* 6-DOF pose using Damped Least Squares Method
72+
* Not calculating inverse directly, because Jacobian is always in singularity for z-axis rotation due to parallel tendon routing
73+
* Therefore, want to damp this DOF
74+
* This method works for 6-DOF or redundant robot
75+
* Citation for damping factor calculation method:
76+
* Y. Nakamura and H. Hanafusa, Inverse kinematics solutions with singularity robustness for robot manipulator control
77+
*/
7878
Eigen::MatrixXd JJT = J_body * J_body.transpose();
7979
// Note: use SVD to calculate determinant because determinant() is not working properly near singularity
80-
// double JJT_det = JJT.determinant();
8180
Eigen::JacobiSVD<Eigen::MatrixXd> svd(JJT);
8281
Eigen::VectorXd JJT_singVals = svd.singularValues();
8382
RoundValues(JJT_singVals, 1e-6); // Round the values to 1e-6 to prevent the case of very_large_double * very_small_double
8483
double JJT_det = JJT_singVals.prod();
8584
double manipul = sqrt(JJT_det); // Manipulability measure
86-
double manipul_th = 0.01; // Manipulability threshold
8785
double lambda = 0.0; // Damping factor
88-
double lambda_zero = 1000; // Maximum damping factor
8986
if (manipul < manipul_th)
9087
lambda = lambda_zero * pow((1 - manipul / manipul_th), 2);
91-
Eigen::MatrixXd J_body_pseudo = J_body.transpose() *
92-
(JJT + lambda * Eigen::Matrix<double,6,6>::Identity()).inverse(); // Right Pseudo Inverse
93-
94-
/* 6dof robot, 5dof pose, skip z-axis rotation */
95-
// Eigen::MatrixXd J_body_5dof(5, 6);
96-
// J_body_5dof.block(0, 0, 2, 6) = J_body.block(0, 0, 2, 6);
97-
// J_body_5dof.block(2, 0, 3, 6) = J_body.block(3, 0, 3, 6);
98-
// Eigen::MatrixXd J_body_pseudo = J_body_5dof.transpose() * (J_body_5dof * J_body_5dof.transpose()).inverse(); // Right Pseudo Inverse
99-
/* redundant 12dof (or 9dof) robot */
100-
// Eigen::MatrixXd J_body_pseudo = J_body.transpose() * (J_body * J_body.transpose()).inverse(); // Right Pseudo Inverse
88+
Eigen::Matrix<double,6,6> modDampingMat = Eigen::Matrix<double,6,6>::Zero();
89+
modDampingMat(2, 2) = 1; // Only damp the z-axis rotation
90+
Eigen::MatrixXd J_body_pseudo = J_body.transpose() * (JJT + lambda * modDampingMat).inverse(); // Right Pseudo Inverse
10191

10292
Eigen::Matrix4d T_body_desired = T_cur.inverse() * T_target;
10393
double theta;
@@ -106,22 +96,8 @@ bool BaseController::PathPlanning(TendonRobot & robot, const Eigen::MatrixXd & t
10696
twist << S_skew(2,1), S_skew(0,2), S_skew(1,0), // omega components
10797
S_skew(0,3), S_skew(1,3), S_skew(2,3); // v components
10898
twist *= theta; // S is normalized, multiply by theta to get twist
109-
110-
/* single segment */
111-
// Eigen::VectorXd twist_v = twist.tail(3);
112-
// Eigen::VectorXd q_dot = J_body_inv * twist_v;
11399

114-
/* 6dof robot, 6dof pose */
115100
Eigen::VectorXd q_dot = J_body_pseudo * twist;
116-
117-
/* 6dof robot, 5dof pose, skip z-axis rotation */
118-
// Eigen::VectorXd twist_5dof(5);
119-
// twist_5dof.head(2) = twist.head(2);
120-
// twist_5dof.tail(3) = twist.tail(3);
121-
// Eigen::VectorXd q_dot = J_body_pseudo * twist_5dof;
122-
/* redundant 12dof (or 9dof) robot */
123-
// Eigen::VectorXd q_dot = J_body_pseudo * twist;
124-
125101
q_cur = q_cur + q_dot * PGain; // TODO: Time step length?
126102
UnpackRobotConfig(robot, numTendon, q_cur, curTendonLengthChange, curSegLength);
127103
T_cur = robot.CalcTipPose(curTendonLengthChange, curSegLength);

robot_controller.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class BaseController
1717
int calcFreq, updateFreq;
1818
double qEpsilon; // small change in q when estimating Jacobian
1919
int maxTimestep;
20+
double lambda_zero; // Maximum damping factor
21+
double manipul_th; // Manipulability threshold
2022
double PGain; // Proportional gain
2123

2224
Eigen::Matrix4d MatrixLog(const Eigen::Matrix4d & T, double & theta);

tendon_robot.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <QDomElement>
77
#include <Eigen/Dense>
88

9-
#define EPSILON 1e-7
9+
#define EPSILON 1e-9
1010

1111
class TendonRobot
1212
{

vtk_visualizer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ VtkVisualizer::VtkVisualizer(std::vector<TendonRobot> & robots)
2424
originAxes = vtkSmartPointer<vtkAxesActor>::New();
2525
originAxes->SetTotalLength(0.01, 0.01, 0.01);
2626
originAxes->SetShaftTypeToCylinder();
27-
originAxes->SetCylinderRadius(0.08);
28-
originAxes->SetConeRadius(0.4);
27+
originAxes->SetCylinderRadius(0.06);
28+
originAxes->SetConeRadius(0.5);
2929
originAxes->AxisLabelsOff();
3030

3131
renderer = vtkSmartPointer<vtkRenderer>::New();
@@ -163,7 +163,7 @@ VtkVisualizer::TACRVisual::TACRVisual(TendonRobot & robot)
163163
targetAxes = vtkSmartPointer<vtkAxesActor>::New();
164164
setAxesStyle(baseAxes, 0.02, 0.03, 0.3);
165165
setAxesStyle(tipAxes, 0.02, 0.03, 0.3);
166-
setAxesStyle(targetAxes, 0.01, 0.08, 0.4);
166+
setAxesStyle(targetAxes, 0.01, 0.06, 0.5);
167167
}
168168

169169
void VtkVisualizer::TACRVisual::setAxesStyle(vtkSmartPointer<vtkAxesActor> axes, double axisLength, double cylinderRadius, double coneRadius)

0 commit comments

Comments
 (0)