This example demonstrates how to establish a connection with a Voyant LiDAR sensor and capture incoming frames.
What You’ll Learn
- How to create a VoyantClient instance
- How to handle multicast connections
- How to receive and process frame data
- Basic signal handling for graceful application termination
Prerequisites
- Voyant API installed (see Installation)
- A Voyant LiDAR sensor (or sensor simulator running in loopback mode)
Example Code
View the complete example on GitHub: voyant_client_basic.cpp
Key Concepts
This example demonstrates the basic usage of the VoyantClient class.
Signal Handling
The VoyantClient::setupSignalHandling()
method configures the application to gracefully handle interruption signals (like Ctrl+C), allowing for proper cleanup when the program terminates.
Client Configuration
The VoyantClient
constructor takes three parameters:
- Local binding address and port
- Multicast group address
- Interface address
The example provides both loopback configuration for testing and real-world sensor configuration. Refer to our Connections Guide for more information.
Frame Capture Loop
The main loop:
- Checks if the application has been terminated (via signals)
- Attempts to receive the next frame from the sensor
- Processes the frame data if available
- Sleeps briefly to avoid consuming excessive CPU resources
In this example we return a mutable reference to the latest received frame.
// Access latest frame as a mutable reference
VoyantFrameWrapper &frame = client.latestFrame();
You can also receive an immutable reference by decorating with the const
keyword.
// Access latest frame as an immutable reference
const VoyantFrameWrapper &frame = client.latestFrame();
Or you can make a copy of the latest frame by removing the &
, but be warned this will allocate a large chunk of memory every time.
// Make a copy of the latest frame
VoyantFrameWrapper frame = client.latestFrame();
Building and Running
You can build and run this example using CMake:
- From
/workspace/
if building in provided docker container. - From
voyant-sdk/
if building on your native system.
# Build the examples
mkdir build && cd build
cmake ..
make
# Run the basic client example
./bin/voyant_client_basic
Expected Output
When running in loopback mode with a sensor simulator, you should see output similar to:
If properly configured, your basic client will display a stream of received full LiDAR frames:
###############
Received frame:
Header{message type:2, device id:MDL-000, frame idx:35, stamp:1691391379.087802875, proto version:0.1.0, api version:0.1.0, fw version:0.1.0, hdl version:0.0.34}
Config{ len: 0 }
Points[24384] {{idx:6238209,ts:163840,pos:[43.984,0.193966,11.0427],v:1.22985,snr:12.3234,refl:0,noise:34.0003,min_snr:-0.00802298,drop reason:1},...}
Next Steps
After understanding this basic example, you might want to explore:
- How to process the point cloud data within frames
See our other examples or refer to the API Documentation for more advanced usage.