跳转至

Webots

robodyno.interfaces.webots

This module provides Webots interface for robodyno devices.

Examples:

from robodyno.interfaces import Webots

def step_callback(webots):
    print(webots.time())

webots = Webots(step_callback=step_callback, start=False)
webots.start()

while True:
    # do something

    if webots.sleep(1) == -1:
        break

webots.stop()

Webots

Bases: object

Webots interface for robodyno devices.

This class provides Webots interface for robodyno devices. It supports managing the time and running the simulation.

A thread is created to run the simulation. When the simulation is running, the callback function will be called every time step.

Attributes:

Name Type Description
robot Robot

The Webots robot instance.

__init__(time_step=None, step_callback=None, start=True)

Initialize the Webots interface.

Parameters:

Name Type Description Default
time_step int

The time step of the simulation. If not specified, the default time step of the robot will be used.

None
step_callback callable

The callback function that will be called every time step.

The function should accept one argument, which is the webots interface instance.

The function should not block for too long, otherwise the simulation will be delayed.

None
start bool

Whether to start the simulation automatically. Defaults to True.

True

time_step: int property

Get the time step of the simulation.

Returns:

Name Type Description
int int

The time step of the simulation.

step_lock: Lock property

Get the step lock of the simulation.

Returns:

Name Type Description
Lock Lock

The step lock of the simulation.

start()

Start the simulation.

stop()

Stop the simulation.

time()

Get the current time of the simulation.

Returns:

Name Type Description
float float

The current time of the simulation.

sleep(seconds)

Sleep for a specified amount of time.

Parameters:

Name Type Description Default
seconds float

The amount of time to sleep.

required

Returns:

Type Description
int

0 if the simulation is running, -1 if the simulation is stopped.

register(device)

Register a device to the simulation.

Parameters:

Name Type Description Default
device WebotsDevice

The device to register.

required

deregister(device)

Deregister a device from the simulation.

Parameters:

Name Type Description Default
device WebotsDevice

The device to deregister.

required