-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsquare.py
executable file
·48 lines (40 loc) · 1.34 KB
/
square.py
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
#! /usr/bin/env python
# Import ROS.
import rospy
# Import the API.
from iq_gnc.py_gnc_functions import *
# To print colours (optional).
from iq_gnc.PrintColours import *
def main():
# Initializing ROS node.
rospy.init_node("drone_controller", anonymous=True)
# Create an object for the API.
drone = gnc_api()
# Wait for FCU connection.
drone.wait4connect()
# Wait for the mode to be switched.
drone.wait4start()
# Create local reference frame.
drone.initialize_local_frame()
# Request takeoff with an altitude of 3m.
drone.takeoff(3)
# 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.
rate = rospy.Rate(3)
# Specify some waypoints
goals = [[0, 0, 3, 0], [5, 0, 3, -90], [5, 5, 3, 0],
[0, 5, 3, 90], [0, 0, 3, 180], [0, 0, 3, 0]]
i = 0
while i < len(goals):
drone.set_destination(
x=goals[i][0], y=goals[i][1], z=goals[i][2], psi=goals[i][3])
rate.sleep()
if drone.check_waypoint_reached():
i += 1
# Land after all waypoints is reached.
drone.land()
rospy.loginfo(CGREEN2 + "All waypoints reached landing now." + CEND)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit()