Memory class is a key-value store used by the Vehicle to pass data between parts. It acts as a shared message bus where parts can publish outputs and subscribe to inputs.
Overview
Memory enables loose coupling between parts. Parts don’t need to know about each other - they just read and write named values to memory. The Vehicle orchestrates the data flow.Constructor
__init__(*args, **kw)
Creates a new Memory instance. No parameters required.
d- Internal dictionary storing all key-value pairs
Methods
get(keys)
Retrieves values from memory by key names.
list
required
List of string keys to retrieve from memory
list
List of values corresponding to the keys. Returns None for keys that don’t exist.
put(keys, inputs)
Stores values in memory. Handles both single and multiple key-value pairs.
list
required
List of string keys where values will be stored
any
required
Value(s) to store. If keys has multiple items, inputs should be a tuple or list of values.
update(new_d)
Updates memory with values from a dictionary.
dict
required
Dictionary of key-value pairs to add or update in memory
Dictionary-Style Access
Memory supports dictionary-style access using[] operators:
__getitem__(key)
Retrieve values using bracket notation.
str | tuple
required
Single key (string) or multiple keys (tuple)
__setitem__(key, value)
Store values using bracket notation.
str | tuple | list
required
Single key (string) or multiple keys (tuple/list)
any
required
Value(s) to store
Dictionary Methods
Memory provides standard dictionary methods for introspection:keys()
Returns all keys in memory.
values()
Returns all values in memory.
items()
Returns all key-value pairs.
Common Memory Keys
By convention, memory keys use the formatcomponent/property:
Camera
cam/image_array- Camera image as numpy arraycam/depth_array- Depth image (for stereo/depth cameras)
User Control
user/angle- Steering angle from user (-1 to 1)user/throttle- Throttle from user (-1 to 1)user/mode- Drive mode: ‘user’, ‘local_angle’, or ‘local’
Autopilot
pilot/angle- Steering angle from AI modelpilot/throttle- Throttle from AI modelrun_pilot- Boolean, whether autopilot should run
Drive Train
angleorsteering- Final steering value sent to servothrottle- Final throttle value sent to ESC/motor
Recording
recording- Boolean, whether data is being savedtub/num_records- Number of records saved
Sensors
enc/speed- Speed from encoder (odometry)imu/acl_x,imu/acl_y,imu/acl_z- Accelerometer dataimu/gyr_x,imu/gyr_y,imu/gyr_z- Gyroscope datalidar/dist_array- LIDAR distance array
Data Flow Example
Here’s how data flows through memory in a typical vehicle:Best Practices
Naming Conventions
Use descriptive names with component prefixes:Handling None Values
Always check for None when reading from memory:Memory Inspection
Debug memory contents during development:See Also
- Vehicle - Main vehicle class that uses Memory
- Creating Parts - How parts interact with memory
- Data Store - Persistent storage for training data
