electronic_io package

electronic_io.pins module

API for working with electrical I/O pins.

class electronic_io.pins.DigitalPin(name, pin_info, inverted)

Bases: electronic_io.pins.RealIOPin

Digital I/O pin (represents a binary value).

Initialize the pin with the given parameters.

Parameters:
  • name (str) – Name of the pin. This name is used to refer to the pin in all parts of this library.
  • pin_info (DigitalIOInfo) – Metadata about the pin.
  • inverted (bool) – Whether readings of this pin should be seamlessly inverted.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
static from_dict(config, io_info)

Create the pin from the given config dictionary and board information.

Parameters:
  • config (dict or str) – The configuration dictionary (or a string containing just the pin name).
  • io_info (IOInfo) – Info about the I/O pins of a board.
Returns:

The configured pin.

Return type:

IOPin

Raises:

AttributeError – When wrong configuration is passed.

get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None
class electronic_io.pins.DigitizedAnalogPin(name, pin_info)

Bases: electronic_io.pins.RealIOPin

Digitized analog I/O pin (works with integral readings of an A/D converter).

Initialize the pin with the given parameters.

Parameters:
  • name (str) – Name of the pin. This name is used to refer to the pin in all parts of this library.
  • pin_info (DigitizedAnalogIOInfo) – Metadata about the pin.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
static from_dict(config, io_info)

Create the pin from the given config dictionary and board information.

Parameters:
  • config (dict or str) – The configuration dictionary (or a string containing just the pin name).
  • io_info (IOInfo) – Info about the I/O pins of a board.
Returns:

The configured pin.

Return type:

IOPin

Raises:

AttributeError – When wrong configuration is passed.

get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None
class electronic_io.pins.IOPin(name, pin_info)

Bases: object

Generic input-output pin representation.

Initialize the pin with the given parameters.

Parameters:
  • name (str) – Name of the pin. This name is used to refer to the pin in all parts of this library.
  • pin_info (DigitalIOInfo or DigitizedAnalogIOInfo or RawAnalogIOInfo) – Metadata about the pin.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None
class electronic_io.pins.RawAnalogPin(name, pin_info)

Bases: electronic_io.pins.RealIOPin

Raw analog I/O pin (works directly with float values).

Initialize the pin with the given parameters.

Parameters:
  • name (str) – Name of the pin. This name is used to refer to the pin in all parts of this library.
  • pin_info (RawAnalogIOInfo) – Metadata about the pin.
add_read_request(req)

Modify the passed read request to also query information relevant for this pin.

Parameters:req (ReadRequest) – The read request to modify.
add_write_request(value, req)

Modify the passed write request to write the given value to this pin.

Parameters:
  • value (bool or int or float) – The value to write.
  • req (WriteRequest) – The write request to modify.
static from_dict(config, io_info)

Create the pin from the given config dictionary and board information.

Parameters:
  • config (dict or str) – The configuration dictionary (or a string containing just the pin name).
  • io_info (IOInfo) – Info about the I/O pins of a board.
Returns:

The configured pin.

Return type:

IOPin

Raises:

AttributeError – When wrong configuration is passed.

get_value(readings)

Read value of the pin from the given set of readings.

Parameters:readings (Readings) – The readings to parse.
Returns:The parsed value. If there is no reading for this pin in the given data, None is returned.
Return type:bool or int or float or None
class electronic_io.pins.RealIOPin(name, pin_info)

Bases: electronic_io.pins.IOPin

A real input-output pin on an I/O board.

Initialize the pin with the given parameters.

Parameters:
  • name (str) – Name of the pin. This name is used to refer to the pin in all parts of this library.
  • pin_info (DigitalIOInfo or DigitizedAnalogIOInfo or RawAnalogIOInfo) – Metadata about the pin.
static find_pin_info(config, io_info)

Create the pin from the given config dictionary and board information.

Parameters:
  • config (dict or str) – The configuration dictionary (or a string containing just the pin name).
  • io_info (list of DigitalIOInfo or list of DigitizedAnalogIOInfo or list of RawAnalogIOInfo) – Info about the I/O pins of a board.
Returns:

The corresponding pin info if it was found, and the config dictionary. If the function does not raise, the config is guaranteed to contain key ‘pin’ with the name of the requested pin.

Return type:

(DigitalIOInfo or DigitizedAnalogIOInfo or RawAnalogIOInfo or None, dict)

Raises:

AttributeError – When wrong configuration is passed.

static from_dict(config, io_info)

Create the pin from the given config dictionary and board information.

