Lifecycle of a Robot

A robot transitions through multiple states during its operation, often for safety and convenience purposes. The robot’s state is also essential for error handling within the automation system it is part of. Therefore, decisions must be based on the robot’s current state, making it crucial to both read and manipulate this state.

The robot instance provided by this library includes multiple states that reflect both the current state of the robot and the status of the interaction between this library and the robot control system. The term lifecycle refers to the typical operational stages of a robot, such as connected, error or ready to move. Additionally, methods to manipulate those states are provided.

Note

To interact with a robot successfully, this library assumes a stable network connection to the robot control is available. Ensure that the robot control is accessible from the machine running this library.

The Lifecycle States of a Robot

A robot of this library always supports the following states:

class LifecycleState(value)

Enum that represents the state of the robot lifecycle.

DISCONNECTED = 'DISCONNECTED'

The robot instance is created. Default value.

CONNECTED = 'CONNECTED'

A connection is established, but the robot is not ready to move.

ENABLED = 'ENABLED'

The robot is ready to move and can receive instructions.

ERROR = 'ERROR'

The robot is in an error state and not ready to move.

Note

A robot might have more specific states, which are accessible in special functions. See Reading the Robot State for details. Note that those states are specific to a robot behavior group and may require additional effort when porting to another robot. If possible, stick to the lifecycle states, as those are available on every robot.

Reading the Lifecycle State

The current lifecycle state of a robot can be read by invoking the get_lifecycle_state() method:

current_state = robot.get_lifecycle_state()
_logger.info("Current state: %s", current_state)  # State DISCONNECTED

Output:

[INFO ]  Current state: DISCONNECTED

Connecting to a Robot

First, the desired robot class must be imported:

from voraus_robot_arm import VorausIndustrialRobotArm

Then, a robot instance is created from it:

robot = VorausIndustrialRobotArm()

After creation, the robot instance will be in the DISCONNECTED state, meaning that no connection to the robot was established yet.

The recommended way of establishing a connection is to use a runtime context. This ensures that the connection is properly closed once the context is left. However, it is also possible to use the connect() and disconnect() methods directly. In order to establish a connection, a robot control host (e.g. IP address or a hostname) and its port must be provided.

with robot.connect(host=VORAUS_CORE_HOST, port=VORAUS_CORE_PORT):
    _logger.info(
        "Current state: %s", robot.get_lifecycle_state()
    )  # State CONNECTED

Enabling the Robot

Most actions require the robot to be put into a moveable state. This is done by using the enable() method.

robot.enable()

Afterwards, the main application logic can be implemented using the functionality provided by this library, as well as any other Python code that helps to solve the given problem.

Once the robot is no longer required to be in a moveable state, the state can be switched again using the disable() method.

robot.disable()

Lastly, the context is left and the connection to the robot is closed automatically. If the context is left while the robot is still in the ENABLED state, disable() will be implicitly called before disconnecting.

Full Example of Lifecycle Handling

The full example on how to work with the robot lifecycle is provided below:

Definition of the Lifecycle Methods

The methods for reading and manipulating the lifecycle state are defined in the LifecycleTrait: