forked from alcorpas10/AS2Mission
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_areas_case_1.py
executable file
·106 lines (83 loc) · 2.43 KB
/
3_areas_case_1.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
#!/bin/python3
from time import sleep
import rclpy
import sys
from mutac_msgs.msg import Generation, Sweep
from mutac_msgs.srv import GeneratePlan
from geometry_msgs.msg import Point, Point32, Polygon
sys.path.insert(1, 'code')
from starter import Starter
def publish_plan_1(node : Starter):
polygon1 = Polygon(points=[
Point32(x= -9.0, y= 5.0, z=0.0),
Point32(x= -5.0, y= 5.0, z=0.0),
Point32(x= -5.0, y= 1.0, z=0.0),
Point32(x= -7.0, y= 0.0, z=0.0),
Point32(x=-10.0, y= 0.0, z=0.0),
Point32(x=-10.0, y= 4.0, z=0.0)
])
polygon2 = Polygon(points=[
Point32(x= 5.0, y= 5.0, z=0.0),
Point32(x= 10.0, y= 5.0, z=0.0),
Point32(x= 10.0, y= 1.0, z=0.0),
Point32(x= 7.0, y= 1.0, z=0.0),
Point32(x= 5.0, y= 3.0, z=0.0)
])
polygon3 = Polygon(points=[
Point32(x= -8.0, y=-1.0, z=0.0),
Point32(x= -3.0, y=-1.0, z=0.0),
Point32(x= -3.0, y=-5.0, z=0.0),
Point32(x=-10.0, y=-5.0, z=0.0)
])
sweeps = [
Sweep(
polygon=polygon1,
orientation=Point(x=0.0, y=-0.3, z=0.0)
),
Sweep(
polygon=polygon2,
orientation=Point(x=0.0, y=-0.3, z=0.0)
),
Sweep(
polygon=polygon3,
orientation=Point(x=0.0, y=-0.3, 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
else:
return False
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(30)
print('LAND DRONE 0')
controller.pub_land(0)
sleep(2.0)
if not auto_confirm:
if confirm("End"):
pass
controller.shutdown()
rclpy.shutdown()
print("Clean exit")
exit(0)