Parameters:
  • config (dict or str) – The configuration dictionary (or a string containing just the pin name).
  • io_info (IOInfo) – Info about the I/O pins of a board.
Returns:

The configured pin.

Return type:

IOPin

Raises:

AttributeError – When wrong configuration is passed.

class electronic_io.pins.VirtualPin(name, pin_info)

Bases: electronic_io.pins.IOPin

Virtual I/O board pin which performs some computation on real I/O pins.

Initialize the pin with the given parameters.

Parameters:
  • name (str) – Name of the pin. This name is used to refer to the pin in all parts of this library.
  • pin_info (DigitalIOInfo or DigitizedAnalogIOInfo or RawAnalogIOInfo) – Metadata about the pin.
static from_dict(pin_name, config, io_board)

Create the pin from the given config dictionary and board information.

Parameters:
  • pin_name (str) – Name of the pin (its config dictionary key).
  • config (dict) – Configuration of the pin.
  • io_board (IOBoardClient) – The I/O board this pin should use (but it is not added to it automatically).
Returns:

The virtual pin.

Return type:

VirtualPin

Raises:

AttributeError – When wrong configuration is passed.

electronic_io.device module

This module provides basic APIs for implementing I/O devices.

An I/O device as understood by this package is a collection of I/O pins whose values together form a logical unit.

There are several basic types of devices:

  • InputDevice: Device that reads some pins and publishes values on a topic.
  • OutputDevice: Device that receives service requests to change to values of some pins. These devices can have
    readback, which means the values of the pins can also be read.
  • MetaDevice: A composite device consisting from several other (non-meta) devices.
class electronic_io.device.Device(name, config, io_board)

Bases: object

Base class for all devices. They must extend it.

Parameters:
  • name (str) – Name of the device. The name has to be unique.
  • config (dict) – Configuration of the device as a dictionary. Key ‘topic’ is required, but can be empty.
  • io_board (IOBoardClient) – The I/O board on which the device will be controlling pins.
Raises:

AttributeError – If invalid config is provided.

get_name()

Get a human-friendly name of the device.

Returns:The name.
Return type:str
class electronic_io.device.DigitalOutputDevice(name, config, io_board)

Bases: electronic_io.device.OutputDevice

Specialized output device which also provides service ~/toggle to toggle the digital value if readback is provided.

Create the specialized output device.

Parameters:
  • name (str) – Name of the device. The name has to be unique.
  • config (dict) – Configuration of the device as a dictionary.
  • io_board (IOBoardClient) – The I/O board on which the device will be controlling pins. The board has to be writable.
set_readback_device(device)

Set the readback device.

Parameters:device (InputDevice) – The device to set.
set_value_cb(request)

Callback called by the ~/set service.

Parameters:request – The setter service request.
toggle(_request)
class electronic_io.device.InputDevice(name, config, io_board, topic_type, queue_size=1, latch=True, initial_value=None)

Bases: electronic_io.device.Device

Base class for input devices.

Parameters:
  • name (str) – Name of the device. The name has to be unique.
  • config (dict) – Configuration of the device as a dictionary.
  • io_board (IOBoardClient) – The I/O board on which the device will be controlling pins. The board has to be readable.
  • topic_type (type) – ROS message type of the published topic.
  • queue_size (int) – Default queue size used for the publisher if not explicitly overridden in config.
  • latch (bool) – Default latching value used for the publisher if not explicitly overridden in config.
  • initial_value – Optional initial value that should be used before the first physical read succeeds.
add_read_request(req)

Modify the passed read request to collect all information needed by this device.

Parameters:req (ReadRequest) – The request to modify.
create_message(value, header)

Convert the given value to a ROS message that can be published by this device.

Parameters:
  • value – The value to convert.
  • header (std_msgs/Header) – Header to be used in the message (if needed).
Returns:

The ROS message.

Return type:

genpy.Message

get_value(readings)

Extract value of this device from the given pin readings.

Parameters:readings (Readings) – Values of pins.
Returns:The value.
read(use_last_value=False)

Read values of the pins and convert them to a value.

Parameters:use_last_value (bool) – When true, this call returns the previously returned value instead of actually reading the pins.
Returns:The value.
update(readings)

Parse the given pin readings, convert them to a ROS message and publish it.

Parameters:readings (Readings) – Values of pins.
class electronic_io.device.MetaDevice(name, config, io_board, devices)

Bases: object

Tagging class denoting devices that work on other devices, i.e. need to be loaded last.

Base class for composite devices.

