Vehicle

November 7, 2023 ยท View on GitHub

from tdw.add_ons.vehicle import Vehicle

A vehicle is a driving agent such as a car, bus or truck. From this API, you can set the vehicles's speed (drive, turn, brake) and turn its motor on and off.

The vehicle's output data, including images, is stored in vehicle.dynamic.


Class Variables

VariableTypeDescriptionValue
LIBRARY_NAMEstrThe vehicle's library file. You can override this to use a custom library (e.g. a local library)."vehicles.json"

Fields

  • initial_position The initial position of the vehicle.

  • dynamic The initial rotation of the vehicle in Euler angles.

  • vehicle_id The ID of this vehicle.

  • avatar_id The ID of the vehicle's avatar (camera). This is used internally for API calls.

  • commands These commands will be appended to the commands of the next communicate() call.

  • initialized If True, this module has been initialized.


Functions

__init__

Vehicle()

Vehicle(vehicle_id=0, position=None, rotation=None, name="all_terrain_vehicle", forward_speed=30, reverse_speed=12, image_capture=True, image_passes=None)

ParameterTypeDefaultDescription
vehicle_idint0The ID of the vehicle.
positionPOSITIONNoneThe position of the vehicle as an x, y, z dictionary or numpy array. If None, defaults to {"x": 0, "y": 0, "z": 0}.
rotationROTATIONNoneThe rotation of the vehicle in Euler angles (degrees) as an x, y, z dictionary or numpy array. If None, defaults to {"x": 0, "y": 0, "z": 0}.
namestr"all_terrain_vehicle"The name of the vehicle model.
forward_speedfloat30Sets the vehicle's max forward speed.
reverse_speedfloat12Sets the vehicle's max reverse speed.
image_captureboolTrueIf True, the vehicle will receive image and camera matrix data per communicate() call. Whether or not this is True, the vehicle will always render images in the simulation window.
image_passesList[str]NoneA list of image passes that will be captured. Ignored if image_capture == False. If None, defaults to ["_img", "_id"].

get_initialization_commands

self.get_initialization_commands()

This function gets called exactly once per add-on. To re-initialize, set self.initialized = False.

Returns: A list of commands that will initialize this add-on.

on_send

self.on_send(resp)

This is called within Controller.communicate(commands) after commands are sent to the build and a response is received.

Use this function to send commands to the build on the next Controller.communicate(commands) call, given the resp response. Any commands in the self.commands list will be sent on the next Controller.communicate(commands) call.

ParameterTypeDefaultDescription
respList[bytes]The response from the build.

before_send

self.before_send(commands)

This is called within Controller.communicate(commands) before sending commands to the build. By default, this function doesn't do anything.

ParameterTypeDefaultDescription
commandsList[dict]The commands that are about to be sent to the build.

get_early_initialization_commands

self.get_early_initialization_commands()

This function gets called exactly once per add-on. To re-initialize, set self.initialized = False.

These commands are added to the list being sent on communicate() before any other commands, including those added by the user and by other add-ons.

Usually, you shouldn't override this function. It is useful for a small number of add-ons, such as loading screens, which should initialize before anything else.

Returns: A list of commands that will initialize this add-on.

set_drive

self.set_drive(drive)

Set the vehicle's drive force.

ParameterTypeDefaultDescription
drivefloatThe drive force as a float. Must be between -1.0 and 1.0.

set_turn

self.set_turn(turn)

Set the vehicle's turn force.

ParameterTypeDefaultDescription
turnfloatThe turn force as a float. Must be between -1.0 and 1.0.

set_brake

self.set_brake(brake)

Set the vehicle's brake force.

ParameterTypeDefaultDescription
brakefloatThe brake force as a float. Must be between -1.0 and 1.0.