AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
horizontalAttitudeTask.cpp
1 #include "header/horizontalAttitudeTask.h"
2 
3 HorizontalAttitudeTask::HorizontalAttitudeTask(int dim, bool eqType, std::string robotName)
4  : Task(dim, eqType, robotName, "HORIZONTAL_ATTITUDE"){
5 
6  if (dimension != 1){
7  std::cerr << "[" << robotName << "][" << taskName << "] ERROR, this task is intended to be a scalar one, "<<
8  "you setted "<< dimension << " as dimension\n";
9  return;
10  }
11 
12  gain = 0.3;
13 
14 }
15 
16 int HorizontalAttitudeTask::updateMatrices(Infos* const robInfo){
17 
18  setPhi(robInfo->robotState.wTv_eigen);
19 
20  setActivation();
21  setJacobian();
22  setReference();
23 
24  return 0;
25 }
26 
32 void HorizontalAttitudeTask::setPhi(Eigen::Matrix4d wTv_eigen){
33 
34  Eigen::Vector3d kHat;
35  kHat << 0, 0, 1; //generic k versor
36 
37  // k versor of the world projected on vehicle frame
38  Eigen::Matrix3d wRv_eigen = wTv_eigen.topLeftCorner(3,3);
39  Eigen::Vector3d v_kHat_w = wRv_eigen.transpose() * kHat;
40 
41  phi = FRM::reducedVersorLemma(v_kHat_w, kHat);
42 
43 }
44 
48 void HorizontalAttitudeTask::setActivation(){
49 
50  // activation we know that is a scalar because dimension = 1
51  A(1) = CMAT::IncreasingBellShapedFunction(0.025, 0.1, 0, 1, phi.norm());
52 }
53 
54 void HorizontalAttitudeTask::setJacobian(){
55 
56  Eigen::Vector3d normalPhi;
57  double normPhi = phi.norm();
58  if (normPhi > 0){ //to not divide by zero
59  normalPhi = phi/normPhi;
60  } else{
61  normalPhi << 0,0,0;
62  }
63 
64  //first element are zero, actually J is a row
65  Eigen::MatrixXd J_eigen(dimension, dof);
66  Eigen::Matrix<double, 3, VEHICLE_DOF> temp;
67  temp.topLeftCorner(3,3) = Eigen::Matrix3d::Zero();
68  temp.topRightCorner(3,3) = Eigen::Matrix3d::Identity();
69 
70 
71  J_eigen.topLeftCorner(dimension, ARM_DOF) = Eigen::RowVectorXd::Zero(ARM_DOF);
72  J_eigen.topRightCorner(dimension, VEHICLE_DOF) = normalPhi.transpose() * temp;
73 
74  J = CONV::matrix_eigen2cmat(J_eigen);
75 }
76 
77 void HorizontalAttitudeTask::setReference(){
78  //We know reference is a scalar becase task is scalar
79  reference(1) = -gain * phi.norm();
80 
81 }
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