Skip to content


This example is similar to Click-and-drive but includes a PathPlanner to find a path around an obstacle.

#!/usr/bin/env python3
from nicegui import ui
from import SceneClickEventArguments

from rosys.automation import Automator
from rosys.driving import Driver, Odometer, robot_object
from rosys.geometry import Point, Pose, Prism
from rosys.hardware import RobotSimulation, WheelsSimulation
from rosys.pathplanning import Obstacle, PathPlanner, obstacle_object, path_object

shape = Prism.default_robot_shape()
path_planner = PathPlanner(shape)
path_planner.restore = lambda _: None  # NOTE: disable persistence
path_planner.obstacles['0'] = Obstacle(id='0', outline=[Point(x=3, y=0), Point(x=0, y=3), Point(x=3, y=3)])
wheels = WheelsSimulation()
robot = RobotSimulation([wheels])
odometer = Odometer(wheels)
driver = Driver(wheels, odometer)
automator = Automator(None, on_interrupt=wheels.stop)

async def handle_click(e: SceneClickEventArguments):
    for hit in e.hits:
        if hit.object_id == 'ground':
            goal = Pose(x=hit.x, y=hit.y, yaw=odometer.prediction.direction(Point(x=hit.x, y=hit.y)))
            path = await, goal=goal)

with ui.scene(on_click=handle_click, width=600):
    robot_object(shape, odometer)
    path3d = path_object()

ui.label('click into the scene to drive the robot')'RoSys')

Path Following

When following a path, a "carrot" is dragged along a spline and the robot follows it like a donkey. Additionally, there is a virtual "hook" attached to the robot, which is pulled towards the carrot.

There are three parameters:

  • hook_offset: How far from the wheel axis (i.e. the coordinate center of the robot) is the hook, which is pulled towards the carrot.
  • carrot_offset: How far ahead of the carrot is the robot pulled. This parameter is necessary in order to have the hook pulled a bit further, even though the carrot already reached the end of the spline.
  • carrot_distance: How long is the "thread" between hook and carrot (or the offset point ahead of the carrot, respectively).

In the following illustration these points are depicted as spheres: the coordinate center of the robot (blue, small), the hook (blue, large), carrot (orange, small), offset point ahead of the carrot (orange, large).

Navigation Geometry

You can display a wire frame version of the robot by passing debug=true to the robot_object.


The automation drive_spline has an optional argument flip_hook. It turns the hook 180 degrees to the back of the robot, while preserving the distance hook_offset to the robot's coordinate center. This allows the robot to drive backwards to a point behind it instead of turning around and approaching it forwards.

A more complex example can be found in the RoSys GitHub repository. There you can create new obstacles and choose between straight driving or navigation.