1 #include "header/forceInsertTask.h" 10 :
Task(dim, eqType, robotName,
"FORCE_INSERTION"){
32 int ForceInsertTask::updateMatrices(
Infos*
const robInfo){
34 Eigen::Vector3d force = robInfo->robotSensor.forcePegTip;
35 Eigen::Vector3d torque = robInfo->robotSensor.torquePegTip;
37 Eigen::Vector3d w_force = robInfo->transforms.wTt_eigen.topLeftCorner<3,3>() * force;
38 Eigen::Vector3d w_torque = robInfo->transforms.wTt_eigen.topLeftCorner<3,3>() * torque;
40 setActivation(w_force, w_torque);
41 setJacobian(robInfo->robotState.w_Jtool_robot, w_force, w_torque);
42 setReference(w_force, w_torque);
54 void ForceInsertTask::setActivation(Eigen::Vector3d force, Eigen::Vector3d torque){
56 double vectDiag[dimension];
57 std::fill_n(vectDiag, dimension, 1);
58 this->A.SetDiag(vectDiag);
62 double negValueForActMax = -1;
63 double posValueForActMax = 2;
64 double negValueForAct = -0.001;
65 double posValueForAct = 0.001;
69 double forceNorm = force.norm();
70 A(1,1) = CMAT::DecreasingBellShapedFunction(negValueForActMax, negValueForAct,
72 CMAT::IncreasingBellShapedFunction(posValueForAct, posValueForActMax ,
77 double forceNorm = force.norm();
78 double torqueNorm = torque.norm();
81 A(1,1) = CMAT::IncreasingBellShapedFunction(posValueForAct, posValueForActMax ,
84 A(2,2) = CMAT::IncreasingBellShapedFunction(posValueForAct, posValueForActMax ,
91 for (
int i=1; i<=dimension; i++){
92 A(i,i) = CMAT::DecreasingBellShapedFunction(negValueForActMax, negValueForAct,
94 CMAT::IncreasingBellShapedFunction(posValueForAct, posValueForActMax,
100 for (
int i=1; i<=3; i++){
101 A(i,i) = CMAT::DecreasingBellShapedFunction(negValueForActMax, negValueForAct,
103 CMAT::IncreasingBellShapedFunction(posValueForAct, posValueForActMax,
107 for (
int i=4; i<=6; i++){
108 A(i,i) = CMAT::DecreasingBellShapedFunction(negValueForActMax, negValueForAct,
110 CMAT::IncreasingBellShapedFunction(posValueForAct, posValueForActMax,
119 void ForceInsertTask::setJacobian(Eigen::Matrix<double, 6, TOT_DOF> w_J_robot,
120 Eigen::Vector3d force, Eigen::Vector3d torque){
126 Eigen::Vector3d normalForce;
127 double normForce = force.norm();
128 if (normForce > 0.001) {
129 normalForce = force/normForce;
131 normalForce << 0,0,0;
135 w_J_robot.topRows<3>().topRightCorner<3,6>() = Eigen::MatrixXd::Zero(3, 6);
136 J = CONV::matrix_eigen2cmat(
137 (normalForce.transpose()) * (w_J_robot.topRows<3>()));
145 Eigen::MatrixXd jacobTemp = Eigen::MatrixXd::Zero(dimension, dof);
148 Eigen::Vector3d normalForce;
149 double normForce = force.norm();
151 normalForce = force/normForce;
153 normalForce << 0,0,0;
158 jacobTemp.topRows<1>() = - (normalForce.transpose()) * (w_J_robot.topRows<3>());
161 Eigen::Vector3d normalTorque;
162 double normTorque = torque.norm();
163 if (normTorque > 0) {
164 normalTorque = torque/normTorque;
166 normalTorque << 0,0,0;
169 jacobTemp.bottomRows<1>() = - (normalTorque.transpose()) * (w_J_robot.bottomRows<3>());
172 J = CONV::matrix_eigen2cmat(jacobTemp);
178 J = CONV::matrix_eigen2cmat(w_J_robot.topRows<3>());
182 J = CONV::matrix_eigen2cmat(w_J_robot);
191 void ForceInsertTask::setReference(Eigen::Vector3d force, Eigen::Vector3d torque){
195 error(1) = 0 - force.norm();
196 reference = gain * error;
197 reference = FRM::saturateCmat(reference, 0.05);
203 error(1) = - force.norm();
205 reference(1) = gain*(error(1));
206 reference(1) = FRM::saturateScalar(reference(1), 0.04);
209 error(2) = - torque.norm();
210 reference(2) = gainAng * error(2);
211 reference(2) = FRM::saturateScalar(reference(2), 0.04);
217 error = -1 * CONV::matrix_eigen2cmat(force);
218 reference = gain * error;
219 reference = FRM::saturateCmat(reference, 0.1);
226 CMAT::Vect3 force_cmat = CONV::matrix_eigen2cmat(force);
227 CMAT::Vect3 torque_cmat = CONV::matrix_eigen2cmat(torque);
228 error(1) = ( - force_cmat(1));
229 error(2) = ( - force_cmat(2));
230 error(3) = ( - force_cmat(3));
231 error(4) = ( - torque_cmat(1));
232 error(5) = ( - torque_cmat(2));
233 error(6) = ( - torque_cmat(3));
234 reference(1) = gain * ( - force_cmat(1));
235 reference(2) = gain * ( - force_cmat(2));
236 reference(3) = gain * ( - force_cmat(3));
237 reference(4) = gainAng * ( - torque_cmat(1));
238 reference(5) = gainAng * ( - torque_cmat(2));
239 reference(6) = gainAng * ( - torque_cmat(3));
240 reference = FRM::saturateCmat(reference, 0.001);
244 std::cerr <<
"[" << taskName <<
"] DIMENSION OF TASK IS WRONG\n";
ForceInsertTask(int dimension, bool eqType, std::string robotName)
ForceInsertTask::ForceInsertTask.
ABSTRACT class task. Each task is a derived class of this class. It contains all the variable that th...