How to assign a callback_group to a Service Server in C++

Hi,
I am working on the Wall Follower rosject - Part 2. My question is about how to assign a callback group to a Service Server.

callback_group =this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
find_wall_srv = create_service<FindWall>("find_wall", std::bind(&WallFinderNode::wall_finder_srv_callback, this, _1, _2), callback_group);

I get an error while compiling the previous code related to the callback_group and the Server.

Thaks in advance
Ronaldo

Hi @w.ronaldo.cd ,

Here is a quick code snippet of how you can assign a callback group to a service server.

service_cbg = create_callback_group(rclcpp::CallbackGroupType::Reentrant);
server = create_service<FindWall>(
    "/find_wall",
    std::bind(&ServiceServer::service_callback, this,
              std::placeholders::_1, std::placeholders::_2),
    rmw_qos_profile_services_default, service_cbg);

This should work. Let me know if this does not work for you.

Regards,
Girish

Thank you Girish, it works.

Hi @w.ronaldo.cd ,

Please mark the corresponding post as “Solution” so this issue can be closed.

Regards,
Girish