AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
obstacleAvoidVehicleTask.cpp
1 #include "header/obstacleAvoidVehicleTask.h"
2 
3 ObstacleAvoidVehicleTask::ObstacleAvoidVehicleTask(int dim, bool eqType, std::string robotName)
4  : Task(dim, eqType, robotName, "OBSTACLE_AVOID_VEH"){
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  gain = 0.7;
12  safe_dist = 0.75; //in meters
13 
14 }
15 
16 int ObstacleAvoidVehicleTask::updateMatrices(struct Infos* const robInfo){
17 
18  //distance in world frame between the base frame of the 2 robot
19  Eigen::Vector3d w_dist = robInfo->exchangedInfo.otherRobPos -
20  robInfo->robotState.wTv_eigen.topRightCorner<3,1>();
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  double w_distNorm = w_dist.norm();
27  if (w_distNorm < 0.001) {
28  std::cout << "[" << robotName << "][" << taskName << "] WARNING: Norm too little,"
29  << " I will set it to 0.001" << std::endl;
30  w_distNorm = 0.001;
31  }
32 
33  //std::cout << w_distNorm << " DIST NORMA\n";
34 
35  setActivation(w_distNorm);
36  //A.PrintMtx("A");
37 
38  Eigen::Vector3d w_dist_normal = w_dist / w_distNorm;
39  setJacobian(robInfo->robotState.wTv_eigen, w_dist_normal);
40  //J.PrintMtx("J");
41 
42  setReference(w_distNorm);
43  //reference.PrintMtx("REF");
44 
45 
46  return 0;
47 }
48 
49 void ObstacleAvoidVehicleTask::setActivation(double w_distNorm){
50 
51  //we know it is a scalar task
52  A(1) = CMAT::DecreasingBellShapedFunction(VEH_DIM, VEH_DIM + safe_dist, 0, 1, w_distNorm);
53 
54 }
55 
56 void ObstacleAvoidVehicleTask::setJacobian(Eigen::Matrix4d wTv, Eigen::Vector3d w_dist_normal){
57 
58  Eigen::Matrix<double, 1, TOT_DOF> jacobian_eigen = Eigen::Matrix<double, 1, TOT_DOF>::Zero();
59 
60  //first ARM_DOF column zero
61 
62  //linear part
63  jacobian_eigen.block<1,3>(0,4) =
64  -w_dist_normal.transpose() * wTv.topLeftCorner<3,3>();
65 
66  //angular part vehicle zero
67 
68 
69  J = CONV::matrix_eigen2cmat(jacobian_eigen);
70 
71 }
72 
73 void ObstacleAvoidVehicleTask::setReference(double w_distNorm){
74 
75  //TODO check where the frame is to undersand well distance minimum
76 
77  //if the frame is in the middle, distance minim is two times the half of lenght
78  //(plus the safe dist)
79  //(1): we know this is a scalar task
80  this->reference(1) = gain * ((VEH_DIM + safe_dist) - w_distNorm);
81 
82 }
83 
84 
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