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

12 views (last 30 days)
Thanks for your help. I am working with rosbag files in MATLAB R2016B. Following the examples in 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
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?
Best Regards

Answers (1)

MathWorks Robotics and Autonomous Systems Team
As shown in the example:
>> 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.


Find more on ROS Log Files and Specialized Messages 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!