Problems in reading rosbag message type

5 次查看(过去 30 天)
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!

回答(2 个)

Sebastian Castro
Sebastian Castro 2017-7-10
编辑:Sebastian Castro 2017-7-10
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 个评论
ARUN ANNAIYAN
ARUN ANNAIYAN 2017-7-11
oh yah! i just noticed the simple error but still i can't get the data in the workspace. so i changed like this below,
bag=rosbag('/home/arun/Workspace/catkin/src/rosbag/path_planning.bag');
bagselect1 = select(bag, 'Topic', '/move_base/NavfnROS/plan')
msgs = readMessages(bagselect1);
Now i can see the data. But i don't how to plot this as time series? if i try like this,
timeinterval=[starttime endtime];
topic_pose=select(bagselect1,'Time',timeinterval,'Topic','/move_base/NavFnROS/plan');
it is not working....
Sebastian Castro
Sebastian Castro 2017-7-11
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
poluri koundinya 2018-7-24
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 个评论
Sebastian Castro
Sebastian Castro 2018-7-28
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

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by