Quick Start Guide
Firstly, you will need to ensure that you have installed j5. You will also need a working knowledge of Python 3.
Your First Robot
The recommended way to use j5 is to first define what the structure of your robot looks like.
You will probably want
from j5 import BaseRobot
class MyRobot(BaseRobot):
"""My Basic Robot definition."""
r = MyRobot()
Adding Boards
To give you robot some functionality, you will need to define what boards are available on your robot.
from j5 import BaseRobot, BoardGroup
from j5.backends.console.sr.v4 import (
SRV4MotorBoardConsoleBackend,
SRV4PowerBoardConsoleBackend,
)
from j5.boards.sr.v4 import MotorBoard, PowerBoard
class MyRobot(BaseRobot):
"""A robot with a few boards."""
def __init__(self) -> None:
self._power_boards = BoardGroup.get_board_group(
PowerBoard,
SRV4PowerBoardConsoleBackend,
)
self.power_board = self._power_boards.singular() # Restrict to exactly one board.
self.motor_boards = BoardGroup.get_board_group(
MotorBoard,
SRV4MotorBoardConsoleBackend,
)
r = MyRobot()
print(f"Found Power Board: {r.power_board.serial_number}")
print(f"Power Board Firmware: {r.power_board.firmware_version}")
# Access a board specific function
r.power_board.wait_for_start_flash()
print(f"Found {len(r.motor_boards)} Motor Board(s):")
# Iterate over the boards in a board group
for board in r.motor_boards:
print(f" - {board.serial_number} - Version {board.firmware_version}")
# Access board by serial number
r.motor_boards["218312"].make_safe()
In order to add some boards to your robot, you will need to define the BoardGroup
for your board.
A BoardGroup
is a group of boards attached to your robot. A BoardGroup
can contain 0 or more of
the specified board. You can also call singular()
on your BoardGroup
, and it will throw an error
if there is not exactly one board of that type connected.
If your robot does not consistent of a modular kit, and is entirely contained within one unit, you do not have to use the board separation, you can instead directly expose components to the use.
Note that whilst we can iterate over a BoardGroup
and access a board in a BoardGroup
by serial, we
cannot access a board using array notation.
Using Components
Whilst it is useful to be able to access attributes and functions that are specific to a board, the real power of j5 is found when you access components and functionality on those boards. j5 has defined a consistent interface for those components, even if they are on separate devices.
from j5 import BaseRobot, BoardGroup
from j5.backends.console.sr.v4 import SRV4PowerBoardConsoleBackend
from j5.boards.sr.v4 import PowerBoard
class MyRobot(BaseRobot):
"""A robot with a few boards."""
def __init__(self) -> None:
self._power_boards = BoardGroup.get_board_group(
PowerBoard,
SRV4PowerBoardConsoleBackend,
)
self.power_board = self._power_boards.singular() # Restrict to exactly one board.
# Expose just a component to the user.
self.big_led = self.power_board.outputs[0]
r = MyRobot()
# Ensure all outputs on the power board are off.
for output in r.power_board.outputs:
output.is_enabled = False
# Turn on the big LED
r.big_led.is_enabled = True
The usual method to access components is to use the definition on the board. It is also possible to expose a component, or even a single attribute on a component as a top level attribute of your Robot object.