zauberzeug / rosys

An all-Python robot system based on web technologies. The purpose is similar to ROS, but it's based on NiceGUI and easier to use for mobile robotics.
https://rosys.io
MIT License
78 stars 10 forks source link

Carrot.move() strategy is not optimal for long splines. #22

Closed AndyPermaRobotics closed 1 year ago

AndyPermaRobotics commented 1 year ago

Hello everyone,

I noticed an issue with the rosys driver, that aborts long splines, before the robot reaches the end of the spline.

image

On the image, you can see, that the robot started to move to Waypoint 2, before it reached Waypoint 1.

I figured out, that the reason is, that in the Carrot.move() method the carrot is moved forward by 1% of the spline length. For very long splines this procedure leads to the behavior in the screenshot.

I would suggest to calculate a step_size for the move() Method based on the desired distance and the spline length.

Here is my code:

@dataclass(kw_only=True)
class Carrot:
    __slots__ = ['spline', 'offset', 't', 'estimated_length']
    spline: Spline
    offset: Point = field(default_factory=lambda: Point(x=0, y=0))
    t: float = 0

    def __post_init__(self):
        self.estimated_length = self.spline.estimated_length()

    def move(self, hook: Point, distance: float) -> bool:
        step_size = distance / self.estimated_length

        while hook.distance(self.offset_point) < distance:
            self.t += step_size
            if self.t >= 1.0:
                return False
        return True

Even in this example the distance between hook and carrot can be quite far away from the given distance. Maybe it would be better to calculate the step_size like this: step_size = distance / self.estimated_length / 10.

I could not create a pull request, because of missing permissions, therefore I created this issue.

Best regards Andreas

falkoschindler commented 1 year ago

Hi Andreas,

thanks for bringing this up! You're right, the carrot move strategy doesn't work well for long splines. Because of the rather complicated nature of splines it isn't trivial to move the carrot by an exact distance. Therefore I originally chose the rather arbitrary value of 0.01 (in terms of parameter t) and never improved upon this solution.

But as you demonstrated, we can use the spline's estimated_length to relate the carrot distance to the approximate spline length. You should, however, divide by something like 10 (as you suggested) to compensate for multiple aspects:

A pull request would be very welcome. I just checked the repository settings: You should be able to post PRs. I actually don't understand why you should be lacking permissions. Maybe you can try again and, if the problem persists, provide a more detailed description of the error you're seeing? Thanks!