Skip to content
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

JSON support to achieve full integration with non-ROS devices for arbitrary ROS message types #51

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ahmad-ra
Copy link

This PR integrates functionality for a full communication with other (non-mqtt_client) MQTT clients. Unlike the current feature of exchanging primitive messages, this feature allows ROS-based devices to exchange arbitrary messages with devices not based on ROS. It works in both directions, where a non-ROS-based device can send a JSON string that will be casted into a ROS message in runtime.

The PR is based on my updates to ros_msg_parser package that uses shapeshifter to provide type introspection in ROS, my contribution was to update the parser class to convert a JSON string into a serialized ROS message, achieving bi-directional parsing capabilities between JSON <-> ROS-msg.

The README is updated to explain the new functionality, and its demo and technical details are added in the corresponding sections.

This PR should close #9 and set the ground ready for working on #18.

  • Subscribe any (non-ROS-based) MQTT message and publish it as a ROS message.
  • Subscribe any ROS message and publish it as a JSON string payload through MQTT, ready to be interpreted by other MQTT clients.

@lreiher
Copy link
Member

lreiher commented Feb 27, 2024

Hi, sorry for the delayed response!

Awesome addition to the mqtt_client, thank you very very much! I will try to test it out soon.

Meanwhile, I have seen that ros_msg_parser has been archived, see here. Do you already have plans to port it over to rosx_introspection? I guess the merge here will have to wait until the feature is implemented there?

@ahmad-ra
Copy link
Author

ahmad-ra commented Mar 3, 2024

Hi again!

Actually the ros_msg_parser got archived just after my PR there :D, as previously it seemed to me an old package that works, but now yes it must be ported, you can see by comparing the date of that PR with the last commit that archived the repo.

I recently started working on porting to rosx_introspection and it is done now.
Now the updates are even better!, since this PR originally was adding JSON support only to ROS, but now it includes support for ROS2 as well.

I still didn't have time to test ROS2 support, so if you can confirm tests working for both ROS and ROS2 it would be great.

You can check my PR on rosx_introspection, where my fork can be cloned for testing until it gets merged upstream.

@ahmad-ra
Copy link
Author

status_update: ROS2 support is now fixed and tested working!

The problem was (in addition to coding errors) that ROS2 message serialization procedure is different from ROS1
Now everything is tested.

@fate4gle
Copy link

fate4gle commented Mar 29, 2024

Hi,
Thank you for your efforts in creating the JSON integration for the mqtt_client! It will be a super valuable tool for many of us out there!
I am currently trying to get your JSON integration on ROS noetic (Ubuntu 20.4) running.
Perhaps this is my mistake but I believe there is an issue with your mqtt_client.hpp and the rosx_introspection package. In line 553 it calls the "deserializeIntoJson" function and in line 726 the "serializeFromJson" function, both of which are not part of the rosx_introspection package but they are available in the previous ros_msg_parser package which was archived.
Did you perhaps modify something in the rosx_intropection package?

Keep up the good work!

@ahmad-ra
Copy link
Author

ahmad-ra commented Apr 2, 2024

Hello

Thank you for your nice comments.

I would double check that you are specifically pulling my fork of rosx_introspection, and building it properly by creating a build subdirectory and doing cmake

@fate4gle
Copy link

fate4gle commented Apr 3, 2024

Thank you for your support. I could get everything up and running, I did not realize that I mixed up your fork with the original one... sight
It works perfectly now! I hope your work gets included quickly!

@lreiher
Copy link
Member

lreiher commented Apr 11, 2024

Hi,

again thank you very much for the great effort!

I have tried to get the ROS2 version running for some quick tests, but encountered a few issues. Here's what I tried:

  • enter a ghcr.io/ika-rwth-aachen/mqtt_client:ros2 Docker container that includes the currently released mqtt_client (and all its dependencies)
  • remove the install space inside the container, cause we need to rebuild your version from source
  • clone your mqtt_client and rosx_introspection forks into a workspace
  • run rosdep install --ignore-src --from-paths src to check for any missing dependencies
  • run colcon build
  • first error: have to manually clone rapidjson and place its include folder in the include folder of rosx_introspection
  • run colcon build again
