How to extract data from sensor_msgs/Joy ROS as timeseries in MATLAB script?

3 views (last 30 days)
Hello!
Thanks for your help. I am working with rosbag files in MATLAB R2016B. Following the examples in https://www.mathworks.com/help/robotics/examples/work-with-rosbag-logfiles.html I try to extract data from sensor_msgs/Joy from an specific topic like this:
bagselection_setpoint_attitude = select(bag,'Topic','/controlbot/joystick');
ts_setpoint_attitude = timeseries(bagselection_setpoint_attitude);
When I type ts_setpoint_attitude.Data the answer is:
ts_setpoint_attitude.Data
ans =
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
But this type of messages contains Header, Axes and Buttons. If I use the following code:
test = readMessages(bagselection_setpoint_attitude)
The result is:
test =
946×1 cell array
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
[1×1 Joy]
If I go into each cell, the property Axes which is that I need, show the correct values:
test{1,1}.Axes
ans =
4×1 single column vector
0
0
12
0
Why when I work with timeseries, the data is not visualized correctly? In fact the size of timeseries columns is not correct?
How can I access to Axes data from this type of message successfully?
Thanks!
Best Regards

Answers (1)

MathWorks Robotics and Autonomous Systems Team
Edited: Walter Roberson on 16 Jan 2024
As shown in the example: https://www.mathworks.com/help/robotics/ref/timeseries.html
filepath = fullfile(fileparts(which('ROSWorkingWithRosbagsExample')), 'data', 'ex_multiple_topics.bag');
bag = rosbag(filepath);
bagSelection = select(bag,'Topic','/odom');
ts = timeseries(bagSelection,'Pose.Pose.Position.X');
There was only one topic in the "bagSelection" variable, and then only one data from Pose data was extracted and was put in timeseries fashion.
Follow a similar pattern and you will be able to extract the data you are looking for.
  1 Comment
Kyle Gao
Kyle Gao on 15 Jan 2024
Hi, can you please eleborate more? Odom data is a structure where the x position can be directly accessed by 'Pose.Pose.Position.X'. However, button in /joy topic is a list of numbers. It seems the timeseries function can not associate a timeseries to a list but rather a single value. Thanks in advance

Sign in to comment.

Categories

Find more on ROS Log Files and Transformations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!