AtsushiSakai / PythonRobotics

Python sample codes for robotics algorithms.
https://atsushisakai.github.io/PythonRobotics/
Other
23.33k stars 6.54k forks source link

fixed hard-coded plot limits #1018

Closed yousefbilal closed 5 months ago

yousefbilal commented 5 months ago

The limits of the plots were fixed to (-2,15) which is the example random range. Adjusted to be rand_min, rand_max instead.

AtsushiSakai commented 5 months ago

@yousefbilal Thank you for your PR. Is it possible to post animation movies before and after changes?

yousefbilal commented 5 months ago

Sure, this is the plot before the change. Some parts are hidden because the plot limits are [-2,15] image

After the change, which sets the limits of the plot to the random sample area image

Note that this also affects RRTStar as it extends the RRT class.

I used the following for the test:

def main(gx=4.0, gy=5.0):
    print("start " + __file__)

    # ====Search Path with RRT====
    obstacleList = [(1, 2, 1), (3, 2, 2), (3, 1, 2), (4, 1, 2), (0.5, -3, 2),
                    (4, -2, 2)]  # [x, y, radius]
    # Set Initial parameters
    rrt = RRT(
        start=[0, 0],
        goal=[gx, gy],
        rand_area=[-5, 6],
        obstacle_list=obstacleList,
        # play_area=[0, 10, 0, 14]
        robot_radius=0.5
        )
    path = rrt.planning(animation=show_animation)

    if path is None:
        print("Cannot find path")
    else:
        print("found path!!")

        # Draw final path
        if show_animation:
            rrt.draw_graph()
            plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
            plt.grid(True)
            plt.pause(0.01)  # Need for Mac
            plt.show()
AtsushiSakai commented 5 months ago

@yousefbilal Thank you!!