You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
13
12
14
13
## Installation
15
14
@@ -27,40 +26,94 @@ pip install sbot[vision]
27
26
28
27
## Usage
29
28
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.
33
30
34
31
```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)
35
42
36
-
from sbot import Robot
43
+
power.get_output_current(PowerOutputPosition.H0)
44
+
utils.sound_buzzer(880, 0.5)
37
45
38
-
r = Robot()
46
+
servos.set_position(0, 45/90)
39
47
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)
40
53
```
41
54
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
44
56
45
-
```python
57
+
You can configure the startup behaviour of `sbot` with an `override.env` file in the same directory as your project.
46
58
47
-
from sbot import Robot
59
+
Example `override.env` file:
48
60
49
-
r = Robot(wait_for_start=False)
61
+
```sh
62
+
ENABLE_DEBUG_LOGGING=1
63
+
SKIP_WAIT_START=1
64
+
NO_POWERBOARD=1
65
+
```
50
66
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:
52
68
53
-
r.wait_start()
69
+
```python
70
+
from sbot import utils
54
71
72
+
utils.load_boards()
73
+
utils.wait_start()
55
74
```
56
75
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
+
57
111
## Developer Notes
58
112
59
113
There are a number of considerations that have been made in the design of this API.
60
114
Some of these may not be immediately obvious, so they are documented below.
61
115
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.
64
116
-`tuple` is used to prevent the user from adding, removing or overwriting items in any parts of the API that would return a list.
65
117
-`__slots__` is used to prevent the user from adding, removing or overwriting attributes in any parts of the API.
66
118
-`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