Add PlotJuggler bridge example - #783
Conversation
Generated-By: Gemini 2.5 Pro Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Generated-By: Gemini 2.5 Pro Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
|
This is so cool! Taking a look... |
|
|
||
| // Convert the message to a JSON string | ||
| std::string msgJsonString; | ||
| google::protobuf::json::PrintOptions options; |
There was a problem hiding this comment.
I'm getting a compilation error on Ubuntu Noble with libprotobuf-dev 3.21.12-8.2ubuntu0.2. I'm guessing this isn't available here. I do see an alternative always_print_primitive_fields.
/home/caguero/jetty_ws/src/gz-transport/example/plotjuggler/gz_pj_bridge.cc:102:23: error: ‘google::protobuf::json’ has not been declared
102 | google::protobuf::json::PrintOptions options;
| ^~~~
/home/caguero/jetty_ws/src/gz-transport/example/plotjuggler/gz_pj_bridge.cc:103:5: error: ‘options’ was not declared in this scope; did you mean ‘optind’?
103 | options.always_print_fields_with_no_presence = true;
| } | ||
|
|
||
| // Get a timestamp | ||
| double timestamp = std::chrono::duration<double>( |
There was a problem hiding this comment.
timestamp doesn't seem used.
| std::chrono::system_clock::now().time_since_epoch()) | ||
| .count(); | ||
|
|
||
| // Create the final JSON payload for PlotJuggler |
There was a problem hiding this comment.
Should we remove the commented block?
| std::cout << "[+] Subscribed: " << topic << " [" << msgType << "]" | ||
| << std::endl; | ||
| this->subscribedTopics.insert(topic); | ||
| this->topicToType[topic] = msgType; |
There was a problem hiding this comment.
I think there's a potential race condition accessing this->topicToType from this function and from OnMessage().
|
|
||
| public: void Run() | ||
| { | ||
| while (true) |
There was a problem hiding this comment.
It would be nice to replace this infinite loop with a while (running) { ... }, where running is declared as an std::atomic<bool>. We can install a signal handler (that will set running to false and allow graceful shutdown.
| pub(ctx, ZMQ_PUB) | ||
| { | ||
| // Bind ZMQ to port 9872 | ||
| this->pub.bind("tcp://*:9872"); |
There was a problem hiding this comment.
It'd be nice to make this port configurable from the command line.
| project(gz_pj_bridge) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
|
|
There was a problem hiding this comment.
Add set(CMAKE_CXX_STANDARD_REQUIRED ON) to force c++17 standard or error otherwise?
| } | ||
| } | ||
|
|
||
| private: gz::transport::Node node; |
There was a problem hiding this comment.
Nit: Add some doxygen doc and our ///////////////////////////////////////////////// delimiters for consistency.
🎉 New feature
Summary
Adds bridge from Gazebo to PlotJuggler that allows plotting any numerical topic from Gazebo. The bridge creates a generic subscriber, converts the protobuf data to json and republishes it over zeromq, which is a supported input source in PlotJuggler.
I was contemplating whether we should add this as subcommand of
gz, maybegz plot_juggler_bridge. How does that sound?Here's a plot of magnetometer sensor data
Test it
Included in the README
Checklist
codecheckpassed (See contributing)Generated-by: Gemini 2.5 Pro
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