select
Select subset of messages in rosbag
Description
returns a bagreadersel
= select(bagreader
)rosbagreader
object
bagreadersel
, that contains all of the messages in the rosbagreader
object
bagreader
.
This function creates a copy of the rosbagreader
object
or returns a new rosbagreader
object
that contains the specified message selection.
specifies additional parameters using one or more name-value arguments. For example
bagreadersel
= select(bagreader
,Name=Value)Topic="/odom"
selects a subset of the messages, filtered by the topic
/odom
.
Examples
Create rosbag Selection Using rosbagreader
Object
Load a rosbag log file and parse out specific messages based on the selected criteria.
Create a rosbagreader
object of all the messages in the rosbag log file.
bagMsgs = rosbagreader("ros_multi_topics.bag")
bagMsgs = rosbagreader with properties: FilePath: '/mathworks/devel/bat/Bdoc22b/build/matlab/toolbox/robotics/robotexamples/ros/data/bags/ros_multi_topics.bag' StartTime: 201.3400 EndTime: 321.3400 NumMessages: 36963 AvailableTopics: [4x3 table] AvailableFrames: {0x1 cell} MessageList: [36963x4 table]
Select a subset of the messages based on their timestamp and topic.
bagMsgs2 = select(bagMsgs,... Time=[bagMsgs.StartTime bagMsgs.StartTime + 1],... Topic='/odom')
bagMsgs2 = rosbagreader with properties: FilePath: '/mathworks/devel/bat/Bdoc22b/build/matlab/toolbox/robotics/robotexamples/ros/data/bags/ros_multi_topics.bag' StartTime: 201.3400 EndTime: 202.3200 NumMessages: 99 AvailableTopics: [1x3 table] AvailableFrames: {0x1 cell} MessageList: [99x4 table]
Retrieve the messages in the selection as a cell array.
msgs = readMessages(bagMsgs2)
msgs=99×1 cell array
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
⋮
Return certain message properties as a time series.
ts = timeseries(bagMsgs2,... 'Pose.Pose.Position.X', ... 'Twist.Twist.Angular.Y')
timeseries Timeseries contains duplicate times. Common Properties: Name: '/odom Properties' Time: [99x1 double] TimeInfo: tsdata.timemetadata Data: [99x2 double] DataInfo: tsdata.datametadata
Input Arguments
bagreader
— Index of messages in rosbag
rosbagreader
object
Index of the messages in the rosbag, specified as a rosbagreader
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: Topic="/odom"
selects a subset of the messages, filtered by
the topic /odom
.
MessageType
— ROS message type
string scalar | character vector | cell array of string scalars | cell array of character vectors
ROS message type, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Specify multiple message types by using a cell array.
Example: select(bagreader,MessageType={"nav_msgs/Odometry","rosgraph_msgs/Clock"})
Data Types: char
| string
| cell
Time
— Start and end times of rosbag selection
n-by-2 vector
Start and end times of the rosbag selection, specified as an n-by-2 vector.
Example: select(bagreader,Time=[bag.StartTime,bag.StartTime+1])
Data Types: double
Topic
— ROS topic name
string scalar | character vector | cell array of string scalars | cell array of character vectors
ROS topic name, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Specify multiple topic names by using a cell array.
Example: select(bagreader,Topic={"/odom","/clock"})
Data Types: char
| string
| cell
Output Arguments
bagreadersel
— Copy or subset of rosbag messages
rosbagreader
object
Copy or subset of rosbag messages, returned as a rosbagreader
object.
Version History
Introduced in R2021b
See Also
rosbagreader
| readMessages
| timeseries
| canTransform
| getTransform
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)