-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcircle.cpp
executable file
·109 lines (97 loc) · 2.5 KB
/
circle.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <autotarget_functions.hpp>
//include API
int main(int argc, char** argv)
{
//initialize ros
ros::init(argc, argv, "gnc_node");
ros::NodeHandle gnc_node("~");
//initialize control publisher/subscribers
init_publisher_subscriber(gnc_node);
// wait for FCU connection
wait4connect();
//wait for used to switch to mode GUIDED
set_mode("GUIDED");
//create local reference frame
initialize_local_frame();
//request takeoff
takeoff(5);
//specify some waypoints
std::vector<gnc_api_waypoint> waypointList;
gnc_api_waypoint nextWayPoint;
/*nextWayPoint.x = 0;
nextWayPoint.y = 0;
nextWayPoint.z = 3;
nextWayPoint.psi = 0;*/
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 0;
nextWayPoint.y = -3;
nextWayPoint.z = 5;
nextWayPoint.psi = 180;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 2;
nextWayPoint.y = -2;
nextWayPoint.z = 5;
nextWayPoint.psi = -45;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 3;
nextWayPoint.y = 0;
nextWayPoint.z = 5;
nextWayPoint.psi = -45;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 2;
nextWayPoint.y = 2;
nextWayPoint.z = 5;
nextWayPoint.psi = 45;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 0;
nextWayPoint.y = 3;
nextWayPoint.z = 5;
nextWayPoint.psi = 45;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = -2;
nextWayPoint.y = 2;
nextWayPoint.z = 3;
nextWayPoint.psi = 135;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = -3;
nextWayPoint.y = 0;
nextWayPoint.z = 5;
nextWayPoint.psi = 135;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = -2;
nextWayPoint.y = -2;
nextWayPoint.z = 5;
nextWayPoint.psi = -135;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 0;
nextWayPoint.y = -3;
nextWayPoint.z = 5;
nextWayPoint.psi = 180;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 0;
nextWayPoint.y = 0;
nextWayPoint.z = 5;
nextWayPoint.psi = 0;
waypointList.push_back(nextWayPoint);
//specify control loop rate. We recommend a low frequency to not over load the FCU with messages. Too many messages will cause the drone to be sluggish
ros::Rate rate(2.0);
int counter = 0;
while(ros::ok())
{
ros::spinOnce();
rate.sleep();
if(check_waypoint_reached(.3) == 1)
{
if (counter < waypointList.size())
{
set_destination(waypointList[counter].x,waypointList[counter].y,waypointList[counter].z, waypointList[counter].psi);
counter++;
}else{
//land after all waypoints are reached
land();
ros::shutdown();
}
}
}
return 0;
}