Comments (10)
I stumbled upon https://github.com/facontidavide/rosx_introspection and was able to make a prototype! Here is the pseudo-code:
#include "rosx_introspection/ros_parser.hpp"
#include "rosx_introspection/ros_utils/ros2_helpers.hpp"
using namespace RosMsgParser;
ParsersCollection<ROS2_Deserializer> parser_;
void print_fields(const std::string& topic_name, const std::string& topic_type, std::shared_ptr<const rclcpp::SerializedMessage> serialized_message) {
parser_.registerParser(topic_name, ROSType(topic_type),
GetMessageDefinition(topic_type));
std::vector<uint8_t> buffer(serialized_message->get_rcl_serialized_message().buffer_length);
memcpy(buffer.data(), serialized_message->get_rcl_serialized_message().buffer, serialized_message->get_rcl_serialized_message().buffer_length);
const FlatMessage* flat_container = parser_.deserialize(topic_name, Span<uint8_t>(buffer));
for (auto& it : flat_container->value)
{
std::cout << it.first << " >> " << it.second.convert<double>() << std::endl;
}
for (auto& it : flat_container->name)
{
std::cout << it.first << " >>>" << it.second << std::endl;
}
}
@facontidavide thanks for that project. As there is no real guide, I got inspired from the tests mostly, am I using your library correctly? Any recommendations?
@Barry-Xu-2018 @fujitatomoya maybe this could be a good starting point to implement something similar in rclcpp?
from rclcpp.
This is a simple sample (The code is a bit ugly. I haven't had time to check out the implementation of rosx_introspection yet.). It tries to get items of sensor_msgs::msg::Temperature based on generic subscription.
https://github.com/Barry-Xu-2018/msg_introspection_demo
from rclcpp.
I found this simillar unanswered question: https://answers.ros.org/question/405796/deserialize-message-with-topic-name-ros2/
from rclcpp.
@Barry-Xu-2018 do you have any thoughts?
from rclcpp.
I think there are two scenarios.
- The message type is one of a few known types
- The message type is completely unknown (many types).
In the first scenario, you should be able to easily cast the pointer to the message type.
In the second scenario, you can use type support to parse each type in the message one by one.
e.g.
https://github.com/ros2/rosbag2/blob/fa84cfeeb0b640d53c23d25634ec5b0177ae1efe/rosbag2_transport/src/rosbag2_transport/player_service_client.cpp#L163-L168
If you want this way, I can provide a simple example to demonstrate how to do.
from rclcpp.
Thanks @Barry-Xu-2018 for your answer. Mine is the second scenario, I'd be grateful if you can provide an example. I would try it out and give feedback in a couple of hours
from rclcpp.
what about having either demos or examples for this? i believe that would be useful for ROS community?
from rclcpp.
what about having either demos or examples for this? i believe that would be useful for ROS community?
It would definitely be useful to a handful of people given that it's been asked a couple of times already here and there
Also the reason why we would need a tutorial for this is because it's (imo) a reasonable thing for high-level users of ROS to want to do but the way to do it seems pretty low-level (with type support and other things I've never heard of with 5 years of experience with ROS). So I'm wondering if it would make sense to expose this functionality on a higher-level? Some function in client libraries?
from rclcpp.
Just found #2260 which is also similar
from rclcpp.
I'd be grateful if you can provide an example. I would try it out and give feedback in a couple of hours
Apologies for the delayed reply. I will prepare a simple example for you.
I'll look into https://github.com/facontidavide/rosx_introspection.
from rclcpp.
Related Issues (20)
- Callback works on Galactic but fails on Rolling - handle_message is not implemented for GenericSubscription HOT 1
- Clang warning: ordered comparison of function pointers (Rolling) HOT 1
- `-fanalyzer` warning: possible null dereference when using TypeAdapters HOT 4
- leak due to std::shared_ptr circular reference between Context and GuardCondition HOT 3
- :farmer: `rclcpp.test_executors` failing in Rolling and Jammy CycloneDDS HOT 1
- rclcpp::Time(int64_t nanoseconds, ...) should check for negative time
- Regression : Executor::spin_some_impl is active waiting HOT 5
- Parameter service behavior is inconsistent with the documentation of rcl_interfaces HOT 9
- Lifecycle destructor calls shutdown while in shuttingdown intermediate state HOT 45
- Backport PR2063 to Humble for Windows HOT 2
- Executor callbacks are no longer in a predictable order HOT 25
- '/clock' Topic cannot change each loop step time from simulation time HOT 10
- Program exits with code -11 when using async_send_request to set parameters in ROS 2 C++ client HOT 1
- Timer callbacks can be delayed when using simulation time HOT 4
- Possible regression in rcl preshutdown callbacks - context invalid? HOT 10
- Shutdown transition on base lifecycle node dtor may lead to segaults on subclass-registered shutdown callback HOT 6
- `on_shutdown` callback not called when `shutdown` transition is triggered on dtor HOT 2
- ABI/API Compliance Checker in github workflow HOT 2
- [rclcpp] C++ lib leaking `rclcpp::Node()` can cause segfaults at `dlclose()` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rclcpp.