ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Using tf2 in ROS2 with pure C?

asked 2021-05-27 08:13:58 -0600

amosteo gravatar image

This is from the context of a client library that relies on rcl, but I guess it would apply to anyone trying to program only in C. My current version is foxy.

I'm looking to provide a binding to tf2, at least partially. I can successfully transform single points by means of copying the data to a Vector3Stamped. This does not seem however very efficient or generalizable if one wants to transform larger/arbitrary messages. So my questions are:

1) Is there any provision or expectation for using tf2 without C++/Python?

2) My understanding is that the C and C++ typesupports aren't compatible, in the sense that I cannot cast a pointer to a C message into the equivalent C++ message, to transform it in a thin layer of C++ and back. Is this correct?

3) Finally, assuming there's no way around using C++ with C++ typesupports, what do you think would be the simplest/most efficient way of achieving transformations of large/new messages? Wrapping the C messages in a C++ type with toMsg/fromMsg functions? Would that inevitably involve copying the data?

Thanks for any guidance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-05-27 14:14:21 -0600

tfoote gravatar image

It sounds like you're operating on large data that's in a custom C structure. To that end like with c++ I would recommend using the best linear math library for your datatype. And you can just query tf2 for the transform and then convert the transform value to your native type which will operate efficiently on your datatype without requiring a conversion.

The direct transform methods for messages and other specific datatypes like Eigen and KDL are designed as helper functions and are not necessary if you are working in some other system. Just use lookupTransform get the data out and use your C library for manipulating your data.

If you're ok with some latency you could implement a tf2 buffer client interface in pure C and query a remote tf2 buffer too. But I only recommend that when you know you are looking for a slow frequency query that's ok with larger latency.

edit flag offensive delete link more

Comments

Thanks for the feedback, @tfoote, this clarifies things for me. I'm actually not bound to a specific system, at this time I'm just trying to provide similar facilities as these found in tf2/tf2_ros to users of my client library, when using geometry_msgs.

amosteo gravatar image amosteo  ( 2021-05-31 10:17:36 -0600 )edit

I would recommend looking at some pure C linear math libraries to integrate which will provide more functionality and higher performance than building out custom infrastructure for the message datatypes. The integration with one of these will both improve the experience for doing transforms and also help leverage it by enabling the more advanced functions through the interoperability of datatypes and not needing to do conversions to use the other methods in the libraries.

tfoote gravatar image tfoote  ( 2021-06-02 12:18:56 -0600 )edit

Do you know of any C lib that you would recommend or that is already among the ROS2 packages? Thanks.

amosteo gravatar image amosteo  ( 2021-06-06 04:50:45 -0600 )edit

Question Tools

4 followers

Stats

Asked: 2021-05-27 08:13:58 -0600

Seen: 300 times

Last updated: May 27 '21