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

Add ROS2 support for calling server-advertised services #142

Merged
merged 8 commits into from
Feb 7, 2023

Conversation

achim-k
Copy link
Collaborator

@achim-k achim-k commented Jan 26, 2023

Public-Facing Changes

  • Add ROS2 support for calling server-advertised services

Description
Based on #136

Implementation details:

The main problem is, that symbols from getting the service type support are missing from the rosidl_typesupport_cpp libraries that are generated for each msg/srv package (see ros2/rosidl_typesupport#122). There is an open pull request (ros2/rosidl_typesupport#114) to fix that, but so far it hasn't been merged.

I found a working, yet little bit hacky, workaround for this problem which is described more in detail here:

/**
* The default symbol names for getting type support handles for services are missing from the
* rosidl_typesupport_cpp shared libraries, see
* https://github.com/ros2/rosidl_typesupport/issues/122
*
* We can however, as a (hacky) workaround, use other symbols defined in the shared library.
* With `nm -C -D /opt/ros/humble/lib/libtest_msgs__rosidl_typesupport_cpp.so` we see that there is
* `rosidl_service_type_support_t const*
* rosidl_typesupport_cpp::get_service_type_support_handle<test_msgs::srv::BasicTypes>()` which
* mangled becomes
* `_ZN22rosidl_typesupport_cpp31get_service_type_support_handleIN9test_msgs3srv10BasicTypesEEEPK29rosidl_service_type_support_tv`
* This is the same for galactic, humble and rolling (tested with gcc / clang)
*
* This function produces the mangled symbol name for a given service type.
*
* \param[in] serviceType The service type, e.g. "test_msgs/srv/BasicTypes"
* \return Symbol name for getting the service type support handle
*/
std::string getServiceTypeSupportHandleSymbolName(const std::string& serviceType) {
const auto [pkgName, middleModule, typeName] = extract_type_identifier(serviceType);
const auto lengthPrefixedString = [](const std::string& s) {
return std::to_string(s.size()) + s;
};
return "_ZN" + lengthPrefixedString(TYPESUPPORT_LIB_NAME) +
lengthPrefixedString("get_service_type_support_handle") + "IN" +
lengthPrefixedString(pkgName) +
lengthPrefixedString(middleModule.empty() ? "srv" : middleModule) +
lengthPrefixedString(typeName) + "EEEPK" +
lengthPrefixedString("rosidl_service_type_support_t") + "v";
}

All in all, the implementation is working, but I would consider it as experimental for now. I am not sure if this approach would work on windows / mac

Base automatically changed from achim/services to main February 7, 2023 17:33
achim-k added a commit that referenced this pull request Feb 7, 2023
**Public-Facing Changes**
- Add ROS1 support for calling server-advertised services

**Description**
- Adds ROS1 support for advertising/unadvertising services and allowing
clients to call them
- Implements the services spec that was added in
foxglove/ws-protocol#344

Implementation details:
- The service type is unfortunately not stored on the ROS master, so for
every new service, a connection to the service server has to be opened
to fetch the service type from the connection header
- For ROS1, one can call services with a custom type (here
`GenericService`) when one defines the `ros::service_traits` and
`ros::serialization` traits


Fixes #10 (together with #142)
@achim-k achim-k merged commit 8e08af0 into main Feb 7, 2023
@achim-k achim-k deleted the achim/services_ros2 branch February 7, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants