Main Content

reset

Reset CurrentTime property of ousterROSMessageReader object to default value

Since R2024a

Description

reset(ousterReader) resets the CurrentTime property of the specified ousterROSMessageReader object to the default value. The default value is the value of the StartTime property of the ousterROSMessageReader object.

example

Examples

collapse all

This example shows how to handle Ouster ROS messages from an Ouster® lidar sensor to visualize point cloud data from road intersection.

Ouster ROS messages store data in a format that requires some interpretation before it can be used for further processing. MATLAB® can help you by formatting Ouster ROS messages for easy use.

Download lidar capture data of road intersection from MathWorks® Supportfiles site.

httpsUrl = "https://ssd.mathworks.com";
dataUrl = strcat(httpsUrl,"/supportfiles/spc/ROS/ROS_Ouster_Supportfiles.zip");
dataFile = "ROS_Ouster_Supportfiles.zip";
lidarData = websave(dataFile,dataUrl);

Extract the ZIP file that contains lidar capture data of road intersection.

unzip("ROS_Ouster_Supportfiles.zip")

Load the ROS bag file to retrieve information from it.

bag = rosbag("lidar_capture_of_road_intersection.bag");

Create a BagSelection object that contains the Ouster messages filtered by the topic /os_node/lidar_packets.

bSel = select(bag,"Topic","/os_node/lidar_packets");

Read the messages from the selection. Each element in the msgs cell array is an Ouster ROS message struct. Using messages in structure format supports better performance.

msgs = readMessages(bSel, DataFormat="struct");

Create Ouster ROS Message Reader

The ousterROSMessageReader object reads point cloud data from ouster_ros/PacketMsg ROS messages, collected from an Ouster lidar sensor.

ousterReader = ousterROSMessageReader(msgs,"lidar_capture_of_road_intersection.json")
ousterReader = 
  ousterROSMessageReader with properties:

     OusterMessages: {45342×1 cell}
    CalibrationFile: 'C:\Users\echakrab\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\echakrab.myBdoc\ros-ex32591831\lidar_capture_of_road_intersection.json'
     NumberOfFrames: 709
           Duration: 70.89 sec
          StartTime: 3539.2 sec
            EndTime: 3610.1 sec
         Timestamps: [3539.2 sec    3539.3 sec    3539.4 sec    3539.5 sec    3539.6 sec    3539.7 sec    3539.8 sec    3539.9 sec    3540 sec    3540.1 sec    3540.2 sec    3540.3 sec    3540.4 sec    3540.5 sec    3540.6 sec    …    ] (1×709 duration)
        CurrentTime: 3539.2 sec

Extract Point Clouds

You can extract point clouds from the raw packets message with the help of this ousterROSMessageReader object. By providing a specific frame number or timestamp, one point cloud can be extracted from ousterROSMessageReader object using the readFrame object function. If you call readFrame without a frame number or timestamp, it extracts the next point cloud in the sequence based on the CurrentTime property.

Create a duration scalar that represents one second after the first point cloud reading.

timeDuration = ousterReader.StartTime + seconds(1);

Read the first point cloud recorded at or after the given time duration.

ptCloudObj = readFrame(ousterReader,timeDuration);

Access Location data in the point cloud.

ptCloudLoc = ptCloudObj.Location;

Reset the CurrentTime property of ousterReader to the default value.

reset(ousterReader)

Display Point Clouds

You can also loop through all point clouds in the input Ouster ROS messages.

Define x-, y-, and z-axes limits for pcplayer in meters. Label the axes.

xlimits = [-60 60];
ylimits = [-60 60];
zlimits = [-20 20];

Create the point cloud player and label the axes.

player = pcplayer(xlimits,ylimits,zlimits);
xlabel(player.Axes,'X (m)');
ylabel(player.Axes,'Y (m)');
zlabel(player.Axes,'Z (m)');

The first point cloud of interest is captured at 0.3 second into the input messages. Set the CurrentTime property to that time to begin reading point clouds from there.

ousterReader.CurrentTime = ousterReader.StartTime + seconds(0.3);

Display the point cloud stream for 2 seconds. To check if a new frame is available and continue past 2 seconds, remove the last while condition. Iterate through the file by calling readFrame to read in point clouds. Display them using the point cloud player.

while(hasFrame(ousterReader) && isOpen(player)) && (ousterReader.CurrentTime < ousterReader.StartTime + seconds(2))
ptCloudObj = readFrame(ousterReader);
view(player,ptCloudObj.Location,ptCloudObj.Intensity);
pause(0.1);
end

Figure Point Cloud Player contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains an object of type scatter.

Reset the CurrentTime property of the reader object to the default value.

reset(ousterReader)

Input Arguments

collapse all

Ouster ROS message reader, specified as a ousterROSMessageReader object.

Version History

Introduced in R2024a