AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
coordInterfaceCoord_old.cpp
1 #include "header/coordInterfaceCoord.h"
2 
3 CoordInterfaceCoord::CoordInterfaceCoord(ros::NodeHandle nh, std::string robotName){
4 
5  this->robotName = robotName;
6  std::cout << "[COORDINATOR][COORD_INTERFACE_to_" << robotName <<"] Start"<<std::endl;
7 
8  readyRob = false;
9  std::string topicReady = "/uwsim/" + robotName+"_MissionManager" + "/ready";
10  readyRobSub = nh.subscribe(topicReady, 1, &CoordInterfaceCoord::readyRobSubCallback, this);
11 
12 
13  std::string topicCoordFromMM = "/uwsim/" + robotName +"_MissionManager/toCoord";
14  subCoordFromMM = nh.subscribe(topicCoordFromMM, 1, &CoordInterfaceCoord::subCoordFromMMCallBack, this);
15 
16 
17 
18 }
19 
20 bool CoordInterfaceCoord::getReadyRob(){
21  return this->readyRob;
22 }
23 
32 int CoordInterfaceCoord::getNonCoopCartVel(
33  Eigen::Matrix<double, VEHICLE_DOF, 1> *nonCoopCartVel_eigen){
34 
35 
36  int vectSize = tempXdot.size();
37 
38  if (vectSize == 0){
39 // std::cout << "[COORDINATOR][COORD_INTERFACE_to_" << robotName <<"] WARNING:"
40 // << "No xDot_tool to read now "
41 // << std::endl;
42  return 1;
43  }
44 
45  if (vectSize != VEHICLE_DOF){
46  std::cout << "[COORDINATOR][COORD_INTERFACE_to_" << robotName <<"] ERROR:"
47  << "something wrong with dimension of xDot_tool received from "
48  << robotName << std::endl;
49  return -1;
50  }
51 
52  for (int i=0; i<vectSize; i++){
53  (*nonCoopCartVel_eigen)(i,0) = tempXdot.at(i);
54  }
55 
56  tempXdot.clear();
57 
58  return 0;
59 }
60 
69 int CoordInterfaceCoord::getJJsharp(
70  Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> *admisVelTool_eigen){
71 
72 
73  int nSize = tempJJsharp.size();
74 
75  if (nSize == 0){
76 // std::cout << "[COORDINATOR][COORD_INTERFACE_to_" << robotName <<"] WARNING:"
77 // << "No JJ# to read now "
78 // << std::endl;
79  return 1;
80  }
81 
82  if (nSize != VEHICLE_DOF*VEHICLE_DOF){
83  std::cout << "[COORDINATOR][COORD_INTERFACE_to_" << robotName <<"] ERROR:"
84  << "something wrong with dimension of JJ# received from "
85  << robotName << std::endl;
86  return -1;
87  }
88 
89  //Rembering that eigen is column major and the msg is store row major
90  int posRow = 0;
91  for (int i=0; i<VEHICLE_DOF; i++){
92  for (int j=0; j<VEHICLE_DOF; j++){
93  posRow = i*VEHICLE_DOF;
94  (*admisVelTool_eigen)(i,j) = tempJJsharp.at(posRow + j);
95  }
96  }
97 
98  tempJJsharp.clear();
99  return 0;
100 }
101 
102 
103 void CoordInterfaceCoord::readyRobSubCallback(const std_msgs::Bool::ConstPtr& start){
104  readyRob = start->data;
105 }
106 
107 
116 void CoordInterfaceCoord::subCoordFromMMCallBack(const peg_msgs::toCoord::ConstPtr& msg){
117 
118  tempXdot.resize(6); //message is a twist so 6 elements
119 
120  tempXdot.at(0) = msg->xDot.twist.linear.x;
121  tempXdot.at(1) = msg->xDot.twist.linear.y;
122  tempXdot.at(2) = msg->xDot.twist.linear.z;
123  tempXdot.at(3) = msg->xDot.twist.angular.x;
124  tempXdot.at(4) = msg->xDot.twist.angular.y;
125  tempXdot.at(5) = msg->xDot.twist.angular.z;
126 
127 
128  //dim[0].stride is the total number of element (row*col)
129  tempJJsharp.resize(msg->JJsharp.layout.dim[0].stride);
130  tempJJsharp = msg->JJsharp.data;
131 
132 }