Node#

class pyaseba.network.Node(node_id: int, name: str = 'node', default_variables: bool = True, default_functions: bool = True, uuid: Sequence[int] = ..., advertised_name: str = '')#
Parameters:
  • node_id – The id of the node. It should be unique in the same network.

  • name – The name of the node.

  • default_variables – Whether to add Aseba default native variables.

  • default_functions – Whether to add Aseba default native functions.

  • uuid – An optional unique identifier for auto-discovery

  • advertised_name – An optional alternative name to use for auto-discovery

Examples

The base class is typically sub-classed to implement specific Aseba nodes.

>>> class MyNode(Node):

We can add Aseba local events by specifying names,

>>>     events = ["event"]

Aseba variables by specifying tuples of (name, size),

>>>     variables = [("value", 1)]

and Aseba local functions by specifying tuples of (name, parameters), where each parameters is specified by a size and a name. The name must corresponds to a compatible Python method

>>>     functions = [("add", [(1, "first"), (1, "second")])]
>>>
>>>     def add(self, first: list[int], second: list[int]) -> None:
>>>         if (len(first) == len(second) == 1):
>>>             result = [x + y for x, y in zip(first, second)]
>>>             self.set("value", result)

We can also override virtual functions init(), tick(), and reset() to specialize a node.

>>>     def init(self) -> None:
>>>         self.set("value", 0)
>>>
>>>     def tick(self, time_step: float) -> None:
>>>         self.emit("event")
>>>
>>>     def reset(self) -> None:
>>>         self.set("value", 0)

Nodes should be added to a network, else they will not perform any work.

>>> network = Network()
>>> network.add_node(MyNode(id=0))

During spinning, the network will dispatch Aseba messages to the node and call py:meth:tick every time_step seconds.

>>> network.spin(time_step=0.1)
events: dict[str, str]#

A dictionary of {name: description} Set it in sub-classes to define local events; the base class does not set the attribute.

functions: dict[str, tuple[str, list[tuple[str, int]]]]#

A dictionary of {name: (description, arguments}, where each argument is a tuple (name, size). Set it in sub-classes to define variables; the base class does not set the attribute.

variables: dict[str, int]#

A dictionary of {name: size}. Set it in sub-classes to define variables; the base class does not set the attribute.

property description#

The node description (readonly).

emit(self, name: str) None#

Emits a local event. The list of events should be known a-priori by specifying the class py:attr:Node.events.

Parameters:

name – the name of the event.

get(self, name: str) list[int]#

Gets the value of an Aseba variable. The variable should be defined a-priori by specifying the specific class py:attr:Node.variables or as part of the default Aseba variables.

Parameters:

name – the variable name.

Returns:

the variable value.

get_all(self) dict[str, list[int]]#

Gets the current value of all Aseba variables

Returns:

A dictionary of variable values keyed by variable names.

property name#

The node name (readonly)..

property node_id#

The node id (readonly).

set(self, name: str, value: Sequence[int]) None#

Sets the value of an Aseba variable. The variable should be defined a-priori by specifying the specific class py:attr:Node.variables or as part of the default Aseba variables.

Parameters:
  • name – the variable name.

  • value – the variable value.