Service not responding with MultiThreadedExecutor executor
I'm attempting to create a service with the MultiThreadedExecutor executor
My goal is to eventually add call backs to a rclcpp::CallbackGroupType::MutuallyExclusive
callback group.
However, the service is never reached when I change the executor to MultiThreadedExecutor executor
.
It does work when I use rclcpp::spin(this);
auto callbackGroup = this->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
std::function<void(
const std::shared_ptr<interface::srv::Reader::Request> request,
std::shared_ptr<interface::srv::Reader::Response> response)> readerCallBack;
std::function<void(
const std::shared_ptr<interface::srv::Writer::Request> request,
std::shared_ptr<interface::srv::Writer::Response> response)> writerCallBack;
readerCallBack = bind(&service::readFrom,
std::placeholders::_1, // Corresponds to the 'request'
std::placeholders::_2, // Corresponds to the 'response'
file);
writerCallBack = bind(&service::writeTo,
std::placeholders::_1, // Corresponds to the 'request'
std::placeholders::_2, // Corresponds to the 'response'
file);
*reader = this->create_service<interface::srv::Reader>(
readerTopic,
readerCallBack,
rmw_qos_profile_services_default);
//create service to write/read to file
*writer = this->create_service<interface::srv::Writer>(
writerTopic,
writerCallBack,
rmw_qos_profile_services_default);
rclcpp::executors::MultiThreadedExecutor executor;
executor.add_node(this);
executor.spin(); //doesnt respond
//rclcpp::spin(this); //works
This seems to work:
rclcpp::executors::MultiThreadedExecutor executor;
executor.add_node(servicePtr->get_node_base_interface());
executor.spin();
However, it fails when I add the callback group:
*reader = this->create_service<interface::srv::Reader>(
readerTopic,
readerCallBack,
rmw_qos_profile_services_default,
callbackGroup);
//create service to write/read to file
*writer = this->create_service<interface::srv::Writer>(
writerTopic,
writerCallBack,
rmw_qos_profile_services_default,
callbackGroup);