AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
main_oldold.cpp
1 #include <ros/ros.h>
2 #include <Eigen/Core>
3 #include <tf/transform_listener.h>
4 
5 #include "../support/support.h"
6 #include "../support/defines.h"
7 
8 #include "../header/publisher.h"
9 #include "../header/controller.h"
10 
11 #include "../header/transforms.h"
12 
13 
14 
15 int main(int argc, char **argv)
16 {
17  ROS_INFO("[MAIN] Start");
18  ros::init(argc, argv, "main");
19  ros::NodeHandle nh;
20 
21  std::string topicTwist = "/uwsim/g500_A/twist_command_A";
22  ros::Publisher pubTwist = nh.advertise<geometry_msgs::TwistStamped>(topicTwist,1);
23 
24 
25  Publisher pubClassTwist(pubTwist);
26  geometry_msgs::TwistStamped twist;
27  twist.twist.linear.x=0;
28  twist.twist.linear.y=0;
29  twist.twist.linear.z=0;
30  twist.twist.angular.x=0;
31  twist.twist.angular.y=0;
32  twist.twist.angular.z=0;
33 
34 
36  double goalLinearVect[] = {-0.287, -0.062, 7.424};
37  Eigen::Matrix4d wTgoal_eigen = Eigen::Matrix4d::Identity();
38 
39  //rot part
40  wTgoal_eigen.topLeftCorner(3,3) = Eigen::Matrix3d::Identity();
41  //trasl part
42  wTgoal_eigen(0, 3) = goalLinearVect[0];
43  wTgoal_eigen(1, 3) = goalLinearVect[1];
44  wTgoal_eigen(2, 3) = goalLinearVect[2];
45  //TRANSFORM LISTENER things
46  tf::TransformListener tfListener;
47  tf::StampedTransform wTv_tf;
48 
49  //struct transforms to pass them to Controller class
50  struct Transforms transf;
51  transf.wTgoal_eigen = wTgoal_eigen;
52  transf.wTv_eigen = CONV::transfMatrix_tf2eigen(wTv_tf);
53 
54  //Controller
55  Controller controller;
56 
57  //Wait to transform to be ready (or fail if wait more than 3 sec)
58  tfListener.waitForTransform("world", "/girona500_A", ros::Time(0), ros::Duration(3.0));
59 
60 
61  ros::Rate r(1000); //1Hz
62  while(ros::ok()){
63  try {
64 
65  tfListener.lookupTransform("world", "/girona500_A", ros::Time(0), wTv_tf);
66 
67  } catch (tf::TransformException &ex) {
68  ROS_ERROR("%s",ex.what());
69  ros::Duration(1.0).sleep();
70  continue;
71  }
72 
73  transf.wTv_eigen = CONV::transfMatrix_tf2eigen(wTv_tf);
74  controller.updateTransforms(&transf);
75 
76  CMAT::Matrix yDot = controller.execAlgorithm();
77 
78 
79  twist.twist.angular.x=yDot(5);
80  twist.twist.angular.y=yDot(6);
81  twist.twist.angular.z=yDot(7);
82  twist.twist.linear.x=yDot(8);
83  twist.twist.linear.y=yDot(9);
84  twist.twist.linear.z=yDot(10);
85 
86  pubClassTwist.publish(twist);
87 
88  ros::spinOnce();
89  r.sleep();
90  }
91 
92  return 0;
93 }
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
The Controller class is responsabile of 1) taking matrices and giving them to Tasks classes...
Definition: controller.h:20
The Transforms struct VARIABLE AND CONSTANT infos necessary to the mission, but not related directly ...
Definition: infos.h:13
std::vector< double > execAlgorithm(std::vector< Task * > tasks)
Controller::execAlgorithm this function calls the step of the algorithm modifying (in the for) each t...
Definition: controller.cpp:101