Developer How-To's for PILOT Drive
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.py
main file
- ie. if the service is named "bluetooth" located at backend/pilot-drive/services/bluetooth/, it has a
- The service name needs to be added to the
EventType
Enum inbackend/pilot-drive/master_event_queue.py
- In the main file, the service inherents the
AbstractService
class, located atbackend/pilot-drive/services/abstract_service.py
. - With the
AbstractService
as a parent class, the service is required to accept and implement the follow parameters: master_event_queue
- aMasterEventQueue
instance to push new events toservice_type
- theEventType
enum value created in step #3, used to identify the service when it pushes to Queuelogger
- aMasterLogger
instance to handle logging events
- With the
- The service needs to contain a
main
method, 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
refresh
method, 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
PilotDrive
located atbackend/pilot-drive/pd_manager.py
manager initializes the service - This should happen in the
__init__
method, using theservice_factory
method. - (Optional) Add a callback for commands sent from the UI by adding a method to
PilotManager.service_msg_handlers
- This should happen in the
- 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!
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.