-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.py
executable file
·126 lines (90 loc) · 3.36 KB
/
shapes.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
#!/usr/bin/env python
import rospy
from math import cos, sin, pi, sqrt
from itertools import permutations
r=2
z=3
offset = [0,2,-2,4,-4]
def get_distance(point1,point2):
return sqrt((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)
def nearest(locations, waypoint, myoffset):
# location = [[x1, y1, z1], [x2, y2, z2]]
# combinations = [([x,y,z],[x1,y1,z1]),([x,y,z],[x1,y1,z1])]
loc = locations
wp = waypoint
combinations = list(permutations(wp))
total_travelled = []
# include the offset
for i in range(len(loc)):
loc[i][0] -= myoffset[i]
for i in range(len(combinations)):
travelled = 0
for j in range(len(loc)):
travelled += get_distance(loc[j], combinations[i][j])
total_travelled.append(travelled)
index_minimum = total_travelled.index(min(total_travelled))
return combinations[index_minimum]
def circle(location, pose, direction, numuav, myoffset):
waypoints = []
angle = 2*pi/numuav
for i in range(numuav):
x = r * cos(angle*(numuav-i)) + direction[0]
y = r * sin(angle*(numuav-i)) + direction[1]
waypoints.append([x,y])
# a points tuple ([x1,y1,z1],[x2,y2,z2])
points = nearest(location, waypoints, myoffset)
for i in range(numuav):
pose[i].pose.position.x = points[i][0] + myoffset[i]
pose[i].pose.position.y = points[i][1]
pose[i].pose.position.z = z
return pose
def xform(location, pose, direction, numuav, myoffset):
if numuav < 5:
return
else:
waypoints = [[direction[0], direction[1]]]
angle = 2*pi/4
for i in range(4):
x = r * cos(angle*i+pi/4) + direction[0]
y = r * sin(angle*i+pi/4) + direction[1]
waypoints.append([x,y])
points = nearest(location, waypoints, myoffset)
for i in range(numuav):
pose[i].pose.position.x = points[i][0] + myoffset[i]
pose[i].pose.position.y = points[i][1]
pose[i].pose.position.z = z
return pose
def triangle(location, pose, direction, numuav, myoffset):
if numuav < 5:
return
else:
waypoints = []
angle = 2*pi/3
for i in range(3):
x = r*cos(angle*i + pi/2) + direction[0]
y = r*sin(angle*i + pi/2) + direction[1]
waypoints.append([x,y])
for i in range(2):
x = waypoints[0][0]+waypoints[i+1][0]
x /= 2
y = waypoints[0][1]+waypoints[i+1][1]
y /= 2
waypoints.append([x,y])
points = nearest(location, waypoints, myoffset)
for i in range(5):
pose[i].pose.position.x = points[i][0] + myoffset[i]
pose[i].pose.position.y = points[i][1]
pose[i].pose.position.z = z
return pose
def line(location, pose, direction, numuav, myoffset):
waypoints = [[0,0], [-2,0],[2,0],[-4,0],[4,0]]
for i in range(len(waypoints)):
waypoints[i][0] += direction[0]
waypoints[i][1] += direction[1]
points = nearest(location, waypoints, myoffset)
for i in range(5):
if location[i][2] > 1:
pose[i].pose.position.x = points[i][0] + myoffset[i]
pose[i].pose.position.y = points[i][1]
pose[i].pose.position.z = z
return pose