Lidar Class Reference

Class for Lidar control and data retrieval.
It provides methods to initialize the Lidar, retrieve data, and enable positional tracking.
Supports both live sensor input and OSF file playback. More...

Functions

 Lidar ()
 Lidar constructor. More...
 
 ~Lidar ()
 Lidar destructor. More...
 
sl::ERROR_CODE open (InitLidarParameters params)
 Opens the Lidar. More...
 
bool isOpened () const
 Checks if the Lidar is opened. More...
 
InitLidarParameters getInitParameters () const
 Returns the initialization parameters used to open the Lidar. More...
 
LidarInformation getLidarInformation () const
 Returns the Lidar information. More...
 
CUcontext getCUDAContext () const
 Returns the CUDA context used by the Lidar when GPU mode is enabled. More...
 
sl::ERROR_CODE read ()
 Reads the next data chunk. More...
 
sl::ERROR_CODE grab ()
 Grabs a new frame. More...
 
sl::ERROR_CODE retrieveMeasure (sl::Mat &mat, sl::LIDAR_MEASURE measure, sl::Resolution res=sl::Resolution(0, 0), sl::MEM type=sl::MEM::CPU, sl::VIEW_COLOR_MAP color_map=sl::VIEW_COLOR_MAP::AUTO, cudaStream_t stream=0)
 Retrieves a measure texture (raw float data). More...
 
sl::ERROR_CODE retrieveView (sl::Mat &mat, sl::LIDAR_VIEW view, sl::Resolution res=sl::Resolution(0, 0), sl::VIEW_COLOR_MAP color_map=sl::VIEW_COLOR_MAP::AUTO, cudaStream_t stream=0)
 Retrieves a view texture (visual data). More...
 
sl::Timestamp getTimestamp (sl::TIME_REFERENCE reference_time) const
 Returns the timestamp of the frame or the current time. More...
 
float getCurrentFPS () const
 Returns the current framerate at which the grab() method is successfully called. More...
 
sl::ERROR_CODE getSensorsData (sl::SensorsData &data, sl::TIME_REFERENCE reference_time=sl::TIME_REFERENCE::CURRENT)
 Retrieves sensors data (IMU). More...
 
sl::ERROR_CODE enablePositionalTracking (PositionalTrackingLidarParameters params=PositionalTrackingLidarParameters())
 Enables positional tracking. More...
 
void disablePositionalTracking ()
 Disables positional tracking. More...
 
sl::POSITIONAL_TRACKING_STATE getPosition (sl::Pose &pose, sl::REFERENCE_FRAME reference_frame=sl::REFERENCE_FRAME::WORLD)
 Retrieves the current position. More...
 
sl::ERROR_CODE enableRecording (RecordingLidarParameters params)
 Enables recording. More...
 
void disableRecording ()
 Disables recording. More...
 
int getSVOPosition () const
 Gets the current SVO/OSF playback position (frame index). More...
 
sl::ERROR_CODE setSVOPosition (int frame_number)
 Sets the SVO/OSF playback position (frame index). More...
 
int getSVONumberOfFrames () const
 Gets the total number of frames in the SVO/OSF file. More...
 
int getSVOPositionAtTimestamp (sl::Timestamp timestamp) const
 Retrieves the frame index within the SVO/OSF file corresponding to the provided timestamp. More...
 
void setTimestampBaseOffset (int64_t offset)
 Sets the base timestamp offset for converting OSF sensor timestamps to Unix epoch. More...
 
int64_t getTimestampBaseOffset () const
 Gets the base timestamp offset for OSF playback. More...
 
void pauseSVOReading (bool status)
 Pauses or resumes SVO/OSF reading. More...
 
void close ()
 Closes the Lidar. More...
 

Static Functions

static std::vector< LidarDevicePropertiesgetDeviceList ()
 Returns a list of available Lidar devices. More...
 
static std::vector< LidarDevicePropertiesgetStreamingDeviceList ()
 Returns a list of streaming Lidar devices. More...
 

Detailed Description

Class for Lidar control and data retrieval.
It provides methods to initialize the Lidar, retrieve data, and enable positional tracking.
Supports both live sensor input and OSF file playback.

