-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfinal_gps.cpp
78 lines (61 loc) · 2.18 KB
/
final_gps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "ros/ros.h"
#include "std_msgs/Int8.h"
#include "stdio.h"
#include "sensor_msgs/NavSatFix.h"
//using namespace std
std_msgs::Int8 obj_found_1=0,obj_found_2=0,obj_found_3=0;
sensor_msgs::NavSatFix gps1, gps2, gps3;
std::float64 lat_offset = 26.192, lon_offset=91.69; // coordinates for guwahati
std::vector<std::pair<int,int> > gps_coordinates;
void obj_number_cb1(const std_msgs::Int8::ConstPtr& msg1)
{
obj_found_1=*msg1;
}
void obj_number_cb2(const std_msgs::Int8::ConstPtr& msg2)
{
obj_found_2=*msg2;
}
void obj_number_cb3(const std_msgs::Int8::ConstPtr& msg3)
{
obj_found_3=*msg3;
}
void gps_cb1(const sensor_msgs::NavSatFix::ConstPtr& msg4)
{
gps1=*msg4;
if (obj_found_1==1)
{
//append the vector with current gps coordinates
gps_coordinates.push_back(int((gps1.latitude-lat_offset)*10000000),int((gps1.longitude-lon_offset)*1000000));
}
}
void gps_cb2(const sensor_msgs::NavSatFix::ConstPtr& msg5)
{
gps2=*msg5;
if (obj_found_2==1)
{
//append the vector with current gps coordinates
gps_coordinates.push_back(int((gps2.latitude-lat_offset)*10000000),int((gps2.longitude-lon_offset)*1000000));
}
}
void gps_cb3(const sensor_msgs::NavSatFix::ConstPtr& msg6)
{
gps3=*msg6;
if (obj_found_3==1)
{
//append the vector with current gps coordinates
gps_coordinates.push_back(int((gps3.latitude-lat_offset)*10000000),int((gps3.longitude-lon_offset)*1000000));
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "gps_clustering_node");
ros::NodeHandle nh;
ros::Subscriber obj_sub1 = nh.subscribe<std_msgs::Int8>("/uav1/object_found", 100, obj_number_cb1);
ros::Subscriber obj_sub2 = nh.subscribe<std_msgs::Int8>("/uav2/object_found", 100, obj_number_cb2);
ros::Subscriber obj_sub3 = nh.subscribe<std_msgs::Int8>("/uav3/object_found", 100, obj_number_cb3);
ros::Subscriber gps_sub1 = nh.subscribe<sensor_msgs::NavSatFix>("/uav1/mavros/global_position/global", 100, gps_cb1);
ros::Subscriber gps_sub2 = nh.subscribe<sensor_msgs::NavSatFix>("/uav2/mavros/global_position/global", 100, gps_cb2);
ros::Subscriber gps_sub3 = nh.subscribe<sensor_msgs::NavSatFix>("/uav3/mavros/global_position/global", 100, gps_cb3);
ros::spin();
return 0;
}