Starting >>> mqtt_client_interfaces
Starting >>> rosx_introspection
Finished <<< mqtt_client_interfaces [14.9s]
Starting >>> mqtt_client
Finished <<< rosx_introspection [18.9s]
--- stderr: mqtt_client
gmake[2]: *** No rule to make target '/docker-ros/ws/src/mqtt_client/mqtt_client/../../rosx_introspection/include/../build/librosx_introspection.a', needed by 'libmqtt_client_lib.so'.  Stop.
gmake[2]: *** Waiting for unfinished jobs....
gmake[1]: *** [CMakeFiles/Makefile2:139: CMakeFiles/mqtt_client_lib.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< mqtt_client [14.3s, exited with code 2]

Summary: 2 packages finished [29.4s]
  1 package failed: mqtt_client
  1 package had stderr output: mqtt_client

Perhaps you can help out? Could you provide a working container-based setup?

@ahmad-ra
Copy link
Author

Hello,

I just would like to make sure about something that wasn't explicitly mentioned in your steps.

rosx_introspection should also be manually built using cmake, since it is linked as a static library that is compiled inside the workspace, I preferred to have everything containerized inside the workspace rather than installing it as a system library (that is the reason for the convoluted .a target location it was searching for)

Does it not work even after doing cd $WS_PATH/rosx_introspection && mkdir build && cd build && cmake .. && make?

As for rapidjson, you are right, as for me I had it already in my system include path. I will check that and add it inside the directories of rosx_introspection.

@lreiher
Copy link
Member

lreiher commented Apr 12, 2024

Thank you, first building rosx_introspection using cmake made it work on ROS 2. Very nice, I was able to both publish and receive JSON message using mosquitto_sub / mosquitto_pub.

I didn't manage though to quickly test in ROS 1. Looks like fastcdr must be installed, which I didn't get working in the couple of minutes that I tried.


I'm not sure how we should proceed at this point. While I think it is a great feature, I'm leaning towards not conducting a through review and not merging right now. This implementation depends on changes to rosx_introspection, so those should be merged first. Also, mqtt_client is officially released to the ROS repositories, so I would only merge this, if I could also guarantee a seamless installation of everything (including rosx_introspection) via apt install ros-humble-mqtt-client.

This doesn't stop anyone from using the feature with your forks though! :)

@fate4gle
Copy link

fate4gle commented Apr 12, 2024

@lreiher @ahmad-ra I do agree that in an ideal world the rosx_introspection should be easier to be installed using the simple apt install method. However, besides the FastCDR library I believe, with a little bit of explanation is not too difficult to install. In the end, the extra steps are not too many. As for FastCDR, it is a bit more tricky, if possible it should be included as a 3rd party (perhaps it is and I am too new to ROS to understand) and make it easier to install. Nevertheless as a newbie to ROS and Linux I was able to get everything running within a bit of time. I believe some more guidance in the README.md will be sufficient.

@lreiher I ended up installing FastCDR globally which requires a cmake update to 3.20 (or later) for ROS1 (noetic). I do agree that things could be easier to get running but this is a first step towards it. At this point I am just happy to have it running. And, oh boy, it is stable:)

…kage, rather than a static lib built with cmake
@ahmad-ra
Copy link
Author

ahmad-ra commented Apr 13, 2024

I totally agree with @fate4gle that this is the first step towards the goal, since the changes done are not small, and it has to start somewhere, then gradually get better in terms of easier usage, and that the Readme should be updated with better instructions.

I also agree with @lreiher that streamlining the process is important to release it, so I think we can move forward some steps towards having an easier installation, to not leave the work half-done, and to see the fruitful result of the efforts where the feature will be useful to many others. In this regard, my latest commit removed the need to manually build rosx_introspection, but it is now normally built using catkin or colcon as a ROS package. I also included rapidjson in the include directory so that it won't give problems.

Regarding fastcdr, I am a bit confused since it didn't give any problems building on my machine (and I thought the reason was that rosx_introspection installed it for me during its building process), but looks like it was problem for both of you. Maybe it should be noted in the Readme to be installed from the official guide before building mqtt_client?