Note
Beta: The Lidar class is currently in beta. Interfaces and behavior may change in future SDK releases.
// Example usage with live sensor
sl::Lidar lidar;
init_params.input.setFromStream("192.168.1.50");
lidar.open(init_params);
lidar.grab();
sl::Mat point_cloud;
lidar.close();
void setFromStream(sl::String sender_ip, unsigned short port=30000)
Set the input as the stream defined by the IP address and the port of the sending device.
Class for Lidar control and data retrieval. It provides methods to initialize the Lidar,...
Definition: Lidar.hpp:650
sl::ERROR_CODE open(InitLidarParameters params)
Opens the Lidar.
sl::ERROR_CODE grab()
Grabs a new frame.
void close()
Closes the Lidar.
sl::ERROR_CODE retrieveMeasure(sl::Mat &mat, sl::LIDAR_MEASURE measure, sl::Resolution res=sl::Resolution(0, 0), sl::MEM type=sl::MEM::CPU, sl::VIEW_COLOR_MAP color_map=sl::VIEW_COLOR_MAP::AUTO, cudaStream_t stream=0)
Retrieves a measure texture (raw float data).
Class representing 1 to 4-channel matrix of float or uchar, stored on CPU and/or GPU side.
Definition: Core.hpp:109
@ XYZ
Point cloud (3 channels, float 32). Contains X, Y, Z coordinates.
Structure containing the options used to initialize the Lidar object.
Definition: Lidar.hpp:426
sl::InputType input
Input type (stream, etc.).
Definition: Lidar.hpp:430
// Example usage with OSF file playback (similar to SVO for Camera)
sl::Lidar lidar;
init_params.input.setFromSVOFile("/path/to/recording.osf");
lidar.open(init_params);
while (lidar.grab() == sl::ERROR_CODE::SUCCESS) {
sl::Mat point_cloud;
// Process point cloud...
}
lidar.close();
void setFromSVOFile(sl::String svo_input_filename)
Set the input as the SVO specified with the filename.

Constructor and Destructor

◆ Lidar()

Lidar ( )

Lidar constructor.

◆ ~Lidar()

~Lidar ( )

Lidar destructor.

Functions

◆ getDeviceList()

static std::vector<LidarDeviceProperties> getDeviceList ( )
static

Returns a list of available Lidar devices.

Returns
A vector of LidarDeviceProperties.

◆ getStreamingDeviceList()

static std::vector<LidarDeviceProperties> getStreamingDeviceList ( )
static

Returns a list of streaming Lidar devices.

Returns
A vector of LidarDeviceProperties.

◆ open()

Opens the Lidar.

Parameters
params: The initialization parameters.
Returns
ERROR_CODE::SUCCESS if successful, otherwise an error code.

◆ isOpened()

bool isOpened ( ) const

Checks if the Lidar is opened.

Returns
True if opened, false otherwise.

◆ getInitParameters()

InitLidarParameters getInitParameters ( ) const

Returns the initialization parameters used to open the Lidar.

Returns
The InitLidarParameters.

◆ getLidarInformation()

LidarInformation getLidarInformation ( ) const

Returns the Lidar information.

Returns
The LidarInformation containing device info and sensor configuration.

◆ getCUDAContext()

CUcontext getCUDAContext ( ) const

Returns the CUDA context used by the Lidar when GPU mode is enabled.

This method allows you to retrieve the CUDA context created by or provided to the SDK, enabling shared GPU memory operations with other CUDA-enabled libraries.

Returns
The CUDA context, or nullptr if GPU mode is disabled or not initialized.

◆ read()

sl::ERROR_CODE read ( )

Reads the next data chunk.

Returns
ERROR_CODE::SUCCESS if successful.

◆ grab()

sl::ERROR_CODE grab ( )

Grabs a new frame.

Returns
ERROR_CODE::SUCCESS if successful.

◆ retrieveMeasure()

sl::ERROR_CODE retrieveMeasure ( sl::Mat mat,
sl::LIDAR_MEASURE  measure,
sl::Resolution  res = sl::Resolution(0, 0),
sl::MEM  type = sl::MEM::CPU,
sl::VIEW_COLOR_MAP  color_map = sl::VIEW_COLOR_MAP::AUTO,
cudaStream_t  stream = 0 
)

Retrieves a measure texture (raw float data).

Parameters
mat: The sl::Mat to store the measure.
measure: The type of measure to retrieve.
res: The resolution to resize the measure (optional).
type: The memory type (CPU or GPU).
color_map: The colormap if applicable.
stream: The CUDA stream for asynchronous operations (optional, GPU mode only).
Returns
ERROR_CODE::SUCCESS if successful.

◆ retrieveView()

sl::ERROR_CODE retrieveView ( sl::Mat mat,
sl::LIDAR_VIEW  view,
sl::Resolution  res = sl::Resolution(0, 0),
sl::VIEW_COLOR_MAP  color_map = sl::VIEW_COLOR_MAP::AUTO,
cudaStream_t  stream = 0 
)

Retrieves a view texture (visual data).

Parameters
mat: The sl::Mat to store the view.
view: The type of view to retrieve.
res: The resolution to resize the view (optional).
color_map: The colormap to use.
stream: The CUDA stream for asynchronous operations (optional, GPU mode only).
Returns
ERROR_CODE::SUCCESS if successful.

◆ getTimestamp()

sl::Timestamp getTimestamp ( sl::TIME_REFERENCE  reference_time) const

