Problems in reading rosbag message type
5 views (last 30 days)
Show older comments
Hello,
I'm trying to read the rosbag message in the matlab,
bag=rosbag('path_planning.bag');
starttime=bag.StartTime;
endtime =bag.EndTime;
timeinterval=[starttime endtime];
topic_pose=select(bag,'Time',timeinterval,'Topic','/move_base/NavFnROS/path');
% ts = timeseries(bag, 'Pose.Pose.Position.X', 'Twist.Twist.Angular.Z');
position = timeseries(topic_pose,...
'Poses.Pose.Position.X',...
'Poses.Pose.Position.Y',...
'Poses.Pose.Position.Z');
But i cannot get any data. The messsage type is nav_msgs/Path, what went wrong here in this code?
thanks in advance!
0 Comments
Answers (2)
Sebastian Castro
on 10 Jul 2017
Edited: Sebastian Castro
on 10 Jul 2017
What do you mean by "cannot get data"? Do you have an error message or does your code run fine without an error?
I think there's a level of indexing missing, because a nav_msg/Path message actually contains an array of geometry_msgs/PoseStamped messages. You're going right into the former message and treating it like the latter.
>> rosmsg info nav_msgs/Path
%An array of Poses that represents a Path for a robot to follow
std_msgs/Header Header
geometry_msgs/PoseStamped[] Poses
>> rosmsg info geometry_msgs/PoseStamped
% A Pose with reference coordinate frame and timestamp
std_msgs/Header Header
Pose Pose
Not 100% sure how the rosbag data looks (you can share a snippet if you'd like), but I would guess you either have to grab individual elements of the array of pose messages, or the timeseries contains higher-dimensional data.
What I would do is display topic_pose in the MATLAB Command Window and taking a deeper look at the contents of the Data property. What type/size/etc. is it?
- Sebastian
4 Comments
Sebastian Castro
on 11 Jul 2017
Hmm... my guess is because it's a more complex/structures message, maybe it doesn't work with timeseries but you can still extract the data as an array of messages, as in your first code snippet.
If you're willing to share your .bag file, I can take a look.
poluri koundinya
on 24 Jul 2018
hi,
I have a bagfile in the following path path: https://github.com/ouster-lidar/ouster_example#running-the-sample-ros-node
> bag.AvailableTopics
ans =
2×3 table
NumMessages MessageType MessageDefinition
___________ ____________________ _________________
/os1_node/imu_packets 9977 ouster_ros/PacketMsg 'uint8[] Buf↵'
/os1_node/lidar_packets 63861 ouster_ros/PacketMsg 'uint8[] Buf↵'
bagselect1 = select(bag, 'Topic', '/os1_node/lidar_packets')
bagselect1 =
BagSelection with properties:
FilePath: 'C:\Users\nikhil\Desktop\bag file\x.bag'
StartTime: 1.5284e+09
EndTime: 1.5284e+09
NumMessages: 63861
AvailableTopics: [1×3 table]
AvailableFrames: {0×1 cell}
MessageList: [63861×4 table]
>> allMsgs = readMessages(bagselect1); Error using robotics.ros.BagSelection/readMessages (line 279) Cannot find a MATLAB message class for type ouster_ros/PacketMsg.
I need to see the point cloud data in the bagfile but the topic does not contain sensor_msgs/PointCloud2.
then how am i supposed to get the point cloud data out of it? any help
1 Comment
Sebastian Castro
on 28 Jul 2018
We responded to the email you sent us, but will answer here too.
Your /os1_node/lidar_packets topic is not of the correct type sensor_msgs/PointCloud2
So, you either need to make sure whatever is publishing to that topic is doing it with the right message type, or figure out a way to get the uint8[] data in your message converted to a point cloud by some other means.
Also, since the ouster_ros/PacketMsg is a custom ROS message definition you created, to use it in MATLAB you need to go through the custom message support workflow:
- Sebastian
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!