Further information: I tried with another rosbag (also containing the visualization_msgs/Marker message) and got the same error. I also tried it in MATLAB online, and there it works. I suspect it has something to do with my installed MATLABs using the wrong character encoding when opening the rosbag.
rosbag error message "Unexpected character after type and field"
6 views (last 30 days)
Show older comments
Hi!
I'm having problems opening a rosbag file in MATLAB R2024a. When only executing the line "bagselect = rosbag("agriData.bag");" I get the following error:
Unexpected character after type and field ' # Scale of the object 1,1,1 means default (usually 1 meter square)':
MSG: visualization_msgs/Marker
# See http://www.ros.org/wiki/rviz/DisplayTypes/Marker and http://www.ros.org/wiki/rviz/Tutorials/Markers%3A%20Basic%20Shapes for more information on using this message with rviz
uint8 ARROW=0
uint8 CUBE=1
uint8 SPHERE=2
uint8 CYLINDER=3
uint8 LINE_STRIP=4
uint8 LINE_LIST=5
uint8 CUBE_LIST=6
uint8 SPHERE_LIST=7
uint8 POINTS=8
uint8 TEXT_VIEW_FACING=9
uint8 MESH_RESOURCE=10
uint8 TRIANGLE_LIST=11
uint8 ADD=0
uint8 MODIFY=0
uint8 DELETE=2
uint8 DELETEALL=3
Header header # header for time/frame information
string ns # Namespace to place this object in... used in conjunction with id to create a unique name for the object
int32 id # object ID useful in conjunction with the namespace for manipulating and deleting the object later
int32 type # Type of object
int32 action # 0 add/modify an object, 1 (deprecated), 2 deletes an object, 3 deletes all objects
geometry_msgs/Pose pose # Pose of the object
geometry_msgs/Vector3 scale # Scale of the object 1,1,1 means default (usually 1 meter square)
std_msgs/ColorRGBA color # Color [0.0-1.0]
duration lifetime # How long the object should last before being automatically deleted. 0 means forever
bool frame_locked # If this marker should be frame-locked, i.e. retransformed into its frame every timestep
#Only used if the type specified has some use for them (eg. POINTS, LINE_STRIP, ...)
geometry_msgs/Point[] points
#Only used if the type specified has some use for them (eg. POINTS, LINE_STRIP, ...)
#number of colors must either be 0 or equal to the number of points
#NOTE: alpha is not yet used
std_msgs/ColorRGBA[] colors
# NOTE: only used for text markers
string text
# NOTE: only used for MESH_RESOURCE markers
string mesh_resource
bool mesh_use_embedded_materials
I have tried this on two different computers running MATLAB 2024a and 2023b. The 2023b has all the toolboxes installed, but for the 2024a I tried a bare bones install with just MATLAB, Simulink and ROS Toolbox. The strangest thing is that two of my colleagues can open this rosbag in MATLAB. At least one of the colleagues is running R2024a on a Windows system like I do.
3 Comments
Walter Roberson
on 15 Jul 2024
geometry_msgs/Pose pose
That does not appear to be valid C or C++. It would make more sense if it were
geometry_msgs::Pose pose
or something like that.
Accepted Answer
Kautuk Raj
on 22 Aug 2024
It sounds like you are encountering an issue with opening a ‘rosbag’ file in MATLAB R2024a, which might be related to custom message types or compatibility issues. Here are some steps you can try to resolve this issue:
(1) Create New Rosbag Files:
Use ‘rosbagwriter’ to create your ‘rosbag’ files. Note that this function will not work on already existing ‘rosbag’ files. More about this function can be found on this documentation page here: https://www.mathworks.com/help/ros/ref/rosbagwriter.html
(2) Re-record Existing Bag Files:
If the above does not work, consider re-recording the existing bag files in the ROS environment. Here is the workflow to get past the issue:
Register the Custom Message in MATLAB:
Execute rosRegisterMessages('C:\rosbags'); where 'C:\rosbags' is your working directory.
Register the custom message with the ROS Noetic installation as well. More can be found on their respective documentation pages here: https://wiki.ros.org/noetic/Installation
Here, 'catkin_ws' refers to the Catkin Workspace, refer to the details here: https://industrial-training-master.readthedocs.io/en/melodic/_source/session1/Create-Catkin-Workspace.html
Set Up ROS Noetic Workspace:
In the MATLAB command window, extract the catkin_ws.zip file to a location, for example, D:\workspaces\catkin_ws.
Open a ROS Noetic terminal or command window and execute the following commands:
cd D:\workspaces\catkin_ws
catkin_make # Ensure build is successful
call D:\workspaces\catkin_ws\devel\setup.bat
roscore # Start ROS master node
Play and Record Rosbag:
Open two more ROS Noetic command windows.
In one terminal, play the existing bag containing the standard message using:
rosbag play existing_bag.bag
In the new terminal, register the custom message using:
call D:\workspaces\catkin_ws\devel\setup.bat
Record a rosbag with all topics using:
rosbag record -a
This will record a new bag with the custom message.
Run Rosbag in MATLAB:
Open MATLAB, where you have already registered the custom ‘sensor_msgs/Image’ (with the previously suggested workaround for new bag files).
rosbag('filename')
These steps should help resolve the issue with opening ‘rosbag’ files in MATLAB.
0 Comments
More Answers (0)
See Also
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!