AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
armShapeTask.cpp
1 #include "header/armShapeTask.h"
2 
3 ArmShapeTask::ArmShapeTask(int dim, bool eqType, std::string robotName, ShapeType shapeType)
4  : Task(dim, eqType, robotName, "ARM_SHAPE"){
5  gain = 0.05;
6  rangeAct = 0.5; //used in activation
7  this->shapeType = shapeType;
8  std::string eqineq = (eqType) ? "equality" : "inequality";
9 
10  std::cout << "[" << robotName << "][ARM_SHAPE]" << " ... as " <<
11  eqineq << "task\n";
12 
13 }
14 
15 int ArmShapeTask::updateMatrices(struct Infos* const robInfo){
16 
17  std::vector<double> jointGoal(4);
18  if (shapeType == MID_LIMITS){
19  //set preferred goal at middle pos for each joint
20  jointGoal[0] = (JLIM1_MAX + JLIM1_MIN)/2;
21  jointGoal[1] = (JLIM2_MAX + JLIM2_MIN)/2;
22  jointGoal[2] = (JLIM3_MAX + JLIM3_MIN)/2;
23  jointGoal[3] = (JLIM4_MAX + JLIM4_MIN)/2;
24 
25  } else if(shapeType == PEG_GRASPED_PHASE){
26 
27  jointGoal[0] = 0;
28  //jointGoal[1] = (JLIM2_MAX + JLIM2_MIN)/2;
29  //jointGoal[2] = (JLIM3_MAX + JLIM3_MIN)/2;
30  //jointGoal[3] = (JLIM4_MAX + JLIM4_MIN)/2;
31  jointGoal[1] = 0.3744;
32  jointGoal[2] = 0.6556;
33  jointGoal[3] = 1.570;
34 
35  //TODO first jointGoal is different from robot which stay in front and behind
36  //the peg, now it is at the actual pos (so no effect on it)
37  }
38 
39  setActivation(jointGoal, robInfo->robotState.jState);
40  setJacobian();
41  setReference(jointGoal, robInfo->robotState.jState);
42  return 0;
43 
44 }
45 
52 int ArmShapeTask::setActivation(std::vector<double> jointGoal, std::vector<double> jState){
53 
54  if (eqType){
55  double vectDiag[dimension];
56  std::fill_n(vectDiag, dimension, 1);
57  this->A.SetDiag(vectDiag);
58 
59  } else {
60  for (int i=1; i<=dimension; i++){
61 
62  A(i,i) =
63  CMAT::DecreasingBellShapedFunction(
64  jointGoal[i-1]-rangeAct, jointGoal[i-1], 0, 1, jState[i-1]) +
65  CMAT::IncreasingBellShapedFunction(
66  jointGoal[i-1], jointGoal[i-1]+rangeAct, 0, 1, jState[i-1]);
67  }
68 
69  }
70 
71  return 0;
72 
73 }
74 
75 int ArmShapeTask::setJacobian(){
76 
77  CMAT::Matrix eye = CMAT::Matrix::Eye(dimension);
78  CMAT::Matrix zero = CMAT::Matrix::Zeros(dimension,VEHICLE_DOF);
79 
80  CMAT::Matrix tot = eye.RightJuxtapose(zero);
81  J = tot;
82 
83 }
84 
85 int ArmShapeTask::setReference(std::vector<double> jointGoal,
86  std::vector<double> jState){
87 
88  for (int i=0; i<dimension; i++){
89  error(i+1) = jointGoal[i] - jState[i];
90  reference(i+1) = gain * (jointGoal[i] - jState[i]);
91  }
92 
93  return 0;
94 }
Definition: infos.h:117
ABSTRACT class task. Each task is a derived class of this class. It contains all the variable that th...
Definition: task.h:17