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

조회 수: 6 (최근 30일)
Camilo
Camilo 2017년 11월 16일
편집: Walter Roberson 2024년 1월 16일
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

답변 (1개)

MathWorks Robotics and Autonomous Systems Team
편집: Walter Roberson 2024년 1월 16일
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
Kyle Gao
Kyle Gao 2024년 1월 15일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 ROS Network Connection and Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by