|
2 | 2 | from PathPlanning.utils import *
|
3 | 3 |
|
4 | 4 | def main():
|
5 |
| - map = Map(left=0, right=640, top=480, down=0) |
| 5 | + map = Map(left=0, right=640, top=480, down=0, refresh=False) |
6 | 6 | map.add_obstacle(CircleObstacle(pos=Point(200, 200), radius=50))
|
7 |
| - map.add_obstacle(CircleObstacle(pos=Point(350, 250), radius=30)) |
8 |
| - map.add_obstacle(CircleObstacle(pos=Point(450, 400), radius=80)) |
9 |
| - potentialFieldPlanner = PotentialFieldPlanner(map=map, iterations=1e4, step_size=2, ka=1, kr=1e4, da=10, dr=100) |
10 |
| - start = Point(0, 0) |
11 |
| - end = Point(640, 480) |
| 7 | + map.add_obstacle(CircleObstacle(pos=Point(400, 300), radius=40)) |
| 8 | + # map.add_obstacle(CircleObstacle(pos=Point(450, 400), radius=80)) |
| 9 | + potentialFieldPlanner = PotentialFieldPlanner(map=map, iterations=1e4, step_size=2, ka=1, kr=1e7, da=10, dr=50) |
| 10 | + start = Point(100, 100) |
| 11 | + end = Point(500, 250) |
| 12 | + potentialFieldPlanner.plan(start=start, target=end) |
| 13 | + map.add_geometry(type='point', pos=start.tuple(), size=10, color=(100, 0, 0)) |
| 14 | + map.add_geometry(type='point', pos=end.tuple(), size=10, color=(0, 100, 0)) |
| 15 | + for i in range(len(potentialFieldPlanner.finalPath)-1): |
| 16 | + map.add_geometry(type='line', start=potentialFieldPlanner.finalPath[i].tuple(), end=potentialFieldPlanner.finalPath[i+1].tuple(), color=(0, 100, 0)) |
| 17 | + # draw potential force |
| 18 | + for x in range(0, map.right+1, 10): |
| 19 | + for y in range(0, map.top+1, 10): |
| 20 | + force = potentialFieldPlanner.calculate_potential_force(Point(x, y), end) |
| 21 | + force_start = Point(x, y) |
| 22 | + force_end = force_start + Polar2Vector(5, force.dir()) |
| 23 | + # map.add_geometry(type='point', pos=(x,y), size=3, color=(0, 0, 100)) |
| 24 | + map.add_geometry(type='line', start=force_start.tuple(), end=force_end.tuple(), width=2, color=(120,50,80)) |
| 25 | + # draw potential line |
| 26 | + potential_lines = [i for i in range(0, 20000, 1000)] |
| 27 | + for x in range(0, map.right+1, 1): |
| 28 | + for y in range(0, map.top+1, 1): |
| 29 | + valid = True |
| 30 | + for obs in map.obstacles: |
| 31 | + if obs.dist(Point(x, y)) <= 32: |
| 32 | + valid = False |
| 33 | + |
| 34 | + if valid: |
| 35 | + offset = 20 |
| 36 | + else: |
| 37 | + offset = 100 |
| 38 | + potential = potentialFieldPlanner.calculate_attractive_potential(Point(x, y), end) + potentialFieldPlanner.calculate_repulsive_potential(Point(x, y)) |
| 39 | + # print(potential, potentialFieldPlanner.calculate_attractive_potential(Point(x, y), end)) |
| 40 | + for p in potential_lines: |
| 41 | + if math.fabs(potential-p) < offset: |
| 42 | + map.add_geometry(type='point', pos=(x,y), size=1, color=(0, 0, 100)) |
| 43 | + |
12 | 44 | while map.is_open:
|
13 |
| - potentialFieldPlanner.plan(start=start, target=end) |
14 |
| - map.add_geometry(type='point', pos=start.tuple(), size=30, color=(100, 0, 0)) |
15 |
| - map.add_geometry(type='point', pos=end.tuple(), size=30, color=(0, 100, 0)) |
16 |
| - for i in range(len(potentialFieldPlanner.finalPath)-1): |
17 |
| - map.add_geometry(type='line', start=potentialFieldPlanner.finalPath[i].tuple(), end=potentialFieldPlanner.finalPath[i+1].tuple(), color=(0, 100, 0)) |
18 | 45 | map.render()
|
19 | 46 |
|
20 | 47 | if __name__ == '__main__':
|
|
0 commit comments