Service callback never called with a custom interfaces using strings
Closed this issue · 8 comments
Service callback never called with a custom interfaces using strings
- Hardware description: ESP32
- RTOS: FreeRTOS
- Installation type: idf component
- Version or commit hash: humble
I made two custom interfaces, one typical AddThreeInts, and one ping :
The callback method in both cases looks like that :
void ping_callback(const void* request, void* response) {
ESP_LOGI(TAG, "Received ping request");
}
When I create the service using my AddThreeInts or the example AddTwoInts, the callback is called properly.
But when I use my ping interfaces, it never goes into the callback...
Steps to reproduce the issue
How I create the service :
// Create ping server with default config (Reliable QoS)
const rosidl_service_type_support_t* type_support =
ROSIDL_GET_SRV_TYPE_SUPPORT(ble2ros_interfaces, srv, Ping);
RCCHECK(rclc_service_init_default(&ping_srv, &node, type_support, ping_srv_name));
// Create executor
executor = rclc_executor_get_zero_initialized_executor();
RCCHECK(rclc_executor_init(&executor, &support.context, 4, &allocator));
// Add ping server to executor
RCCHECK(rclc_executor_add_service(
&executor,
&ping_srv,
&ping_req,
&ping_rsp,
ping_callback
));
Could you share the .srv
files of your custom interfaces?
Here is my Ping.srv from ble2ros_interfaces/srv (I have the package built and setup in ROS2 and in the extra_packages of the uROS component)
# Sends a ping to the BT Mesh provisioner
# Receives the response from provisioner
string ping
---
string pong
are you initializing the strings? https://micro.ros.org/docs/tutorials/advanced/handling_type_memory/
Not at all... Didn't think I had to do that but it makes sense.
If I understand correctly, I should use the automated memory handling from micro-ros-utilities ? And I can customize the string sizes using the micro_ros_utilities_memory_conf_t struct ?
And I must do it for both the request and response message ? The utility will know that those are service messages and do it automatically ?
You need to do it for both messages, req and res. You can assign memory directly or use the utilities. In the case that is a simple string, maybe is easier to assign memory manually. You have instructions for both approaches in the link above.
Please provide feedback so we can close this issue.
Works like a charm, thanks a lot ! I assigned memory directly like that : (writing it in case someone find this issue too)
// Initializing request and response msg
ping_req.ping.capacity = 100;
ping_req.ping.data = (char*) malloc(ping_req.ping.capacity * sizeof(char));
ping_rsp.pong.capacity = 100;
ping_rsp.pong.data = (char*) malloc(ping_rsp.pong.capacity * sizeof(char));
Quick last question, it doesn't appear possible to create two services with the ESP32, the second one always makes an error. I saw here :micro-ROS/micro_ros_arduino#442 that the Teensy only supports one services. Is it also the case with the ESP32 ? (If not I will probably look further into that or make another issue)
micro_ros_espidf_component/colcon.meta
Line 43 in f426aa2