Skip to content

Commit a61fbb7

Browse files
authored
An Easier Way to Insert Custom ESC Plugins (#492)
* Moved ESC plugin registration into the devices module. (#489) * Provided a more user-friendly interface. (#489) * Bug fixed: plugins not instantiated. (#489) * Docs. (#489)
1 parent 6b2a235 commit a61fbb7

5 files changed

Lines changed: 32 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
LEADS is a lightweight embedded assisted driving system. It is designed to simplify the development of instrumentation,
1212
control, and analysis systems for racing cars. It is written in well-organized Python and C/C++ and has impressive
13-
performance.It is not only out-of-the-box but also fully customizable. It provides multiple abstract layers that allow
13+
performance. It is not only out-of-the-box but also fully customizable. It provides multiple abstract layers that allow
1414
users to pull out the components and rearrange them into a new project. You can either configure the existing executable
1515
modules ([LEADS VeC](https://leads-docs.projectneura.org/en/latest/vec)) simply through a JSON file or write your own
1616
codes based on the framework as easily as building a LEGO.
@@ -83,7 +83,7 @@ The LEADS framework ensures that its applications, including LEADS VeC, have ext
8383
provide promising safety, but still, always keep our
8484
[Safety Instructions](https://leads-docs.projectneura.org/en/latest/vec/safety-instructions.html) in mind.
8585

86-
Most of the codes are written in Python and the dependencies are carefully chosen so that LEADS runs everywhere Python
86+
Most of the codes are written in Python, and the dependencies are carefully chosen so that LEADS runs everywhere Python
8787
runs. In addition, on platforms like Arduino where we must use other programming languages, we try hard to keep
8888
consistency.
8989

@@ -131,7 +131,7 @@ configuration.
131131
<details>
132132
<summary>DTCS (Dynamic Traction Control System)</summary>
133133

134-
DTCS helps you control the amount of rear wheel slip by detecting and comparing the speed difference between all wheels.
134+
DTCS helps you control the amount of rear-wheel slip by detecting and comparing the speed difference between all wheels.
135135
It allows a certain amount of drift while ensuring grip.
136136

137137
</details>
@@ -167,7 +167,7 @@ provide a manual mode where all assistance is forcibly disabled. You can simply
167167

168168
</details>
169169

170-
Plugins can be easily customized and installed in LEADS. It also comes with several existing ones including 4 ESC
170+
Plugins can be easily customized and installed in LEADS. It also comes with several existing ones, including 4 ESC
171171
plugins that realize 4 ESC systems. All 4 systems have 4 calibrations: standard, aggressive, sport, and off. Their
172172
intervention comes later than the previous respectively.
173173

@@ -230,7 +230,7 @@ data was recorded.
230230
<summary>AI-enhanced data analysis and driver training</summary>
231231

232232
Powered by rich datasets, our ambition is to change car racing as a whole, just as AlphaGo changed Go. This blueprint
233-
has never been such easy as today thanks to AI.
233+
has never been so easy as today thanks to AI.
234234

235235
![lap-analysis](docs/assets/lap-analysis.png)
236236

@@ -674,6 +674,9 @@ jobs:
674674
```python
675675
from leads import controller, MAIN_CONTROLLER
676676
from leads_emulation import RandomController
677+
from leads_vec.utils import register_plugins
678+
679+
register_plugins() # required
677680

678681

679682
@controller(MAIN_CONTROLLER)

leads_vec/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
from leads_vec.run import *
77
from leads_vec.__entry__ import __entry__
88
from leads_vec.config import *
9+
from leads_vec.utils import *

leads_vec/cli.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pynput.keyboard import Listener as _Listener, Key as _Key, KeyCode as _KeyCode
1010
from screeninfo import get_monitors as _get_monitors
1111

12-
from leads import LEADS, SystemLiteral, require_config, register_context, DTCS, ABS, EBI, ATBS, ESCMode, L, \
12+
from leads import LEADS, SystemLiteral, require_config, register_context, ESCMode, L, \
1313
EventListener, DataPushedEvent, UpdateEvent, has_device, GPS_RECEIVER, get_device, InterventionEvent, \
1414
SuspensionEvent, Event, LEFT_INDICATOR, RIGHT_INDICATOR, format_duration, BRAKE_INDICATOR, REAR_VIEW_CAMERA, \
1515
FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, RIGHT_VIEW_CAMERA, SuspensionExitEvent
@@ -157,10 +157,6 @@ def main() -> int:
157157
cfg = require_config()
158158
ctx = LEADS(data_seq_size=cfg.data_seq_size, num_laps_timed=cfg.num_laps_timed)
159159
register_context(ctx)
160-
ctx.plugin(SystemLiteral.DTCS, DTCS())
161-
ctx.plugin(SystemLiteral.ABS, ABS())
162-
ctx.plugin(SystemLiteral.EBI, EBI())
163-
ctx.plugin(SystemLiteral.ATBS, ATBS())
164160
w = Pot(cfg.width, cfg.height, cfg.refresh_rate, CustomRuntimeData(), fullscreen=cfg.fullscreen,
165161
no_title_bar=cfg.no_title_bar, theme_mode=cfg.theme_mode)
166162
root = w.root()

leads_vec/devices.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from leads_gpio import NMEAGPSReceiver, LEDGroup, LED, LEDGroupCommand, LEDCommand, Entire, Transition, Button, \
1212
ButtonCallback, CPUMonitor
1313
from leads_vec.config import Config
14+
from leads_vec.utils import register_plugins
1415
from leads_video import Base64Camera, get_camera
1516

1617
config: Config = require_config()
@@ -28,6 +29,8 @@
2829
BRAKE_PEDAL_PIN: int = config.get("brake_pedal_pin", 3)
2930
VOLTAGE_SENSOR_PIN: int = config.get("voltage_sensor_pin", 4)
3031

32+
register_plugins()
33+
3134

3235
@controller(MAIN_CONTROLLER)
3336
class VeCController(Controller):

leads_vec/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from leads import LEADS as _LEADS, Plugin as _Plugin, SystemLiteral as _SystemLiteral, DTCS as _DTCS, ABS as _ABS, \
2+
EBI as _EBI, ATBS as _ATBS, set_on_register_context as _set_on_register_context
3+
from leads.types import OnRegister as _OnRegister
4+
5+
6+
def register_plugins(plugins: dict[str, _Plugin] | None = None) -> None:
7+
if not plugins:
8+
plugins = {_SystemLiteral.DTCS: _DTCS(), _SystemLiteral.ABS: _ABS(), _SystemLiteral.EBI: _EBI(),
9+
_SystemLiteral.ATBS: _ATBS()}
10+
11+
def _on_register_context(chain: _OnRegister[_LEADS]) -> _OnRegister[_LEADS]:
12+
def _(ctx: _LEADS) -> None:
13+
chain(ctx)
14+
for k, p in plugins.items():
15+
ctx.plugin(k, p)
16+
17+
return _
18+
19+
_set_on_register_context(_on_register_context)

0 commit comments

Comments
 (0)