Skip to content

Commit 2898f86

Browse files
authored
Merge pull request #359 from sourcebots/docs-update
Update README with overview of new API
2 parents 2168e67 + ab260b0 commit 2898f86

File tree

1 file changed

+70
-17
lines changed

1 file changed

+70
-17
lines changed

README.md

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
[![Lint & build](https://github.com/sourcebots/sbot/actions/workflows/test_build.yml/badge.svg)](https://github.com/sourcebots/sbot/actions/workflows/test_build.yml)
44
[![PyPI version](https://badge.fury.io/py/sbot.svg)](https://badge.fury.io/py/sbot)
5-
[![Documentation Status](https://readthedocs.org/projects/pip/badge/?version=stable)](http://pip.pypa.io/en/stable/?badge=stable)
5+
[![Documentation Status](https://readthedocs.org/projects/sbot/badge/?version=stable)](https://docs.sourcebots.co.uk)
66
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://opensource.org/licenses/MIT)
77
![Bees](https://img.shields.io/badge/bees-110%25-yellow.svg)
88

99
`sbot` - SourceBots Robot API
1010

11-
This is the API for SourceBots, library for writing Robotics APIs.
12-
It will first be deployed at Smallpeice 2023.
11+
This is the API for Southampton Robotics Outreach robotics competitions.
1312

1413
## Installation
1514

@@ -27,40 +26,94 @@ pip install sbot[vision]
2726

2827
## Usage
2928

30-
The main entry point for the API is the `Robot` class.
31-
Intantiating this class will automatically detect and connect to any SR v4 boards connected to the device.
32-
By default, the `Robot` class will wait for the start button on the power board to be pressed before continuing.
29+
Importing the module will, by default, trigger board discovery and wait for the start button to be pressed.
3330

3431
```python
32+
import sbot
33+
```
34+
35+
Unlike previous versions, robot functionality is accessed directly from the `sbot` library instead of instantiating a class.
36+
37+
```python
38+
from sbot import *
39+
40+
motors.set_power(0, 0.3)
41+
motors.set_power(1, 0.3)
3542

36-
from sbot import Robot
43+
power.get_output_current(PowerOutputPosition.H0)
44+
utils.sound_buzzer(880, 0.5)
3745

38-
r = Robot()
46+
servos.set_position(0, 45/90)
3947

48+
print(arduino.measure_ultrasound_distance(8, 9))
49+
50+
if comp.is_competition:
51+
markers = vision.detect_markers()
52+
leds.set_colour(0, Colour.MAGENTA)
4053
```
4154

42-
To disable the waiting for the start button, you can pass `wait_for_start=False` to the constructor.
43-
The `wait_for_start` method needs to be called before the metadata is available.
55+
### Startup behaviour
4456

45-
```python
57+
You can configure the startup behaviour of `sbot` with an `override.env` file in the same directory as your project.
4658

47-
from sbot import Robot
59+
Example `override.env` file:
4860

49-
r = Robot(wait_for_start=False)
61+
```sh
62+
ENABLE_DEBUG_LOGGING=1
63+
SKIP_WAIT_START=1
64+
NO_POWERBOARD=1
65+
```
5066

51-
# Setup in here
67+
If `SKIP_WAIT_START` is set, you will have to manually trigger board discovery and wait for the start button:
5268

53-
r.wait_start()
69+
```python
70+
from sbot import utils
5471

72+
utils.load_boards()
73+
utils.wait_start()
5574
```
5675

76+
The currently supported override keys are:
77+
78+
Override | Description
79+
--- | ---
80+
ENABLE_DEBUG_LOGGING | Enable debug logging
81+
ENABLE_TRACE_LOGGING | Enable trace level logging
82+
SKIP_WAIT_START | Don't block for the start signal automatically
83+
NO_POWERBOARD | Allow running without a power board
84+
MANUAL_POWER_PORTS | Specify additional serial ports for power boards
85+
MANUAL_MOTOR_PORTS | Specify additional serial ports for motor boards
86+
MANUAL_SERVO_PORTS | Specify additional serial ports for servo boards
87+
MANUAL_ARDUINO_PORTS | Specify additional serial ports for arduino boards
88+
MANUAL_LED_PORTS | Specify additional serial ports for led boards, only used in the simulator
89+
MANUAL_TIME_PORTS | Specify additional serial ports for the time interface, only used in the simulator
90+
SORT_POWER_ORDER | Override the sort order of the power boards, unused
91+
SORT_MOTOR_ORDER | Override the sort order of the motor boards
92+
SORT_SERVO_ORDER | Override the sort order of the servo boards
93+
SORT_ARDUINO_ORDER | Override the sort order of the arduino boards, unused
94+
SORT_LED_ORDER | Override the sort order of the led boards, unused
95+
SORT_TIME_ORDER | Override the sort order of the time interface, unused
96+
97+
You can also configure these settings as environment variables, by prepending the prefix `SBOT_`. For example, `ENABLE_DEBUG_LOGGING` can be set as `SBOT_ENABLE_DEBUG_LOGGING`.
98+
Some settings can only be configured as environment variables. These are:
99+
100+
Environment Variable | Description
101+
--- | ---
102+
OPENCV_CALIBRATIONS | Override the location to look for additional camera calibrations, defaults to the working directory
103+
SBOT_METADATA_PATH | Override the location to look for metadata files, normally configured by the runner
104+
SBOT_PYTEST | Set to `1` when running unit tests, to disable automatic discovery on import
105+
SBOT_MQTT_URL | The URI to use for the MQTT broker, normally configured by the runner
106+
run_uuid | The UUID to include in all MQTT messages, normally configured by the runner
107+
WEBOTS_SIMULATOR | Set to `1` when running in the Webots simulator, used to detect the simulator environment
108+
WEBOTS_ROBOT | List of socket URIs to connect to for the simulated boards, configured by the runner
109+
WEBOTS_DEVICE_LOGGING | Set to the log level name to use for logging of the simulated boards, defaults to `WARNING`
110+
57111
## Developer Notes
58112

59113
There are a number of considerations that have been made in the design of this API.
60114
Some of these may not be immediately obvious, so they are documented below.
61115

62-
- The API is designed to raise exceptions for incorrect actions, such as trying to modify the output dictionary or assign a value directly to the motor object.
63-
- `MappingProxyType` is used to prevent the user from adding, removing or overwriting keys in any parts of the API that return a dictionary.
64116
- `tuple` is used to prevent the user from adding, removing or overwriting items in any parts of the API that would return a list.
65117
- `__slots__` is used to prevent the user from adding, removing or overwriting attributes in any parts of the API.
66118
- `sbot.serial_wrapper.SerialWrapper` handles automatic reconnection to the serial port if the connection is lost and impleents 3 retries on any serial operation before raising a `BoardDisconnectionError`.
119+
- The old API is still available under `sbot.historic`, though this might change.

0 commit comments

Comments
 (0)