-
Notifications
You must be signed in to change notification settings - Fork 2
/
random_fly_xyz.cpp
executable file
·153 lines (123 loc) · 3.19 KB
/
random_fly_xyz.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#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);
wait4connect();
set_mode("GUIDED");
initialize_local_frame();
//in HZ (10HZ=100ms)
ros::Rate rate(1);
takeoff(5);
ros::spinOnce();
rate.sleep();
set_destination(5, 0, 5, -90);
ros::spinOnce();
rate.sleep();
set_destination(5, 5, 5, 0);
ros::spinOnce();
rate.sleep();
/*
set_destination(0, 0, 5, 0);
ros::spinOnce();
rate.sleep();
set_destination(5, 0, 5, -90);
ros::spinOnce();
rate.sleep();
set_destination(5, 5, 5, 0);
ros::spinOnce();
rate.sleep();
set_destination(0, 5, 5, 90);
ros::spinOnce();
rate.sleep();
set_destination(0, 0, 5, 180);
ros::spinOnce();
rate.sleep();
set_destination(0, 0, 5, 0);
ros::spinOnce();
rate.sleep();
*/
land();
ros::shutdown();
return 0;
}
/*
#include <gnc_functions.hpp>
int main(int argc, char** argv)
{
int altitude=3;
int speed=5;
//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();
set_speed(speed);
//request takeoff
takeoff(altitude);
//specify some waypoints
std::vector<gnc_api_waypoint> waypointList;
gnc_api_waypoint nextWayPoint;
nextWayPoint.x = 0;
nextWayPoint.y = 0;
nextWayPoint.z = altitude;
nextWayPoint.psi = 0;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 3;
nextWayPoint.y = 0;
nextWayPoint.z = altitude;
nextWayPoint.psi = 90;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 4;
nextWayPoint.y = 2;
nextWayPoint.z = altitude;
nextWayPoint.psi = 180;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 1;
nextWayPoint.y = 3;
nextWayPoint.z = altitude;
nextWayPoint.psi = 270;
waypointList.push_back(nextWayPoint);
nextWayPoint.x = 0;
nextWayPoint.y = 0;
nextWayPoint.z = altitude;
nextWayPoint.psi = 0;
waypointList.push_back(nextWayPoint);
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);
//ros::Duration(5.0).sleep();
int counter = 0;
while(ros::ok())
{
ros::spinOnce();
rate.sleep();
if(check_waypoint_reached(.2) == 1)
{
if (counter < waypointList.size())
{
ROS_INFO("MOVE TO POINT %i", counter);
set_destination(waypointList[counter].x,waypointList[counter].y,waypointList[counter].z, waypointList[counter].psi);
set_yaw(waypointList[counter].psi, 45, -1, 1);
ROS_INFO("POINT %i REACHED", counter);
//ros::Duration(5.0).sleep();
//ROS_INFO("************************************ WAIT FOR 5 sec ************************************");
counter++;
}else{
//land after all waypoints are reached
land();
}
}
}
return 0;
}*/