-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsnr.py
executable file
·118 lines (103 loc) · 3.42 KB
/
snr.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
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
#! /usr/bin/env python
# Import ROS.
import rospy
# Importing BoundingBoxes message from package darknet_ros_msgs.
from darknet_ros_msgs.msg import BoundingBoxes
# Import the API.
from iq_gnc.py_gnc_functions import *
# To print colours (optional).
from iq_gnc.PrintColours import *
mode_g = False
# True - Rescue
# False - Search
def detection_cb(msg):
# Callback function of the subscriber.
# Assigning bounding_boxes of the message to bbox variable.
bbox = msg.bounding_boxes
for i in range(len(bbox)):
# Printing the detected object with its probability in percentage.
rospy.loginfo("{}% certain {} detected.".format(
float(bbox[i].probability * 100), bbox[i].Class))
if bbox[i].Class == "person":
global mode_g
# Setting mode_g to True to mark presence of person.
mode_g = True
rospy.loginfo(
CBLUE + "Person found. Starting Rescue Operation" + CEND)
def main():
# Initialise ROS node
rospy.init_node("search_and_rescue_node")
# Creating a subscriber for the topic "/darknet_ros/bounding_boxes".
rospy.Subscriber(name="/darknet_ros/bounding_boxes",
data_class=BoundingBoxes,
callback=detection_cb,
queue_size=1)
# 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 10m.
drone.takeoff(10)
# Specify some waypoints
wps = []
# Amount to move in the y-direction (local frame) in the snake like pattern.
spacing = 10.0
# No of times the snake like pattern needs to repeat.
rows = 5
# Amount to move in the x-direction (local frame) in the snake like pattern.
drange = 50.0
for i in range(rows):
# Creating the snake like pattern and pushing it to the waypoints list.
row = i * 2
x = row * spacing
y = 0
z = 10
psi = 0
wps.append([x, y, z, psi])
x = row * spacing
y = drange
z = 10
psi = 0
wps.append([x, y, z, psi])
x = (row+1) * spacing
y = drange
z = 10
psi = 0
wps.append([x, y, z, psi])
x = (row+1) * spacing
y = 0
z = 10
psi = 0
wps.append([x, y, z, psi])
# 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(2)
i = 0
global mode_g
while i < len(wps):
if not mode_g:
drone.set_destination(
x=wps[i][0], y=wps[i][1], z=wps[i][2], psi=wps[i][3])
rate.sleep()
if drone.check_waypoint_reached():
i += 1
elif mode_g:
break
drone.land()
# Land after all waypoints is reached or if human is detected.
print((CGREEN2 + "Human detected Landing" + CEND)
if mode_g else (CRED2 + "Landing no humans detected" + CEND))
# Shutdown node.
rospy.signal_shutdown()
# Driver code.
if __name__ == '__main__':
try:
main()
# Used to keep the node running.
rospy.spin()
except KeyboardInterrupt:
rospy.signal_shutdown("KeyboardInterrupt")
exit()