-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deserialize the cdr message #473
Comments
@mabelzhang is this issue related to #476 ? Either way, do you have insight on how this functionality can be accomplished via the python API? |
I have very limited understanding of CDR (zero understanding) and message deserialization (a little more than zero), so I will try to answer what I can and hope something hits. Looks like this implementation deals with I think that's what you're asking - deserializing the ROS messages, as opposed to CDR? If that's not what you're asking, and you're asking about CDR, then I have no clue. |
From my understanding the goal here is "read data out of rosbag into an understandable format so that it can be saved out in a different format" - I think currently this is talking about CDR because that's the data that was discovered to be available, not because it's a desired format to work with. I'm assuming that if there were a Python API available to read out the bag as deserialized Python message objects then that would solve the problem. @anacsousa1 can you confirm if this is what you're trying to accomplish? |
We might have |
|
@anacsousa1 it's great that you've come already thus far and the link Mabel posted should do exactly what you're missing, namely taking a buffer with serialized CDR data and convert it into a python ROS2 message. Please don't go down that rabbit hole of implementing a CDR parser in python. ROS2 has code in place to do that for you ;-) |
Hey! Thank you all for the responses! I won't be able to do any further tests until the beginning of the next week. But I wanted to make sure I understood the idea: I really did not intend to create the API, if there is an easier path, I definitely prefer that! |
Use If you want to try another API, you can try the branch in this PR #308 . It is almost ready to merge, I just need to add one more feature and look into a compiler warning on Windows. Everything is working. |
Hey @mabelzhang , thanks a lot for the answer. I believe I am too noob in this. If you could help me with more "baby steps" I would really appreciate it. But I am having trouble using the functions you suggested. A few things I tried:
As you can see, I am totally lost... |
all you'd need to do is to install the test msgs package - we have binary packages for this, so you don't need to compile it yourself. You could either use |
Thanks a lot for the answer, I installed the test msgs and build it successfully! sudo apt-get install ros-foxy-test-msgs
colcon build --packages-select rosbag2_cpp rosbag2_test_common shared_queues_vendor sqlite3_vendor rosbag2_storage rosbag2_storage_default_plugins I expected to find an executable at the CMake, as it does not have one (so it is not just running I thank you for the patience with this type of questions. |
Clone from the root (the URL from the green button on the repo page):
To simplify the packages you pass to
Which file are you trying to run? If you're looking to run the test Python scripts in For your use case, another way to try out the deserialization is to copy those two lines |
@mabelzhang, thanks a lot! I used the get_message and deserialize_message as the example you showed me, and it is working perfectly with the functions I have already created: import rosbag_api as bag
from rosidl_runtime_py.utilities import get_message
from rclpy.serialization import deserialize_message
bag_file = 'rosbag2_2020_07_13-18_13_16/rosbag2_2020_07_13-18_13_16_0.db3'
topic_name = '/control/stim'
### connect to the database
conn, c = bag.connect(bag_file)
### get all topics names and types
topic_names = bag.getAllTopicsNames(c, print_out=False)
topic_types = bag.getAllMsgsTypes(c, print_out=False)
# Create a map for quicker lookup
type_map = {topic_names[i]:topic_types[i] for i in range(len(topic_types))}
### get all timestamps and all messages
t, msgs = bag.getAllMessagesInTopic(c, topic_name, print_out=False)
### >>> deserialization
msg_type = get_message(type_map[topic_name])
x = deserialize_message(msgs[1], msg_type)
print(x)
### close connection to the database
bag.close(conn) Side note: errors related to pybind11:I cloned the repository, checkout to your branch, and build the code (thank you a lot for the CMake Error at CMakeLists.txt:20 (find_package):
By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "pybind11",
but CMake did not find one. I tried to fix with # Some prerequisites (but not all of them)
apt-get install cmake
pip3 install pytest
# Clone, build and install
git clone https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake ..
sudo make install Issue closedAnyway, now, I am able to get information from messages perfectly. =] |
Thank you for the feedback! Glad it worked for you! We added |
For anyone landing here and using the foxy branch that doesn't have the rosbag2_py. Here is an example using sqlite3
|
How to deserialize cdr message without ros? (C++) |
Such a method above were available in foxy as eloquent don't have rclpy.serialization |
In Ros2, Is there an generic way of deserialising the messages as in ROS1, like |
I get a "string data is not null-terminated" on galactic when using the |
is there also the possibility to use own defined messages? |
For customized module, I get around it with using importlib directly. please see the following code:
|
Is this obsolete with humble or rolling? |
To add to the code of @anacsousa1 , here is the python script for anyone interested to get the values of each attribute of a topic in a CSV file:
|
Hello, thank you for the repository and for the instructions. I have been using the rosbag2 play, record, and info successfully.
However, I need to save data in another format (along with the bag files). And I have not found a python-API for data deserialization.
I innocently thought I could create a python API to open the CDR file and read it as messages. What I have done so far was
Opening and closing the bag file;
Finding if a specific topic is in the database;
Getting all messages in the topic;
Getting all topics names;
Getting all message types;
Getting message types for particular topics.
So, with that, I can get each message sent. However, I am at the moment of actual deserialization, and I couldn't fully understand how the cdr file is constructed.
When I print a message, I get, for example:
b'\x00\x01\x00\x00\x0f\x00\x00\x00Fake ergometer\x00\x00\x00\x00\x00\x00\xcd\xcc\xcc\xcc\xcc\xcc<@\xfd\xff\xff\xff\xff\xffA@'
I know that the first field is a string with the value "Fake ergometer," so I know I am on the right path. But how do I go from there? What does the header mean, for example?
\x00\x01\x00\x00\x0f\x00\x00\x00
I have been trying to read the CDR documentation (from OMG). Still, it is not direct, and sometimes it mentions different versions of GIOP, so I get confused.
I appreciate any help.
Bellow are the functions for the python-API that I created:
The text was updated successfully, but these errors were encountered: