motion-planning / rrt-algorithms

n-dimensional RRT, RRT* (RRT-Star)
MIT License
613 stars 175 forks source link

Setting Edge Lengths as Float Type #30

Closed sosoeeee closed 7 months ago

sosoeeee commented 7 months ago

Firstly, I want to express my gratitude for your open-source code—it helps me a lot : )

In my current project, I find the need for edge lengths to be represented as floating-point numbers. This specifically relates to the variable Q in examples/rrt_3d.py. However, this requirement exposes an issue in the file rrt-algorithms/rrt/rrt.py.

while True:
    for q in self.Q:  # iterating over different edge lengths until a solution is found or a timeout occurs
        for i in range(int(q[1])):  # iterating over the number of edges of the given length to add
            x_new, x_nearest = self.new_and_near(0, q)

            if x_new is None:
                continue

            # connecting the shortest valid edge
            self.connect_to_point(0, x_nearest, x_new)

            solution = self.check_solution()
            if solution[0]:
                return solution[1]

The issue arises because Q is a numpy array, and q[1] is automatically interpreted as a float, causing a problem when passing it to the range() function. To resolve this, I performed an integer type conversion onq[1] using range(int(q[1])).

I'm curious if this is a minor oversight in the code that could be addressed.

Best regards

SZanlongo commented 7 months ago

I see the issue. It's caused by an old experiment where edges were represented as an array of tuples. The idea was that each tuple represented an edge length, and a number of times to try that edge length. That way, you could try different lengths iteratively within the same run. this is somewhat confusing, so I've changed it in favor of a single value. Changes are in d61b21b.