roboglia.base.BaseRobot

class BaseRobot(name='ROBOT', buses={}, inits={}, devices={}, joints={}, sensors={}, groups={}, syncs={}, manager={})[source]

Bases: object

A complete representation of a robot.

A robot has at minimum one Bus and one Device. You can create a robot programatically by calling the constructor and providing all the parameters required or use an initialization dictionary or a YAML file. The last option is the preferred one considering the volume of information usually needed to describe a robot.

For initializing a robot from a dictionary definition use from_dict() class method. For instantiating from a YAML file use from_yaml() class method.

Parameters
  • name (str) – the name of the robot; will default to ROBOT

  • buses (dict) – a dictionary with buses definitions; the components of the buses are defined by the attributes of the particular class of the bus

  • inits (dict) –

    a dictionary of register initialization; should have the following form:

    inits:
        init_template_1:
            register_1: value
            register_2: None     # this indicates 'read initialization'
        init_template_2:
            register_3: value
            register_4: value
    

    see also the BaseDevice where the details of the initialization process are described

  • devices (dict) – a dictionary with the device definitions; the components of devices are defined by the attributes of the particular class of device

  • joints (dict) – a dictionary with the joint definitions; the components of the joints are defined by the attributes of the particular class of joint

  • sensors (dict) – a dictionary with the sensors defintion; the components of the sensor are defined by the attributes of the particular class of sensor

  • groups (dict) – a dictionary with the group definitions; the groups end up unwind in the robot as sets (eliminates duplication) and they are defined by the following components (keys in the dictionary defintion): devices a list of device names in no particular order, joints a list of joint names in no particular order, sensors a list of sensors in no particular order and groups a list of sub-groups that were previously defined and will be included in the current group. Technically it is possible to mix and match the components of a group (for instance create groups that contain devices, sensors, and joints).

  • syncs (dict) – a dictionary with sync loops definitions; the components of syncs are defined by the attributes of the particular class of sync.

__init__(name='ROBOT', buses={}, inits={}, devices={}, joints={}, sensors={}, groups={}, syncs={}, manager={})[source]

Initialize self. See help(type(self)) for accurate signature.

classmethod from_yaml(file_name)[source]

Initializes the robot from a YAML file. It will attempt to read the file and parse it with yaml library (PyYaml) and then passes it to the from_dict() class method to do further initialization.

Parameters

file_name (str) – The name of the YAML file with the robot definition

Raises

FileNotFoundError – in case the file is not available

add_bus(bus_obj)[source]

Adds an already instantiated Bus object to the robot. Raises an error in the log if a bus with the same name is already registered and does not register it.

Parameters

bus_obj (BaseBus or subclass) – The bus to be added

add_device(dev_obj)[source]

Adds an already instantiated Device object to the robot. Raises an error in the log if a device with the same name is already registered and does not register it.

Parameters

dev_obj (BaseDevice or subclass) – The device to be added

property name

(read-only) The name of the robot.

property buses

(read-only) The buses of the robot as a dict.

property inits

The initialization templates defined for the robot.

property devices

(read-only) The devices of the robot as a dict.

device_by_id(dev_id)[source]

Returns a device by it’s ID.

Parameters

dev_id (int) – the ID or device to be returned

Returns

the register with that ID in the device. If no register with that ID exists, returns None.

Return type

BaseRegister

property joints

(read-only) The joints of the robot as a dict.

property sensors

The sensors of the robot as a dict.

property groups

(read-only) The groups of the robot as a dict.

property syncs

(read-only) The syncs of the robot as a dict.

property manager

The RobotManager of the robot.

start()[source]

Starts the robot operation. It will:

  • call the open() method on all buses except the ones that have auto set to False

  • call the open() method on all devices except the ones that have auto set to False

  • call the start() method on all syncs except the ones that have auto set to False

stop()[source]

Stops the robot operation. It will:

  • call the stop() method on all syncs

  • call the close() method on all devices

  • call the close() method on all buses