-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwaypoint_generate.py
138 lines (105 loc) · 2.91 KB
/
waypoint_generate.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This Script is used to provide a GUI to generate waypoints for Egoplanner and save them.
import turtle
import math
from hover import *
# Initalize Map and Grid
screen = turtle.Screen()
screen.setup(width=800, height=800)
def draw_grid():
grid_turtle = turtle.Turtle()
grid_turtle.speed(0)
turtle.tracer(False)
grid_turtle.penup()
grid_turtle.hideturtle()
grid_turtle.color(0.9, 0.9, 0.9)
for x in range(-400, 401, 20):
grid_turtle.goto(x, -400)
grid_turtle.pendown()
grid_turtle.goto(x, 400)
grid_turtle.penup()
for y in range(-400, 401, 20):
grid_turtle.goto(-400, y)
grid_turtle.pendown()
grid_turtle.goto(400, y)
grid_turtle.penup()
grid_turtle.pensize(2)
grid_turtle.pencolor(0.6,0.6,0.6)
# X-axis
grid_turtle.goto(-400, 0)
grid_turtle.pendown()
grid_turtle.goto(400, 0)
grid_turtle.penup()
# Y-axis
grid_turtle.goto(0, -400)
grid_turtle.pendown()
grid_turtle.goto(0, 400)
grid_turtle.penup()
turtle.update()
turtle.tracer(True)
draw_grid()
# Define Fast waypoint generation function
t = turtle.Turtle()
t.penup()
waypoints = []
def goto_click(x, y):
t.penup()
current_x, current_y = t.pos()
angle = math.degrees(math.atan2(y - current_y, x - current_x))
t.setheading(angle)
t.goto(x, y)
waypoints.append((x, y))
screen.onscreenclick(goto_click)
def move_forward():
t.forward(20)
def turn_left():
t.left(20)
def turn_right():
t.right(15)
# Go back to home position
def go_home():
goto_click(0, 0)
# t.penup()
# t.goto(0, 0)
# t.pendown()
# Circle Around
def circle_around():
current_x, current_y = t.pos()
current_heading = t.heading()
#t.forward(50)
circle_center_x, circle_center_y = t.pos()
t.rt(90)
for i in range(1):
t.circle(60)
#waypoints.append("Circle around")
t.goto(current_x, current_y)
pos = (current_x+math.cos(math.radians(current_heading))*60, current_y+math.sin(math.radians(current_heading))*60)
logging=waypoint_generate(pos, current_heading-180, 60, 6)
waypoints.extend(logging)
t.setheading(current_heading)
t.pendown()
# Circle and return
def explore():
circle_around()
go_home()
# Quit program and save waypoints to file
def quit_program():
print("Flight logging:")
for waypoint in waypoints:
print(waypoint)
with open("./waypoints.txt", "w") as f:
for waypoint in waypoints:
f.write(str(waypoint) + "\n")
print("Waypoints saved to waypoints.txt.")
print("Successful flight.")
screen.bye()
# Bind keys to functions
screen.listen()
screen.onkey(move_forward, "w")
screen.onkey(turn_left, "a")
screen.onkey(turn_right, "d")
screen.onkey(quit_program, "q")
screen.onkey(go_home,"h")
screen.onkey(circle_around,"c")
screen.onkey(explore,"e")
# Start program
screen.mainloop()