as a developer…
Developer How-To’s for PILOT Drive
create a new service
Making a new service has some basic prerequisites to allow for modularity:
It has it’s own module within the
backend/pilot-drive/services/directory (requiring an__init__.py).- Within the module, it has a “main” file, with the same name as the module directory.
ie. if the service is named “bluetooth” located at backend/pilot-drive/services/bluetooth/, it has a
bluetooth.pymain file
The service name needs to be added to the
EventTypeEnum inbackend/pilot-drive/master_event_queue.pyIn the main file, the service inherents the
AbstractServiceclass, located atbackend/pilot-drive/services/abstract_service.py.- With the
AbstractServiceas a parent class, the service is required to accept and implement the follow parameters: master_event_queue- aMasterEventQueueinstance to push new events toservice_type- theEventTypeenum value created in step #3, used to identify the service when it pushes to Queuelogger- aMasterLoggerinstance to handle logging events
- With the
- The service needs to contain a
mainmethod, that will run as a process upon PILOT Drive’s start. The service can either utilize a loop to run until SIGINT, or it can terminate after some work on startup.
- The service needs to contain a
- Each service also needs a
refreshmethod, which runs on the UI’s initial connection, along with refreshes. This might not last long, and most services do not have any logic contained in the refresh. Doesn’t work well with multiprocessing.
- Each service also needs a
- The
PilotDrivelocated atbackend/pilot-drive/pd_manager.pymanager initializes the service This should happen in the
__init__method, using theservice_factorymethod.(Optional) Add a callback for commands sent from the UI by adding a method to
PilotManager.service_msg_handlers
- The
- Get Creative!
This is where the fun happens! Build your services’ logic, and make sure it can be leveraged by the frontend.
NOTE: Do not use the Python logging module in services, only the provided PILOT Drive Logger!
run an OBD/ELM327 emmulator
It’s pretty inconvenient as a developer to walk out to your car every time you want to test a feature. Thankfully, ELM327-emulator makes this easy!
Confirm ELM327-emulator is installed:
python3.11 -m pip install ELM327-emulator
Run the ELM327 emulator:
python3 -m elm
Note the port provided and configure PILOT Drive with specified port
Restart PILOT Drive
You should now see emulated vehicle data under the vehicle tab.