Parameters:
  • name (str) – Name of the device. The name has to be unique.
  • config (dict) – Configuration of the device as a dictionary.
  • io_board (IOBoardClient) – The I/O board on which the device will be controlling pins. The board has to be writable.
  • devices (dict) – Dictionary of already loaded devices.
class electronic_io.device.OutputDevice(name, config, io_board, service_type)

Bases: electronic_io.device.Device

Base class for output devices.

Parameters:
  • name (str) – Name of the device. The name has to be unique.
  • config (dict) – Configuration of the device as a dictionary.
  • io_board (IOBoardClient) – The I/O board on which the device will be controlling pins. The board has to be writable.
  • service_type (type) – ROS service type of the setter service.
get_readback_device()

Get the device used for readback.

Returns:The device or None if it is not set.
Return type:InputDevice
has_readback()

Whether this device has readback pin.

Return type:bool
set_readback_device(device)

Set the readback device.

Parameters:device (InputDevice) – The device to set.
set_value(value)

Set the given value and propagate it to pins.

Parameters:value (Any) – The value to set.
Returns:Whether setting the value succeeded.
Return type:bool
set_value_cb(request)

Callback called by the ~/set service.

Parameters:request – The setter service request.
electronic_io.device.load_class(conf, name)

Dynamically load a class specified by the given config’s ‘type’ key.

Parameters:
  • conf (dict) – Configuration dictionary. Has to contain key ‘type’.
  • name (str) – The name to be used in error messages.
Returns:

The corresponding type, or None.

Return type:

type or None

electronic_io.device.load_devices(devices_conf, io_board)

Load devices from the given config dictionary.

Parameters:
  • devices_conf (dict) – The dictionary with configuration.
  • io_board (IOBoardClient) – The I/O board on which the devices will operate.
Returns:

The loaded devices.

Return type:

dict

Raises:

AttributeError – If invalid configuration has been provided.

electronic_io.device.load_virtual_pins(virtual_pins_conf, io_board)

Load virtual pins from the given config dictionary into the io_board.

Parameters:
  • virtual_pins_conf (dict) – The dictionary with configuration.
  • io_board (IOBoardClient) – The I/O board for which the virtual pins are defined.
Raises:

AttributeError – If invalid configuration has been provided.

electronic_io.io_board_client module

Client for communicating with an I/O board.

class electronic_io.io_board_client.IOBoardClient(base_topic)

Bases: object

Client for communicating with an I/O board.

Parameters:base_topic (str) – Base topic (namespace) used by all the other ROS endpoints.
add_virtual_pin(pin)

Add the given virtual pin.

Parameters:pin (VirtualPin) – The virtual pin to add.
can_read()

Whether this board has some readable pins.

Returns:Whether the board can be read.
Return type:bool
can_write()

Whether this board has some writable pins.

Returns:Whether the board can be written to.
Rtype bool:
get_digital_pin(config)

Get a digital pin corresponding to the given config.

Parameters:config (dict) – The pin’s config dictionary.
Returns:The pin.
Return type:DigitalPin or VirtualPin
get_digitized_analog_pin(config)

Get a digitized analog pin corresponding to the given config.

Parameters:config (dict) – The pin’s config dictionary.
Returns:The pin.
Return type:DigitizedAnalogPin or VirtualPin
get_io_info()

Get the I/O pins description.

Returns:Pin descriptions.
Return type:IOInfo
get_raw_analog_pin(config)

Get a raw analog pin corresponding to the given config.

Parameters:config (dict) – The pin’s config dictionary.
Returns:The pin.
Return type:RawAnalogPin or VirtualPin
get_virtual_pin(config)

Get virtual pin corresponding to the given config.

Parameters:config (dict or str) – Config with key ‘pin’ that specifies name of the pin, or just a string with the name.
Returns:The virtual pin or None if it does not exist.
Return type:VirtualPin or None
read(req)

Read values for filling the given request.

Parameters:req (ReadRequest) – The request specifying the pins to read.
Returns:The pin values.
Return type:Readings
write(req)

Write values from the given request to the pins.

Parameters:req (WriteRequest) – The request specifying the pins to write and their values.
Returns:The pin values.
Return type:Readings

electronic_io.io_board_server module

Base for implementation of I/O board drivers exposing their pins via the read/write services or a topic.

class electronic_io.io_board_server.IOBoardServer(base_topic)

Bases: object

Base for implementing I/O board driver.

Parameters:base_topic (str) – The base topic to use for publishing messages.
poll_forever(rate)

Poll and publish values indefinitely.

Parameters:rate (Rate) – The polling rate.
poll_once()

Poll values of all pins and publish - only once.