AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
obstacleAvoidEETask.cpp
1 #include "header/obstacleAvoidEETask.h"
2 
3 
4 ObstacleAvoidEETask::ObstacleAvoidEETask(int dim, bool eqType, std::string robotName)
5  : Task(dim, eqType, robotName, "OBSTACLE_AVOID_EE"){
6 
7  gain = 0.6;
8  safe_dist = 0.3; //in meters
9 
10 }
11 
12 
13 int ObstacleAvoidEETask::updateMatrices(struct Infos* const robInfo){
14 
15  double wZseafloor = SEAFLOOR_DEPTH;
16  Eigen::Matrix4d wTee = robInfo->robotState.wTv_eigen * robInfo->robotState.vTee_eigen;
17  Eigen::Vector3d w_ee_posiz= wTee.topRightCorner<3,1>();
18 
19  // the distance is a scalar because only along z axis
20  double w_dist = wZseafloor - w_ee_posiz(2);
21 
22  // if norm is too little we cant provide a ref because will tend to infinite;
23  // so we set a minimu value possible
24  // However, if norm is so little the robot are already compenetrating so problems are other:
25  //gain, safe_dist, and veh_dim maybe are too little
26  if (w_dist < 0.001) {
27  std::cout << "[" << robotName << "][" << taskName << "] WARNING: Norm too little,"
28  << " I will set it to 0.001" << std::endl;
29  w_dist = 0.001;
30  }
31 
32  setActivation(w_dist);
33  //A.PrintMtx("A");
34 
35  setJacobian(robInfo->robotState.w_Jee_robot);
36  //J.PrintMtx("J");
37 
38  setReference(w_dist);
39  //reference.PrintMtx("REF");
40 
41 
42  return 0;
43 }
44 
45 void ObstacleAvoidEETask::setActivation(double w_dist){
46 
47  A(1) = CMAT::DecreasingBellShapedFunction(0, 0 + safe_dist, 0, 1, w_dist);
48 
49 }
50 
51 void ObstacleAvoidEETask::setJacobian(Eigen::Matrix<double, 6, TOT_DOF> w_J_robot){
52 
53  Eigen::MatrixXd jacobian_eigen(dimension, TOT_DOF);
54  jacobian_eigen = Eigen::MatrixXd::Zero(dimension, TOT_DOF);
55 
56  Eigen::Vector3d zComponent;
57  zComponent << 0, 0, 1;
58 
59  //top rows are the linear part of jacobian
60  jacobian_eigen = - zComponent.transpose() * w_J_robot.topRows(3);
61 
62  J = CONV::matrix_eigen2cmat(jacobian_eigen);
63 
64 }
65 
66 void ObstacleAvoidEETask::setReference(double w_dist){
67 
68  //TODO check where the frame is to undersand well distance minimum
69 
70  //if the frame is in the middle, distance minim is two times the half of lenght
71  //(plus the safe dist)
72  //(1): we know this is a scalar task
73  this->reference(1) = gain * (safe_dist - w_dist);
74 
75 }
76 
77 
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