Skip to content

Valve's Lighthouse v2 positioning system decoder implemented for the RP2040

License

Notifications You must be signed in to change notification settings

DotBots/lh2_on_rp2040

Repository files navigation

LH2 Decoder on RP2040

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.

RP2040 with 4 TS4231 receiving pulses from 2 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.

Logic analyser data

The decoded data is printed to a serial port trough the USB.

Serial log with LH2 data

How does it work

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

diagram of how the system works

Results and Benchmark

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.

diagram of how the system works

All the decoded information gets printed to the serial console in the following format.

diagram of how the system works

Getting Started

Circuit Pinout

TODO

Build & Flash the code

  1. 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 ..
  1. Set the enviroment variable To let the system know where is the SDK
export PICO_SDK_PATH=$PWD/pico-sdk
  1. 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"
  1. Build project
make
  1. Flash the lh2_receiver.uf2 file to the microcontroller/

References

  • 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.

About

Valve's Lighthouse v2 positioning system decoder implemented for the RP2040

Resources

License

Stars

Watchers

Forks

Packages

No packages published