j5 package

Subpackages

Module contents

j5 Robotics API.

class j5.BoardGroup(backend_class: Type[U])[source]

Bases: typing.Generic

A group of boards that can be accessed.

backend_class

The Backend that this group uses for Boards.

Returns:The backend used to interact with boards.
boards

Get an unordered list of boards in this group.

Returns:unordered list of boards in this group.
classmethod get_board_group(_: Type[T], backend: Type[U]) → j5.boards.board_group.BoardGroup[~T, ~U][T, U][source]

Get the board group with the given types.

Whilst the first parameter value is not actually used in the function, we need it for typing purposes. This is similar to how a ProxyType works in Haskell.

Parameters:backend – The class of backend to get.
Returns:A BoardGroup containing all of the backends of the requested type.
make_safe() → None[source]

Make all of the boards safe.

singular() → T[source]

If there is only a single board in the group, return that board.

Returns:The instance of the only board in the group.
Raises:CommunicationError – Multiple boards were found.
update_boards() → None[source]

Update the boards in this group to see if new boards have been added.

class j5.BaseRobot[source]

Bases: object

A base robot.

make_safe() → None[source]

Make this robot safe.

class j5.Environment(name: str)[source]

Bases: object

A collection of backends that can work together.

A number of Backends that we wish to use in a grouping, such as those that all work together in hardware can be added to this group. We can then pass Environments to a Robot object, so that the Robot object can call different methods based on where it is being used.

e.g Hardware Environment

We have n boards of n different types. They are all physical hardware. We create an Environment containing the Backends to control the physical hardware for our boards.

It is later realised that we want to test code without the physical hardware. We can add Console backends to an environment, and instantiate our Robot object with that environment, so that the console is manipulated rather than the hardware.

This allows for a high degree of code reuse and ensures API compatibility in different situations.

get_backend(board: Type[Board]) → Type[j5.backends.backend.Backend][source]

Get the backend for a board.

Parameters:board – board type to fetch a backend for.
Returns:Backend in this environment for the given board.
Raises:NotImplementedError – The environment does not support the board.
get_board_group(board: Type[BoardT]) → j5.boards.board_group.BoardGroup[~BoardT, j5.backends.backend.Backend][BoardT, j5.backends.backend.Backend][source]

Get a board group for the given board type.

Parameters:board – board type to fetch a backend for.
Returns:BoardGroup in this environment for the given board.
Raises:NotImplementedError – The environment does not support the board.
merge(other: j5.backends.environment.Environment) → None[source]

Merge in the board-backend mappings from another environment.

This allows vendors to predefine Environments and API authors can then merge several vendor environments to get the one that they need for their API.

This method will fail if any board is defined in both environments,
as it is unclear which one has the correct mapping.
Parameters:other – environment to merge into this one.
Raises:RuntimeError – a board was implemented in both backends, conflict.
register_backend(backend: Type[j5.backends.backend.Backend]) → None[source]

Register a new backend with this environment.

Parameters:backend – The backend to register in the environment.
Raises:RuntimeError – The backend has already been registered.
supported_boards

The boards that are supported by this environment.

Returns:set of boards that are supported by this environment.