-
Notifications
You must be signed in to change notification settings - Fork 1
/
mission_case_2.py
103 lines (77 loc) · 2.22 KB
/
mission_case_2.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
#!/bin/python3
from time import sleep
import rclpy
import sys
from mutac_msgs.msg import Generation, Sweep, Alarm
from mutac_msgs.srv import GeneratePlan
from geometry_msgs.msg import Point, Point32, Polygon
from starter import Starter
def publish_plan_1(node : Starter):
polygon1 = Polygon(points=[
Point32(x=-3.0 , y= 3.0, z=0.0),
Point32(x=-1.5 , y= 2.0, z=0.0),
Point32(x=-1.5 , y=-1.0, z=0.0),
Point32(x=-3.0 , y=-1.0, z=0.0)
])
polygon2 = Polygon(points=[
Point32(x=-0.75, y= 3.0, z=0.0),
Point32(x= 1.0 , y= 3.0, z=0.0),
Point32(x= 1.0 , y= 0.0, z=0.0),
Point32(x=-0.75, y= 1.0, z=0.0)
])
sweeps = [
Sweep(
polygon=polygon1,
orientation=Point(x=0.0, y=-0.5, z=0.0)
),
Sweep(
polygon=polygon2,
orientation=Point(x=0.0, y=-0.5, z=0.0)
)
]
generation = Generation(sweeps=sweeps)
genPlan = GeneratePlan.Request(generation=generation)
resp = node.pub_plan(genPlan)
return resp
def confirm(msg: str = 'Continue') -> bool:
""" Ask for confirmation """
confirmation = input(f"{msg}? (y/n): ")
if confirmation == "y":
return True
elif confirmation == "n":
return False
else:
sys.exit(1)
if __name__ == '__main__':
uavs = list()
rclpy.init()
auto_confirm = False
if len(sys.argv) > 1:
if str(sys.argv[1]) == "-y":
auto_confirm = True
controller = Starter()
controller.get_logger().info("Publish Plan")
if not auto_confirm:
if confirm("Publish Plan"):
controller.get_logger().info("Publishing...")
publish_plan_1(controller)
else:
controller.get_logger().info("Publishing...")
publish_plan_1(controller)
sleep(24.5)
print('LAND DRONE 1')
controller.pub_land(1)
sleep(25.5)
print('REPEAT DRONE 0')
controller.pub_repeat(0, Alarm.PHOTO_ERROR)
sleep(13.0)
print('REPEAT DRONE 2')
controller.pub_repeat(2, Alarm.PHOTO_ERROR)
sleep(2.0)
if not auto_confirm:
if confirm("End"):
pass
controller.shutdown()
rclpy.shutdown()
print("Clean exit")
exit(0)