跳转至

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.

属性:

名称 类型 描述
robot Robot

The Webots robot instance.

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

Initialize the Webots interface.

参数:

名称 类型 描述 默认
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 property

Get the time step of the simulation.

返回:

名称 类型 描述
int int

The time step of the simulation.

step_lock property

Get the step lock of the simulation.

返回:

名称 类型 描述
Lock Lock

The step lock of the simulation.

start()

Start the simulation.

stop()

Stop the simulation.

time()

Get the current time of the simulation.

返回:

名称 类型 描述
float float

The current time of the simulation.

sleep(seconds)

Sleep for a specified amount of time.

参数:

名称 类型 描述 默认
seconds float

The amount of time to sleep.

必需

返回:

类型 描述
int

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

register(device)

Register a device to the simulation.

参数:

名称 类型 描述 默认
device WebotsDevice

The device to register.

必需

deregister(device)

Deregister a device from the simulation.

参数:

名称 类型 描述 默认
device WebotsDevice

The device to deregister.

必需