Digital Inputs and Outputs

Digital inputs and outputs are used for communication between a robot and external devices or sensors by digital signals. Unlike analog signals, digital signals are binary, they can only be in one of two states: HIGH (1 / True) or LOW (0 / False). Digital inputs can only be read, while digital outputs can be read and written to.

Depending on the specific robot, a digital input or output may represent a physical pin on the robot cabinet or an abstract bit on a fieldbus.

Note

Interacting with Digital I/Os is currently only supported for robots within the Victor Robot Behavior Group.

Read and Write Digital Inputs and Outputs

A digital output is represented by a DigitalOutput object and a digital input by a DigitalInput object.

They can be retrieved through the functions get_digital_input_v() and get_digital_output_v. Both functions require a numeric identifier which pin they should retrieve. The first pin has id 1.

A digital output pin can be set by calling the set() method on the pin object. In order to read the current value of digital output or digital input, use the is_set() method.

For a quick interaction it is possible to read, set and clear a digital output inline like this:

output_id = 1

robot.get_digital_output_v(output_id).set()

output_value = robot.get_digital_output_v(output_id).is_set()
_logger.info("Output '%s' has value '%s'", output_id, output_value)

robot.get_digital_output_v(output_id).clear()

Digital inputs can only be read but can be used in the same fashion.

If one input or output is used multiple times, the output object can be assigned to a variable and used without retrieving it multiple times.

output = robot.get_digital_output_v(1)

output.set()
_logger.info(
    "Output '%s' has value '%s'", output.get_id(), output.is_set()
)
output.clear()

Using Input and Output Groups

While single inputs and outputs often are sufficient enough control simple logic, most peripherals require setting more than one output or reading more than one input together.

voraus_robot_arm provides the DigitalInputGroup and DigitalOutputGroup to bundle multiple inputs and outputs in one convenient object.

They can be retrieved through the functions get_digital_input_group_v() and get_digital_output_group_v. Similar to their non group counterparts the methods require a list of numeric identifiers which inputs or outputs they should control.

The current values of the whole group can then be read and returned in different data styles with to_dict(), to_tuple() and to_int() methods.

Similarly, all inputs can be set from the same data types with the methods set_from_dict(), set_from_tuple() and set_from_int().

Please note that the control of a group is not exclusive and single inputs and outputs can still be set as normally. It is also possible to share outputs and inputs between multiple groups. Also note, that it depends on the robot control in use whether the values of a group are read and written at once or sequential.

The following example shows how multiple conveyors connected to digital outputs 1,2 and 4 could be activated and deactivated:

conveyors = robot.get_digital_output_group_v((1, 2, 4))

on = {1: True, 2: False, 4: True}
off = {1: False, 2: False, 4: False}

conveyors.set_from_dict(on)

_logger.info("Conveyors have the state %s", conveyors.to_tuple())

conveyors.set_from_dict(off)

Full Example

The following example shows a simple interaction with digital inputs and outputs:

Definition of the Digital Input and Output Methods

The digital input related functionality is defined in the DigitalInputVictorTrait:

The digital input related functionality is defined in the DigitalOutputVictorTrait: