Skip to content

Commit 2a5ea94

Browse files
Minor changes added
1 parent 299140f commit 2a5ea94

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

RRT.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
help='Maximum number of nodes')
1313
parser.add_argument('-e', '--epsilon', type=float, metavar='', required=False, help='Step size')
1414
parser.add_argument('-init', '--x_init', nargs='+', type=int, metavar='', required=False,
15-
help='Initial node position in X and Y respectively')
15+
help='Initial node position in X and Y, respectively')
1616
parser.add_argument('-goal', '--x_goal', nargs='+', type=int, metavar='', required=False,
17-
help='Goal node position in X and Y respectively')
17+
help='Goal node position in X and Y, respectively')
1818
parser.add_argument('-srn', '--show_random_nodes', type=bool, action=argparse.BooleanOptionalAction,
1919
metavar='', required=False, help='Show random nodes on screen')
2020
parser.add_argument('-snn', '--show_new_nodes', type=bool, action=argparse.BooleanOptionalAction,
@@ -27,6 +27,9 @@
2727
metavar='', required=False, help='Shows the movements of the robot from the start to the end')
2828
args = parser.parse_args()
2929

30+
# Initialization
31+
pygame.init()
32+
3033
# Constants
3134
MAP_DIMENSIONS = 640, 480
3235

@@ -75,7 +78,7 @@ def main():
7578

7679
if not is_simulation_finished:
7780
# Sample free space and check x_rand node collision
78-
x_rand = graph_.generate_random_node(obstacles=obstacles) # Random node
81+
x_rand = graph_.generate_random_node() # Random node
7982
rand_collision_free = graph_.is_free(point=x_rand, obstacles=obstacles)
8083

8184
if rand_collision_free:
0 Bytes
Binary file not shown.

__pycache__/graph.cpython-310.pyc

108 Bytes
Binary file not shown.

graph.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, start, goal, map_dimensions, epsilon):
4040
self.FUCSIA = (255, 0, 255)
4141

4242
def is_free(self, point, obstacles):
43-
"""Checks whether a node is colliding with an obstacle or not.
43+
"""Checks if a node is colliding with an obstacle.
4444
4545
When dealing with obstacles it is necessary to check
4646
for the collision with them from the generated node.
@@ -62,7 +62,7 @@ def is_free(self, point, obstacles):
6262

6363
return True
6464

65-
def generate_random_node(self, obstacles):
65+
def generate_random_node(self):
6666
"""Generates a random node on the screen.
6767
6868
The x and y coordinate is generated given an uniform
@@ -79,7 +79,6 @@ def generate_random_node(self, obstacles):
7979
Coordinates of the random node.
8080
"""
8181
self.x_rand = random.uniform(0, self.WIDTH), random.uniform(0, self.HEIGHT)
82-
# collision_free = self.is_free(point=self.x_rand, obstacles=obstacles)
8382

8483
return self.x_rand
8584

@@ -278,8 +277,7 @@ def draw_path_to_goal(self, map_):
278277

279278
def move_robot(self, position, map_):
280279
"""Draws the robot moving."""
281-
pygame.draw.circle(surface=map_, color=(0, 0, 255),
282-
center=position, radius=4)
280+
pygame.draw.circle(surface=map_, color=(0, 0, 255), center=position, radius=4)
283281

284282
def draw_tree(self, nears, news, map_):
285283
"""Draws the tree constantly. Used to display it in an infinite loop."""
@@ -303,5 +301,5 @@ def draw_trajectory(self, nears, news, environment_):
303301

304302
# Refresh the screen
305303
pygame.display.update()
306-
pygame.time.delay(50) # Wait 0.1 seconds
304+
pygame.time.delay(20) # Wait 0.1 seconds
307305
environment_.map.fill(self.WHITE)

0 commit comments

Comments
 (0)