Skip to content

Commit 5b808a5

Browse files
No tree in trajectory towards goal added
1 parent 2a5ea94 commit 5b808a5

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

RRT.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
metavar='', required=False, help='Draws a red line indicating the path to goal')
2626
parser.add_argument('-mr', '--move_robot', type=bool, action=argparse.BooleanOptionalAction,
2727
metavar='', required=False, help='Shows the movements of the robot from the start to the end')
28+
parser.add_argument('-kt', '--keep_tree', type=bool, action=argparse.BooleanOptionalAction,
29+
metavar='', required=False, help='Keeps the tree while the robot is moving towards the goal')
2830
args = parser.parse_args()
2931

3032
# Initialization
@@ -43,8 +45,7 @@
4345

4446
# Instantiating the environment and the graph
4547
environment_ = environment.Environment(map_dimensions=MAP_DIMENSIONS)
46-
graph_ = graph.Graph(start=x_init, goal=x_goal,
47-
map_dimensions=MAP_DIMENSIONS, epsilon=EPSILON)
48+
graph_ = graph.Graph(start=x_init, goal=x_goal, map_dimensions=MAP_DIMENSIONS, epsilon=EPSILON)
4849

4950
def main():
5051
clock = pygame.time.Clock()
@@ -112,10 +113,10 @@ def main():
112113
node_value += 1 # Increment the value for the next randomly generated node
113114

114115
if graph_.is_goal_reached:
115-
graph_.draw_local_planner(p1=x_new, p2=x_goal, map_=environment_.map)
116116
is_simulation_finished = True
117117
graph_.parent = parent
118118
graph_.tree = tree
119+
graph_.draw_local_planner(p1=x_new, p2=x_goal, map_=environment_.map)
119120
graph_.path_to_goal()
120121
graph_.get_path_coordinates()
121122

@@ -125,7 +126,8 @@ def main():
125126
k += 1 # One more node sampled
126127

127128
if graph_.is_goal_reached and args.move_robot:
128-
graph_.draw_trajectory(nears=nears, news=tree, environment_=environment_)
129+
graph_.draw_trajectory(nears=nears, news=tree, environment=environment_,
130+
obstacles=obstacles, keep_tree=args.keep_tree)
129131

130132
pygame.display.update()
131133

__pycache__/graph.cpython-310.pyc

53 Bytes
Binary file not shown.

graph.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,30 +276,34 @@ def draw_path_to_goal(self, map_):
276276
end_pos=self.path_coordinates[i+1], width=4)
277277

278278
def move_robot(self, position, map_):
279-
"""Draws the robot moving."""
279+
"""Draws the robot moving at the given position."""
280280
pygame.draw.circle(surface=map_, color=(0, 0, 255), center=position, radius=4)
281281

282282
def draw_tree(self, nears, news, map_):
283283
"""Draws the tree constantly. Used to display it in an infinite loop."""
284284
for i in range(len(nears)):
285285
self.draw_local_planner(p1=nears[i], p2=news[i+1], map_=map_)
286286

287-
def draw_trajectory(self, nears, news, environment_):
287+
def draw_trajectory(self, nears, news, environment, obstacles, keep_tree):
288288
"""Draws the robot moving in the map."""
289289
for i in range(len(self.path_coordinates)-1):
290290
robot_position = self.path_coordinates[::-1][i]
291291

292+
if obstacles != []:
293+
environment.draw_obstacles()
294+
292295
# Draw inital and final robot configuration
293-
self.draw_initial_node(map_=environment_.map)
294-
self.draw_goal_node(map_=environment_.map)
295-
environment_.draw_obstacles()
296+
self.draw_initial_node(map_=environment.map)
297+
self.draw_goal_node(map_=environment.map)
296298

297299
# Draw path to goal, and the robot movement
298-
self.draw_path_to_goal(map_=environment_.map)
299-
self.move_robot(position=robot_position, map_=environment_.map)
300-
self.draw_tree(nears=nears, news=news, map_=environment_.map)
300+
self.draw_path_to_goal(map_=environment.map)
301+
self.move_robot(position=robot_position, map_=environment.map)
302+
303+
if keep_tree:
304+
self.draw_tree(nears=nears, news=news, map_=environment.map)
301305

302306
# Refresh the screen
303307
pygame.display.update()
304308
pygame.time.delay(20) # Wait 0.1 seconds
305-
environment_.map.fill(self.WHITE)
309+
environment.map.fill(self.WHITE)

0 commit comments

Comments
 (0)