AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
vehicleReachTask.cpp
1 #include "header/vehicleReachTask.h"
2 
10 VehicleReachTask::VehicleReachTask(int dim, bool eqType, std::string robotName, LinAngType linAngType)
11  : Task(dim, eqType, robotName, "VEHICLE_REACH_GOAL") {
12  gain = 0.2;
13  this->linAngType = linAngType;
14 }
15 
21 int VehicleReachTask::updateMatrices(struct Infos* const robInfo){
22 
23  setActivation();
24  setJacobian(robInfo->robotState.wTv_eigen);
25  setReference(robInfo->robotState.wTv_eigen, robInfo->transforms.wTgoalVeh_eigen);
26  return 0;
27 }
28 
29 int VehicleReachTask::setJacobian(Eigen::Matrix4d wTv_eigen){
30 
31  Eigen::Matrix<double, 3, TOT_DOF> jacobianLIN_eigen = Eigen::Matrix<double, 3, TOT_DOF>::Zero();
32  Eigen::Matrix<double, 3, TOT_DOF> jacobianANG_eigen = Eigen::Matrix<double, 3, TOT_DOF>::Zero();
33 
34  Eigen::Matrix3d wRv_eigen = wTv_eigen.topLeftCorner(3,3);
35 
36  //matrix([1:6];[1:4]) joint part must be zero
37  //matrix([1:3];[5:7]) linear part
38  if (linAngType == LINEAR || linAngType == LIN_ANG || linAngType == YAXIS){
39  jacobianLIN_eigen.block<3,3>(0,4) = wRv_eigen; //block: <dimensions> & (beginning row, beginning column)
40  }
41  //matrix([4:6];[8:10]) angular
42  //according to eigen doc, using these kind of specific function (and not
43  //.block) improves performance
44  if (linAngType == ANGULAR || linAngType == LIN_ANG){
45  jacobianANG_eigen.bottomRightCorner(3,3) = wRv_eigen;
46  }
47 
48  //to cmat
49  switch (linAngType){
50  case LINEAR:
51  this->J = CMAT::Matrix(dimension, dof, jacobianLIN_eigen.data());
52  break;
53  case ANGULAR:
54  this->J = CMAT::Matrix(dimension, dof, jacobianANG_eigen.data());
55  break;
56  case YAXIS:
57  this->J = CONV::matrix_eigen2cmat(jacobianLIN_eigen.row(1));
58  break;
59  case LIN_ANG:
60  Eigen::Matrix<double, 6, TOT_DOF> jacobian_eigen = Eigen::Matrix<double, 6, TOT_DOF>::Zero();
61  jacobian_eigen.topRows(3) = jacobianLIN_eigen;
62  jacobian_eigen.bottomRows(3) = jacobianANG_eigen;
63  this->J = CONV::matrix_eigen2cmat(jacobian_eigen);
64  break;
65 
66  }
67 
68  //J.PrintMtx("JACOB"); ///DEBUG
69 
70 }
71 
72 int VehicleReachTask::setActivation(){
73 
74  double vectDiag[dimension];
75  std::fill_n(vectDiag, dimension, 1);
76  this->A.SetDiag(vectDiag);
77 
78  return 0;
79 }
80 
81 int VehicleReachTask::setReference(
82  Eigen::Matrix4d wTv_eigen, Eigen::Matrix4d wTg_eigen){
83 
84  CMAT::TransfMatrix wTv_cmat = CONV::matrix_eigen2cmat(wTv_eigen);
85  CMAT::TransfMatrix wTg_cmat = CONV::matrix_eigen2cmat(wTg_eigen);
86  CMAT::Vect6 errorSwapped = CMAT::CartError(wTg_cmat, wTv_cmat); //ang,lin
87 
88 
89  // ang and lin must be swapped because in yDot and jacob the linear part is before
90  switch (linAngType){
91  case LINEAR:
92  error(1) = errorSwapped(4);
93  error(2) = errorSwapped(5);
94  error(3) = errorSwapped(6);
95  break;
96  case ANGULAR:
97  error(1) = errorSwapped(1);
98  error(2) = errorSwapped(2);
99  error(3) = errorSwapped(3);
100  break;
101  case LIN_ANG:
102  error(1) = errorSwapped(4);
103  error(2) = errorSwapped(5);
104  error(3) = errorSwapped(6);
105  error(4) = errorSwapped(1);
106  error(5) = errorSwapped(2);
107  error(6) = errorSwapped(3);
108  case YAXIS:
109  error(1) = errorSwapped(5);
110  break;
111  }
112 
113  this->reference = this->gain * (this->error);
114 }
int updateMatrices(struct Infos *const robInfo)
VehicleReachTask::updateMatrices overriden of the pure virtual method of Task parent class...
VehicleReachTask(int dimension, bool eqType, std::string robotName, LinAngType linAngType)
VehicleReachTask::VehicleReachTask Constructor of specific task simply calls the parent constructor t...
Definition: infos.h:117
Eigen::Matrix4d wTv_eigen
Transforms.
Definition: infos.h:34
ABSTRACT class task. Each task is a derived class of this class. It contains all the variable that th...
Definition: task.h:17