AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
worldInterface.cpp
1 #include "header/worldInterface.h"
2 
3 WorldInterface::WorldInterface(std::string callerName){
4 
5  this->callerName = callerName;
6  std::cout << "[" << callerName <<"][WORLD_INTERFACE] Start"<< std::endl;
7 
8 }
9 
10 
11 
12 int WorldInterface::waitReady(std::string objName){
13 
14  if(!ros::ok()){
15  return -1;
16  }
17 
18  //wait to transform wTx to be ready
19  std::string objTopic = "/" + objName;
20  tfListener.waitForTransform("world", objTopic, ros::Time(0), ros::Duration(3.0));
21 
22 
23  return 0;
24 }
25 
26 int WorldInterface::waitReady(std::string firstFrame, std::string secondFrame){
27 
28  if(!ros::ok()){
29  return -1;
30  }
31 
32  //wait to transform xTx to be ready
33  std::string firstFrameTopic = "/" + firstFrame;
34  std::string secondFrameTopic = "/" + secondFrame;
35 
36  tfListener.waitForTransform(firstFrameTopic, secondFrameTopic, ros::Time(0), ros::Duration(3.0));
37 
38 
39  return 0;
40 }
41 
42 int WorldInterface::getT(Eigen::Matrix4d* xTx_eigen, std::string firstFrame, std::string secondFrame){
43  std::string firstFrameTopic = "/" + firstFrame;
44  std::string secondFrameTopic = "/" + secondFrame;
45 
46  tf::StampedTransform wTt_tf;
47 
48 
49  try {
50  tfListener.lookupTransform(firstFrameTopic, secondFrameTopic, ros::Time(0), wTt_tf);
51 
52  } catch (tf::TransformException &ex) {
53  ROS_ERROR("%s",ex.what());
54  ros::Duration(1.0).sleep();
55  }
56 
57  *xTx_eigen = CONV::transfMatrix_tf2eigen(wTt_tf);
58 
59 
60 
61 }
62 
63 int WorldInterface::getwT(Eigen::Matrix4d* wTt_eigen, std::string objName){
64 
65  std::string topic = "/" + objName;
66  tf::StampedTransform wTt_tf;
67 
68  try {
69  tfListener.lookupTransform("world", topic, ros::Time(0), wTt_tf);
70 
71  } catch (tf::TransformException &ex) {
72  ROS_ERROR("%s",ex.what());
73  ros::Duration(1.0).sleep();
74  }
75 
76  *wTt_eigen = CONV::transfMatrix_tf2eigen(wTt_tf);
77 
78 
79 }
80 
81 
82 int WorldInterface::getwPos(Eigen::Vector3d* pos, std::string robotName){
83 
84  tf::StampedTransform wTv_tf;
85 
86  std::string topic = "/" + robotName;
87  try {
88  tfListener.lookupTransform("world", topic, ros::Time(0), wTv_tf);
89 
90  } catch (tf::TransformException &ex) {
91  ROS_ERROR("%s",ex.what());
92  ros::Duration(1.0).sleep();
93  }
94 
95  Eigen::Matrix4d wTvother_eigen = CONV::transfMatrix_tf2eigen(wTv_tf);
96  *pos = wTvother_eigen.topRightCorner<3,1>();
97 
98  return 0;
99 }
WorldInterface(std::string callerName)
WorldInterface.