Welcome to AUDRI’s documentation!¶
audri module¶
Provides functionality for automated driving. AUDRI is able to receive feature vectors, learn from them, and then decide upon an action to perform when presented with another feature vector
config module¶
Configuration classes for all of the components
-
class
config.
GUIConfig
[source]¶ Bases:
object
Configuration used by the
gui
moduletuple
attributes store main text at index 0, and tooltip text at index 1-
CompareText
= 'Compete with AUDRI'¶ (
str
) Text for the button in theMainFrame
, linking to theSimulator
in compare mode
-
ConfAppearance
= 'Appearance'¶ (
str
) Header text for the appearance parameters section in theConfigFrame
-
ConfBackground
= ('Scroll background', 'Whether the background should scroll down the window, as if the car\nis travelling down it\nDisable if you experience dizziness')¶
-
ConfCarScale
= ('Car scale', 'Multiplied against the normal size of the car sprite')¶
-
ConfCarSpeed
= ('Car speed', '(metres per second)\nThe forward speed of the main car')¶
-
ConfExperiment
= 'Experiment parameters'¶ (
str
) Header text for the experimental parameters section in theConfigFrame
-
ConfFPS
= ('Frames per second', 'Frame rate - how many times per second the screen is redrawn\nHigher values will likely result in more CPU usage')¶
-
ConfInnerPadding
= 15¶ (
int
) Padding between labels and their connected control in theConfigFrame
-
ConfObstFreq
= ('Obstacle frequency', '(seconds)\nTime between obstacles spawning')¶
-
ConfObstScale
= ('Obstacle scale', 'Multiplied against the normal size of the obstacle sprites')¶
-
ConfObstSpeed
= ('Obstacle speed', '(metres per second)\nThe forward speed of the obstacle vehicles\nMust be smaller than car speed')¶
-
ConfOffroad
= ('Allow the car to drive offroad', 'If checked, the main car will be able to use the offroad areas to avoid vehicles')¶
-
ConfRandomSeed
= ('Random seed', 'The value used to control pseudo-random number generation')¶
-
ConfRecordFreq
= ('Snapshot interval', 'Gap in seconds between recordings of the state of the simulation')¶
-
ConfRowPadding
= 10¶
-
ConfSave
= ('Save', 'Save configuration and return to the main menu')¶
-
ConfText
= 'Configuration'¶ (
str
) Text for the button in theMainFrame
, linking to theConfigFrame
-
ConfTickrate
= ('Tickrate', 'Tick rate - how many times per second the game logic should run\nLower values will impact expermiental accuracy\nHigher values will likely result in more CPU usage')¶
-
ConfTitle
= 'Configuration'¶ (
str
) Header text in theConfigFrame
-
DataText
= 'Gather training data'¶ (
str
) Text for the button in theMainFrame
, linking to theSimulator
in training mode
-
FontBold
= {'family': 'sans-serif', 'size': 10, 'weight': 'bold'}¶ (
dict
) Data used to create a bold font
-
FontHeading
= {'family': 'sans-serif', 'size': 15, 'weight': 'bold'}¶ (
dict
) Data used to create a header font
-
MainButtonXPad
= 15¶
-
MainButtonYPad
= 15¶
-
ModeText
= ['manual', 'AUDRI', 'compare']¶ list
ofstr
mapping simulator modes to a description of that mode, used bySimulatorPanel
-
SimPopupDupWarn
= 'This name is already in use, overwrite?'¶ Duplicate warning message in (
NameDatasetPopup
)
-
SimPopupPad
= 10¶ Padding in (
NameDatasetPopup
)
-
SimPopupText
= 'Choose a name for this training set'¶ Message in (
NameDatasetPopup
)
-
SimPopupTitle
= 'Name the training set'¶ Window title of the popup for naming a training set (
NameDatasetPopup
)
-
TestText
= 'Test AUDRI'¶
-
TooltipWidth
= 250¶
-
VisualiserWidth
= 500¶ (
int
) Width of thevisualiser.visualiser.SimulatorVisualiser
-
-
class
config.
SimulatorConfig
[source]¶ Bases:
object
Configuration used by the
visualiser
class-
ObstacleSpeed
= 8¶
-
RandomSeed
= 'geqJQD6MfJ'¶ Random seed used to influence when vehicles spawn Can be
int
,str
, and others. Seerandom.seed()
for details
-
-
class
config.
Singleton
[source]¶ Bases:
type
Metaclass that provides singleton behaviour
Author: Adam Forsyth <adam@adamforsyth.net> Source: https://stackoverflow.com/a/6798042
data module¶
Provides functionality for manipulating training data sets and models
-
data.
DATA_DIR
= '/home/docs/checkouts/readthedocs.org/user_builds/audri/checkouts/latest/src/../data/training'¶ (
str
) Path to store data in
-
data.
MODEL_DIR
= '/home/docs/checkouts/readthedocs.org/user_builds/audri/checkouts/latest/src/../data/models'¶ (
str
) Path to store models in
-
data.
dataExists
(name)[source]¶ Parameters: name – ( str
) The name of the data set to search forReturns: bool
indicating if a data set named name exists
-
data.
loadData
(name)[source]¶ Parameters: name – ( str
) The name of the data set to loadReturns: dict
containing the training dataReturns: dict
containing the experimental settings used
-
data.
modelExists
(name)[source]¶ Parameters: name – ( str
) The name of the model to search forReturns: bool
indicating if a model named name exists
gui package¶
Submodules¶
gui.conf module¶
Provides ConfigFrame, the Tkinter frame that allows modifying the visualiser configuration
-
class
gui.conf.
ConfigFrame
(root, main)[source]¶ Bases:
tkinter.Frame
Frame allowing the configuration of the visualiser
Contains a number of Tkinter controls allowing the modification of attributes in
SimulatorConfig
-
_labelControl
(text, control, ctrlOpts={})[source]¶ Create a label and a widget, which are placed adjacent on the same row.
Parameters: Returns: The created
Widget
control
-
_load
()[source]¶ Load values into the controls from the
SimulatorConfig
-
_matches
= {'CarScale': 'carScale', 'CarSpeed': 'carSpeed', 'ObstacleInterval': 'obstFreq', 'ObstacleSpeed': 'obstSpeed'}¶ SimulatorConfig
attributes as keys, associated private attributes (with a set() method) as attributes. These config values are allfloat
-
_save
()[source]¶ Save values into the
SimulatorConfig
from the controls
-
gui.controls module¶
Provides custom Tkinter controls
-
class
gui.controls.
LabeledScale
(root, font, resolution=2, **kwargs)[source]¶ Bases:
tkinter.Frame
tkinter.ttk.Scale
and atkinter.Spinbox
joined in a frameThe
Scale
in shown to the left of theSpinbox
Parameters: - root – Parent
tkinter.Widget
- font –
Font
to use in theSpinbox
- resolution – (
int
) Number of decimal places to round stored and displayed value to
-
_update
(val=None)[source]¶ Callback method for both the
Spinbox
andScale
so that each can update the other, and the value can be properly formatted
- root – Parent
gui.main module¶
The main window and main page which links to the others
-
class
gui.main.
MainFrame
(root, main)[source]¶ Bases:
tkinter.Frame
Main ‘page’ of the application, linking to the
Simulator
andConfigFrame
usingButton
widgets. These cause theMainWindow
to focus on the desired frameParameters: - root –
Widget
parent - main –
MainWindow
- root –
-
class
gui.main.
MainWindow
(*args, **kwargs)[source]¶ Bases:
tkinter.Tk
The main Tkinter window of the application
Encapsulates
Simulator
andConfigFrame
-
_keyPress
(event)[source]¶ Tkinter key press callback method, sends events to the
Simulator
if it is currently focused
-
gui.panel module¶
Provides the side panel shown alongside the visulaiser
-
class
gui.panel.
SimulatorPanel
(parent, sim, visualiser, **kwargs)[source]¶ Bases:
tkinter.Frame
Side panel of the window, extends tk.Frame. Shows information about the visulisation.
Parameters: - parent – Parent
tkinter.Widget
- sim –
Simulator
instance to control - visualiser –
SimulatorVisualiser
instance to take information from - kwargs – keyword arguments to pass to superclass constructor
-
_call
(func)[source]¶ Return a function that focuses the panel then calls func
Used for button commands
-
tick
()[source]¶ Update displayed information using the
SimulatorVisualiser
- parent – Parent
gui.sim module¶
Provides the main simulator, which includes the Pygame visualiser and a Tkinter panel
-
class
gui.sim.
NameDatasetPopup
(main)[source]¶ Bases:
tkinter.Toplevel
A Tkinter popup that requests a name for a training set.
It will check if the name is in use; if it is, another prompt asks whether it should be overriden or another name should be input.
-
class
gui.sim.
Simulator
(root, main)[source]¶ Bases:
tkinter.Frame
The GUI component of the visualiser Contains the
SimulatorVisualiser
(Pygame canvas) in atkinter.ttk.Frame
. TheSimulatorPanel
is displayed alongside it.-
focus
()[source]¶ If loaded in manual mode, create a
NameDatasetPopup
to choose the training data name.If in AUDRI mode, train the model
-
mode
¶ - The current mode in which the simulator should run in.0 = Manual: Collect training data1 = AUDRI: Train AUDRI and let it control the car2 = Compare: Allow both expert and AUDRI to control two different cars, side by side
Getter: Get the current mode Setter: Set the current mode, also setting the mode of the SimulatorVisualiser
. Prevents setting an invalid modeType: int
-
setDataset
(name)[source]¶ Set the
_datasetName
property from theNameDatasetPopup
, unpause theSimulatorVisualiser
, and return focus to the main windowParameters: name – str
name of dataset to store training data in
-
visualiser package¶
Provides the visualiser modules
-
class
visualiser.
SimulatorVisualiser
(windowID)[source]¶ Bases:
object
The visualiser of the simulator, showing a graphical representation of the highway.
Parameters: windowID – str
set as the SDL_WINDOWID environment variable. Used to embed the pygame window into the GUI.-
_cachedSprites
= None¶ (
boolean
) Whether all sprites have been cached
-
draw
()[source]¶ Updates the canvas Attempts to achieve target FPS by blocking As such, it should run in its own thread so other things can be done in the background Should run in and endless loop to continuously redraw
-
fps
¶ The current target frames per second
Getter: Get the current FPS Setter: Set the current FPS. Calculates the necessary target draw interval Type: int
-
mode
¶ The mode of the visualiser. See
mode
for details.Getter: Return the current set mode Setter: Set the current mode. Also sets the correct dimensions of the display, doubling the width if in compare mode Type: int
-
stateVector
(agent=False)[source]¶ Return a dictionary of features: {last action, current lane, distance of obstales in three lanes, offroad} Some features have been ‘pruned’ from our descision tree because they did not affect the accuracy of the tree. These have been commented out for clarity.
-
Submodules¶
visualiser.util module¶
Utility functions and classes
-
class
visualiser.util.
Actions
[source]¶ Bases:
enum.Enum
Enumerations of the actions that the simulator can receive
-
LEFT
= 2¶ Move into the lane to the left
-
NONE
= 1¶ No action
-
PAUSE
= 4¶ Toggle the pause state of the simulator
-
RIGHT
= 3¶ Move into the lane to the right
-
-
class
visualiser.util.
Pos
(vehicle, x=0, y=0)[source]¶ Bases:
visualiser.util.Vector
2D vector that automatically updates its vehicle’s rect position
-
class
visualiser.util.
Vector
(x=0, y=0)[source]¶ Bases:
object
A 2D vector, with arithmetic magic methods implemented
-
x
= None¶ The x component of the vector
-
y
= None¶ The y component of the vector
-
-
visualiser.util.
loadSprite
(path, scale=1)[source]¶ Load an image as a
pygame.Surface
. Automatically caches loaded images in the backgroundParameters:
visualiser.vehicles module¶
Vehicle classes used by the game
-
class
visualiser.vehicles.
Car
(game)[source]¶ Bases:
visualiser.vehicles.Vehicle
The controlled car
Parameters: game – The parent SimulatorVisualiser
-
class
visualiser.vehicles.
Obstacle
(game)[source]¶ Bases:
visualiser.vehicles.Vehicle
An obstacle vehicle that the main car has to avoid
Parameters: game – The parent SimulatorVisualiser
-
hasCollidedAgent
¶ Getter: Returns whether the vehicle has started colliding with agent car this tick. Updates _agentCollided
-
speed
¶ The virtual forward speed of the vehicle, in metres per second
Getter: Get the vehicle speed Setter: Set the vehicle speed in m/s. Also sets the real velocity, which is relative to the user car
-
-
visualiser.vehicles.
SPRITE_SCALES
= {'car.png': 0.4, 'lorry.png': 0.75, 'police.png': 0.42, 'taxi.png': 0.35, 'truck.png': 0.5, 'van.png': 0.55, 'viper.png': 0.37}¶ dict
mapping obstacle sprites onto their respectivefloat
scales
-
class
visualiser.vehicles.
Vehicle
(game)[source]¶ Bases:
object
A vehicle in the game
Parameters: game – The parent SimulatorVisualiser
-
lane
¶ The current lane of the vehicle
Getter: Get the current lane Setter: Set the lane of the vehicle. The vehicle is centered in its lane. Will only accept lanes available Type: int
-
speed
¶ The virtual forward speed of the vehicle, in metres per second
Getter: Get the vehicle speed Setter: Set the vehicle speed in m/s
-
sprite
¶ The sprite object. Uses
_sprite
as the file name of the image to loadGetter: Return the sprite Type: pygame.Surface
-
visualiser.visualiser module¶
The visualiser of the simulator - the game the user plays Uses the PyGame library
-
class
visualiser.visualiser.
SimulatorVisualiser
(windowID)[source]¶ Bases:
object
The visualiser of the simulator, showing a graphical representation of the highway.
Parameters: windowID – str
set as the SDL_WINDOWID environment variable. Used to embed the pygame window into the GUI.-
_cachedSprites
= None¶ (
boolean
) Whether all sprites have been cached
-
draw
()[source]¶ Updates the canvas Attempts to achieve target FPS by blocking As such, it should run in its own thread so other things can be done in the background Should run in and endless loop to continuously redraw
-
fps
¶ The current target frames per second
Getter: Get the current FPS Setter: Set the current FPS. Calculates the necessary target draw interval Type: int
-
mode
¶ The mode of the visualiser. See
mode
for details.Getter: Return the current set mode Setter: Set the current mode. Also sets the correct dimensions of the display, doubling the width if in compare mode Type: int
-
stateVector
(agent=False)[source]¶ Return a dictionary of features: {last action, current lane, distance of obstales in three lanes, offroad} Some features have been ‘pruned’ from our descision tree because they did not affect the accuracy of the tree. These have been commented out for clarity.
-