RobotBase

November 7, 2023 ยท View on GitHub

from tdw.add_ons.robot_base import RobotBase

Abstract base class for robots.


Class Variables

VariableTypeDescriptionValue
NON_MOVINGfloatIf a joint has moved less than this many degrees (revolute or spherical) or meters (prismatic) since the previous frame, it is considered to be not moving for the purposes of determining which joints are moving.0.001

Fields

  • initial_position The initial position of the robot.

  • initial_rotation The initial rotation of the robot.

  • robot_id The ID of this robot.

  • static Static robot data.

  • dynamic Dynamic robot data.

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

  • initialized If True, this module has been initialized.


Functions

__init__

RobotBase()

RobotBase(robot_id=0, position=None, rotation=None)

ParameterTypeDefaultDescription
robot_idint0The ID of the robot.
positionDict[str, float]NoneThe position of the robot. If None, defaults to {"x": 0, "y": 0, "z": 0}.
rotationDict[str, float]NoneThe rotation of the robot in Euler angles (degrees). If None, defaults to {"x": 0, "y": 0, "z": 0}.

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 after commands are sent to the build and a response is received.

Use this function to send commands to the build on the next frame, given the resp response. Any commands in the self.commands list will be sent on the next frame.

ParameterTypeDefaultDescription
respList[bytes]The response from the build.

before_send

self.before_send(commands)

This is called 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.

joints_are_moving

self.joints_are_moving()

self.joints_are_moving(joint_ids=None)

ParameterTypeDefaultDescription
joint_idsList[int]NoneA list of joint IDs to check for movement. If None, check all joints for movement.

Returns: True if the joints are moving.

reset

self.reset()

self.reset(position=None, rotation=None)

Reset the robot.

ParameterTypeDefaultDescription
positionDict[str, float]NoneThe position of the robot.
rotationDict[str, float]NoneThe rotation of the robot.