Regarding the changes to rosx_introspection, the repo itself was developed to provide introspection capabilities, and do things like a generic subscriber, not to parse a message between different formats, so one would understandably argue that my edits are an extra layer to the repo, not serving its original purpose but serving a different goal, where one can argue it shouldn't be merged. I even nearly totally changed its CMakeLists in the last commit, which probably doesn't make much sense to merge as it changes the build process from the vanilla cmake. That is why I think we shouldn't wait for the merges there, but consider testing for our specific use case and merging if it is working for us.

@ignasimUPC
Copy link

ignasimUPC commented Apr 26, 2024

Hello,

First of all, thank you all for your effort in this utility. I want to report that, when using this PR, an issue arises.

Issue:
it works well for a lot of messages types, but not for navsatfix msgs. I get the following:

[mqtt_client-1] terminate called after throwing an instance of 'eprosima::fastcdr::exception::NotEnoughMemoryException'
[mqtt_client-1] what(): Not enough memory in the buffer stream
[ERROR] [mqtt_client-1]: process has died

You can reproduce this error easily launching the mqtt_client with custom params and doing in another terminal:

ros2 topic pub /ping/ros sensor_msgs/NavSatFix '{header: {stamp: {sec: 1625092073, nanosec: 123456789}, frame_id: "base_link"}, latitude: 41.123, longitude: 2.456, altitude: 100.0}'

@lars-nagel
Copy link

Hi there!
Are there any updates regarding this PR? It introduces a super useful functionality!!

@lreiher
Copy link
Member

lreiher commented Jul 5, 2024

The main problem that I see right now is the official release process to the ROS package indices. For sure, people could clone mqtt_client, clone the rosx_introspection fork and build the feature themselves. But mqtt_client is also released as an official ROS package, such that people can apt install ros-$ROS_DISTRO-mqtt-client.

As long as the changes to rosx_introspection have not been officially released, I cannot release mqtt_client with dependencies to a newer version of rosx_introspection. It would break the apt-installable version of mqtt_client.

This is also the main reason that I have been reluctant with conducting a thorough code review right now. I would postpone that until a release becomes feasible.

What I could offer is:

  • Someone adds instructions to the README to this branch to build mqtt_client and its dependencies, incl. the rosx_introspection fork, from source.
  • Someone creates a separate PR to only modify the main README, where you mention the feature and how it's currently only available from source by checking out the fork.
  • I could then merge this PR with the README change. This would at least give the feature and the fork more visibility in the meantime.

@chanhhoang99
Copy link

chanhhoang99 commented Jul 6, 2024

Hello there,
Thanks for the introduction of the nice feature.
Unfortunately I am not able to build it.
I use the latest fork from https://github.com/ahmad-ra/mqtt_client/tree/main and https://github.com/ahmad-ra/rosx_introspection/tree/master
Then go to ${WS}/rosx_introspection then run mkdir build && cd build && cmake .. && make
After that run colcol build
However I encountered below error:
Could not find a package configuration file provided by "rosx_introspection" with any of the following names: rosx_introspectionConfig.cmake rosx_introspection-config.cmake

Could you give me hints ?

@LuCarpentier92
Copy link

Hello there, Thanks for the introduction of the nice feature. Unfortunately I am not able to build it. I use the latest fork from https://github.com/ahmad-ra/mqtt_client/tree/main and https://github.com/ahmad-ra/rosx_introspection/tree/master Then go to ${WS}/rosx_introspection then run mkdir build && cd build && cmake .. && make After that run colcol build However I encountered below error: Could not find a package configuration file provided by "rosx_introspection" with any of the following names: rosx_introspectionConfig.cmake rosx_introspection-config.cmake

Could you give me hints ?

Hello,

I’m facing the same issue with the rosx_introspection package. I get the error about missing rosx_introspectionConfig.cmake rosx_introspection-config.cmake after running catkin_make.

Any clues for this issues ?

@chanhhoang99
Copy link

@LuCarpentier92 no luck, i switch to mqtt_bridge and wait for this PR to be developed in futureand hope the auther will give us some update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Send messages as JSON to generic MQTT clients
7 participants