Using the API

In this example we show various ways to work with the sensor configuration interface.

Imports

First let’s add the necessary imports to work with the sensor configuration API.

# Other imports
from ouster.sdk import core
from ouster.sdk import sensor
#include "ouster/core/types.h"
#include "ouster/sensor/client.h"
using namespace ouster::sdk;

Get Configuration

Let’s look at the first step, where we get the configuration of the sensor as it starts:

config: core.SensorConfig = sensor.get_config(sensor_hostname)
print(f"Sensor config of {sensor_hostname}:\n" +
      f"{str(config)}")
core::SensorConfig config = sensor::get_config(sensor_hostname);
std::cerr << "Sensor config of " << sensor_hostname << ":\n"
          << core::to_string(config) << std::endl;

get_config takes the sensor hostname and returns a SensorConfig directly; it throws if it can’t connect to the sensor or retrieve the config.

In the full C++ example (click the “View on GitHub” on the top-right corner of the code snippet above), this is the first of five numbered steps; if there are no errors, running it end-to-end prints a status line for each step. The full Python example follows the same get-config, modify, set-config, re-fetch flow without the numbered output.

The sensor configuration can be updated using the API which will be covered in the next sections.

The configuration parameters provided are in direct correspondence with the settings available for the sensor. A complete list of the sensor settings can be found in the sensor configuration overview .

Some of the most commonly modified parameters are described below.

Configure Dual Returns

Once you’ve configured your sensor, you shouldn’t have to configure it again until it shuts down or restarts. You can explore the persist flag to persist port and udp_dest settings over sensor restarts.

If you have a Rev6 or later sensor and are running FW 2.2+, you should be able to configure your sensor to use dual returns by setting the config parameter UDPProfileLidar.

config.udp_profile_lidar = core.UDPProfileLidar.RNG19_RFL8_SIG16_NIR16_DUAL
config.udp_profile_lidar = core::UDPProfileLidar::RNG19_RFL8_SIG16_NIR16_DUAL;

Timing Configuration

The sensor’s timing and synchronization can be configured using the following options:

Timing Source: The timestamp_mode field allows you to switch between internal timing, PTP 1588, or an external sync-pulse (PPS) input.

GNSS Input: The multipurpose_io_mode can be set to accept NMEA sentences from a GNSS receiver via the multi-purpose IO port. Other modes are available for driving sync or PPS outputs.

NMEA Baud Rate: The nmea_baud_rate parameter sets the serial speed for the NMEA UART, which must correspond to the baud rate of your GNSS receiver (e.g., 9600, 115200).

# or TIME_FROM_PTP_1588, TIME_FROM_SYNC_PULSE_IN
config.timestamp_mode = core.TimestampMode.TIME_FROM_INTERNAL_OSC
config.multipurpose_io_mode = core.MultipurposeIOMode.OUTPUT_FROM_INTERNAL_OSC
config.nmea_baud_rate = core.NMEABaudRate.BAUD_9600
// or TIME_FROM_PTP_1588, TIME_FROM_SYNC_PULSE_IN
config.timestamp_mode = core::TimestampMode::TIME_FROM_INTERNAL_OSC;
config.multipurpose_io_mode = core::MultipurposeIOMode::INPUT_NMEA_UART;
config.nmea_baud_rate = core::NMEABaudRate::BAUD_9600;

For a complete list of configurable options view API reference SensorConfig. To view the complete code for above example please refer to the github repository. The github icon on the top-right corner on each code snippet will redirect you to the actual code on the repository.

Set Configuration

set_config can be used to apply sensor configuration parameters.

The SensorConfig struct consists of several optional members, which can be set directly. Members which are not set will not set sensor configuration parameters when sent to the sensor.

To work with your sensor, you should configure the ports, the OperatingMode, and the LidarMode.

# set the values that you need: see sensor documentation for param meanings
config.operating_mode = core.OperatingMode.NORMAL
config.lidar_mode = core.LidarMode._1024x10
config.udp_dest = "@auto"
// set the values that you need: see sensor documentation for param meanings
config.operating_mode = core::OperatingMode::NORMAL;
config.lidar_mode = core::LidarMode::_1024x10;
config.udp_dest = "@auto";

Once defined, one can now call set_config to apply the above configuration.

persist = True

sensor.set_config(sensor_hostname, config, persist)
auto persist = true;
config_flags |= sensor::CONFIG_PERSIST;
sensor::set_config(sensor_hostname, config, config_flags);

Note

The automatic udp destination flag cannot be set via CONFIG_UDP_DEST_AUTO when config.udp_dest is set, as those conflict.

After setting the configuration, retrieve the configuration from the sensor using get_config to ensure that the settings were applied correctly.