Skip to content

Simulation Speed

When running in simulation you can accelerate the time. Here we have set up a fence in which the robot moves to random positions. With a simple slider the execution time is accelerated. Note how the time advances faster if the simulation speed is increased. The driving speed of the robot remains the same.

simulation speed

This is achieved simply by placing rosys.simulation_ui() in your UI. The rest of the code is needed to define the boundary, draw it in the 3D scene and start the automation for random movement:

#!/usr/bin/env python3
import random

from nicegui import ui

import rosys
from rosys.automation import Automator
from rosys.driving import Driver, Odometer, robot_object
from rosys.geometry import Point, Prism
from rosys.hardware import RobotSimulation, WheelsSimulation

wheels = WheelsSimulation()
robot = RobotSimulation([wheels])
odometer = Odometer(wheels)
driver = Driver(wheels, odometer)
driver.parameters.linear_speed_limit = 3
driver.parameters.angular_speed_limit = 1
automator = Automator(None, on_interrupt=wheels.stop)

size = 3
boundary = [(-size, -size), (-size, size), (size, size), (size, -size)]

with ui.scene() as scene:
    robot_object(Prism.default_robot_shape(), odometer)
    for i, a in enumerate(boundary):
        b = boundary[(i+1) % len(boundary)]
        ui.scene.line([*a, 0.1], [*b, 0.1]).material('red')
    scene.move_camera(0, 0, 8)
with ui.column().style('width: 400px'):

async def move_around():
    while True:
        await driver.drive_to(Point(x=random.uniform(-size, size), y=random.uniform(-size, size)))

rosys.on_startup(lambda: automator.start(move_around()))'RoSys')