Returns the timestamp of the frame or the current time.


This function can also be used when playing back an OSF file.

Parameters
reference_time: The selected TIME_REFERENCE.
- TIME_REFERENCE::IMAGE : timestamp of the last grabbed frame.
- TIME_REFERENCE::CURRENT : current system time.
Returns
The timestamp in nanoseconds. 0 if not available.
Note
As this function returns UNIX timestamps, the reference it uses is common across several Lidar instances.
sl::Timestamp last_frame_timestamp = lidar.getTimestamp(sl::TIME_REFERENCE::IMAGE);
sl::Timestamp current_timestamp = lidar.getTimestamp(sl::TIME_REFERENCE::CURRENT);
std::cout << "Latest frame timestamp: " << last_frame_timestamp << "ns from Epoch." << std::endl;
std::cout << "Current timestamp: " << current_timestamp << "ns from Epoch." << std::endl;
Structure representing timestamps with utilities.
Definition: types.hpp:2646

◆ getCurrentFPS()

float getCurrentFPS ( ) const

Returns the current framerate at which the grab() method is successfully called.

The returned value is based on the difference of timestamps between two successful grab() calls.

Returns
The current SDK framerate.
Warning
The returned framerate (number of frames grabbed per second) can be lower than the Lidar mode fps if the grab() function runs slower than the data stream or is called too often.
float current_fps = lidar.getCurrentFPS();
std::cout << "Current framerate: " << current_fps << std::endl;

◆ getSensorsData()

sl::ERROR_CODE getSensorsData ( sl::SensorsData data,
sl::TIME_REFERENCE  reference_time = sl::TIME_REFERENCE::CURRENT 
)

Retrieves sensors data (IMU).

Parameters
data: The SensorsData object to store the data.
reference_time: The reference time for the data.
Returns
ERROR_CODE::SUCCESS if successful.

◆ enablePositionalTracking()

Enables positional tracking.

Parameters
params: The positional tracking parameters (optional).
Returns
ERROR_CODE::SUCCESS if successful.

◆ disablePositionalTracking()

void disablePositionalTracking ( )

Disables positional tracking.

◆ getPosition()

Retrieves the current position.

Parameters
pose: The Pose object to store the position.
reference_frame: The reference frame for the position.
Returns
POSITIONAL_TRACKING_STATE.

◆ enableRecording()

sl::ERROR_CODE enableRecording ( RecordingLidarParameters  params)

Enables recording.

Parameters
params: The recording parameters.
Returns
ERROR_CODE::SUCCESS if successful.

◆ disableRecording()

void disableRecording ( )

Disables recording.

◆ getSVOPosition()

int getSVOPosition ( ) const

Gets the current SVO/OSF playback position (frame index).

Returns
The current frame index, or -1 if not in playback mode.

◆ setSVOPosition()

sl::ERROR_CODE setSVOPosition ( int  frame_number)

Sets the SVO/OSF playback position (frame index).

Parameters
frame_number: The frame index to seek to.
Returns
ERROR_CODE::SUCCESS if successful.

◆ getSVONumberOfFrames()

int getSVONumberOfFrames ( ) const

Gets the total number of frames in the SVO/OSF file.

Returns
The total number of frames, or -1 if not in playback mode.

◆ getSVOPositionAtTimestamp()

int getSVOPositionAtTimestamp ( sl::Timestamp  timestamp) const

Retrieves the frame index within the SVO/OSF file corresponding to the provided timestamp.

Parameters
timestamp: The timestamp to search for (in nanoseconds).
Returns
The frame index closest to the given timestamp, or -1 if not in playback mode.

◆ setTimestampBaseOffset()

void setTimestampBaseOffset ( int64_t  offset)

Sets the base timestamp offset for converting OSF sensor timestamps to Unix epoch.

OSF files store sensor-relative timestamps (nanoseconds since sensor boot). This method sets an offset that is added to OSF timestamps when returning frame timestamps via getTimestamp(IMAGE), and subtracted when seeking via getSVOPositionAtTimestamp().

This is used by Sensors::syncSVO() to align LiDAR timestamps with camera timestamps for multi-sensor synchronized playback.

Parameters
offset: The offset in nanoseconds to add to OSF timestamps.
Note
This should be called after open() and before reading frames.

◆ getTimestampBaseOffset()

int64_t getTimestampBaseOffset ( ) const

Gets the base timestamp offset for OSF playback.

Returns
The current timestamp offset in nanoseconds.

◆ pauseSVOReading()

void pauseSVOReading ( bool  status)

Pauses or resumes SVO/OSF reading.

Parameters
status: If true, the reading is paused. If false, the reading is resumed.
Note
This is only relevant when InitLidarParameters::svo_real_time_mode is enabled.

◆ close()

void close ( )

Closes the Lidar.