forked from alcorpas10/AS2Mission
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mission_case_0.py
executable file
·90 lines (69 loc) · 1.99 KB
/
mission_case_0.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
#!/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=-2.0 , y= 2.0, z=0.0),
Point32(x=-0.5 , y= 1.0, z=0.0),
Point32(x=-0.5 , y=-2.0, z=0.0),
Point32(x=-2.0 , y=-2.0, z=0.0)
])
polygon2 = Polygon(points=[
Point32(x= 0.25, y= 2.0, z=0.0),
Point32(x= 2.0 , y= 2.0, z=0.0),
Point32(x= 2.0 , y=-1.0, z=0.0),
Point32(x= 0.25, y= 0.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)
)
]
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(2.0)
if not auto_confirm:
if confirm("End"):
pass
controller.shutdown()
rclpy.shutdown()
print("Clean exit")
exit(0)