Valve's Lighthouse v2 positioning system decoder implemented for the RP2040. 100% CPU implementation.
4 TS4231
are connected to a RP2040
. The MCU receives and decodes data from two LH2 basestations.
A logic analyser is connected to the system. It shows the arriving data, and how much time it takes the CPU to decode the data.
The decoded data is printed to a serial port trough the USB.
The code uses the PIO
system to sample the data from the TS4231
. Four PIO state machines samples each TS4231
data line for 16us at a constant rate of 32 MS/s
.
The capture data is automatically moved to a buffer in RAM using the DMA system. After each successful capture, the PIO state machine triggers an interrupt.
This signals the CPU to retrieve the data from the buffers and decode it. Each core of the RP2040
monitors and processes two TS4231
sensors
Below is a capture from two sweeps of a basestation.
- Top 4 lines: Envelope pin of the
TS4231
. It signals the presence of data - Bottom 4 lines: Benchmark of each function in the decoding function
All 8 pulses from a full sweep of the basestation, can be decoded in less than
3ms
. Full bench mark available here.
All the decoded information gets printed to the serial console in the following format.
TODO
- Clone the repository and initialize the SDK submodule
git clone https://github.com/DotBots/lh2_on_rp2040.git
cd lh2_on_rp2040
git submodule update --init
cd pico-sdk
git submodule update --init
cd ..
- Set the enviroment variable To let the system know where is the SDK
export PICO_SDK_PATH=$PWD/pico-sdk
- Create a build directory and run CMAKE
mkdir build && cd build
# For the Pico 2 board
cmake .. -D"PICO_BOARD=pico2"
# For the Pico 2W board
cmake .. -D"PICO_BOARD=pico2_w"
# For the Pico 1 board
cmake .. -D"PICO_BOARD=pico"
# For the Pico 1W board
cmake .. -D"PICO_BOARD=pico_w"
- Build project
make
- Flash the
lh2_receiver.uf2
file to the microcontroller/
- How to change the CPU system clock, with
set_sys_clock_khz(128000, true)
Link- this function is available from stdlib.h
- The script
pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
confirms that 128MHz is an achievable frequency.