pathfinder package
The pathfinder package contains all the modules required to run the heads up display.
Submodules
Necessary submodules are listed below. Note: not all modules as seen in the github are here, as some were used for testing and are not used.
pathfinder.HUD module
HUD Module
Main module for running PathFinder software.
This module calls from display, directions, and OBD to put together functionality for the PathFinder project. Furthermore, it acts as a MQTT client subscribed to the broker listening to channels ‘source’ and ‘destination’
- inputA:
String representation of source point for PathFinder.
- inputB:
String representation of destination point for PathFinder.
- client:
Instance of mqtt.Client() object for subscribing to the MQTT broker.
Typical usage example:
python3 pathfinder/HUD.py
- class pathfinder.HUD.Hud(display)
Bases:
threading.Thread
- on_connect(client, userdata, flags, rc)
The callback for when the client recieves a CONNACK response from the server.
- Parameters
client (client) – The client instance for this callback.
userdata (userdata) – The private user data set in Client() or user_data_set().
flags (flags) – Response flags sent by the broker.
rc (rc) – The connection result.
- on_dest(client, userdata, msg)
Defines what should happen upon receiving a message published on the ‘destination’ channel. Formats message payload anad saves to local variable inputB.
- Parameters
client (client) – MQTT client class instance.
userdata (userdata) – A user provided object passed to the on_message callback when a message is received.
msg (msg) – Message class from the broker.
- on_message(userdata, msg)
Callback function that happens when subscriber client receives message from broker.
- Parameters
client (client) – Instance of client class.
userdata (userdata) – User provided object passed onto on_message callback when a message is received.
msg (msg) – Message class from the broker.
- on_source(client, userdata, msg)
Defines what should happen upon receiving a message published on the ‘source’ channel. Formats message payload and saves to local variable inputA.
- Parameters
client (client) – MQTT client class instance.
userdata (userdata) – A user provided object passed to the on_message callback.
msg (msg) – Message class from the broker.
- pull_directions()
Method instantiates a DirectionController and Display instance. Calls getDirections() and getInstructions from DirectionController then formats them for Display.
- run()
Main function of PathFinder project. Sets up connection to MQTT broker and calls functions defined below.
pathfinder.OBD module
OBD Module
Functions as connectivity between the HUD and OBDII bluetooth transmitter. Establishes a connection to the bluetooth adapter and gathers measurements such as speed and fuel percentage. When it first forms a connection the code has to loop multiple times to pull all instructions.
- class pathfinder.OBD.Obd(display)
Bases:
threading.Thread
- get_dtc()
- get_fuel_percentage()
Queries fuel % of car is connected :returns: fuel percentage :rtype: string
- get_speed()
Queries speed of car is connected :returns: speed in mph :rtype: string
- is_healthy_message(dtc)
- run()
While loop that relies on previous functions to show the user what is occuring.
pathfinder.GPS module
GPS module
The GPS module handles the reading of data from our NEO-6M chip via gpsd. It contains two helper functions: one to get coordinates for the current location, and one to calculate the distance between two coordinate points.
- class pathfinder.GPS.GPS_controller
Bases:
object
- calculate_distance(cords1, cords2)
Returns a distance in miles given two coordinate points.
- Parameters
cords1 (float, float) – Tuple of point A.
cords2 (float, float) – Tuple of point B.
- Returns
Distance between point A and point B.
- Return type
float
- get_coordinates()
Returns latitude and longitude of current location.
- Returns
Tuple of floating point coordinates.
- Return type
(float, float)
pathfinder.directions module
Directions Module
This is a module handles all the direction requests and data acquisition for driving instructions. Uses the Google Places API to gather instruction data.
- Typical usage example
dirC = new DirectionController(“pointA”, “pointB”)
- class pathfinder.directions.DirectionController(pointA, pointB)
Bases:
object
Base class for the Direction Controller.
Defines the methods to fetch and store directions using Google Places API.
- user_origin
Starting origin point defined by user.
- user_destination
Final desitnation point defined by user.
- instruction_queue
List of instructions obtained from API given source and destination.
Notes
It is critically important that you call getDirections() method first before getInstructions() when using this class. The getDirections() method fills the instruction_queue which can then be returned by getInstructions(). Otherwise you will be returning an empty list.
- coordinate_queue = []
- getCoordinates()
Returns list of maneuvers parsed from JSON response after calling .getDirections().
- Returns
list of all maneuvers
- Return type
list
- getDirections()
Makes an HTTP request to the Google API endpoint and parses through the JSON response to obtain a list of instructions.
- Returns
Text output of json response.
- Return type
string
- getInstructions()
Returns directions.instruction_queue (should be called after .getDirections()).
- Returns
list of all instructions
- Return type
list
- instruction_queue = []
pathfinder.display module
Display Module
This is a module to control the OLED display for the PathFinder via I2C protocol.
- Typical usage example:
screen = display.Display()
- class pathfinder.display.Display
Bases:
object
Base class for display. Defines the basic properties of the display plus methods used to update an OLED display using I2C interface with text output.
- i2c
Defines bus supported I2C protocol.
- disp
Object represented from adafruit OLED display drivers
- clear_bot()
Clears only the bottom line of the display.
- clear_disp()
Clears the display image
- clear_mid()
Clears only the third line of the display.
- refresh()
Refreshes the display to show a new image. Specifically places image in display and calls disp.show() to present the image.
- show_arrow(current_inst, distance)
Prints directional indicator to third line on the display, along with the distance before next instruction.
- Parameters
current_inst (Any) – Current instruction to determine indicator.
distance (Any) – Distance in miles to next point.
- show_direction(text)
Takes instruction input and splits into 3 lines for display
- Parameters
text (string) – String containing instruction.
- show_obd(speed, fuel, health)
Shows status of the OBD on the bottom line of the display. Displays fuel, speed, and health.
- Parameters
speed (Any) – Speed from OBD module.
fuel (Any) – Fuel from OBD module.
health (Any) – Health from OBD module.
- show_text(text='not available')
Shows line of text. * NOTE: this function was used in testing and is not used elsewhere *
- Parameters
text (string) – text to put on display, defaults to ‘not available’