reset
Reset CurrentTime
property of
ousterROSMessageReader
object to default value
Since R2024a
Syntax
Description
reset(
resets the
ousterReader
)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.
Examples
Work with Ouster ROS Messages to Visualize Point Cloud Data from Road Intersection
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
Reset the CurrentTime
property of the reader object to the default value.
reset(ousterReader)
Input Arguments
ousterReader
— Ouster® ROS message reader
ousterROSMessageReader
object
Ouster ROS message reader, specified as a ousterROSMessageReader
object.
Version History
Introduced in R2024a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)