Calling a ros service function from another one
I am trying to find a way to call a service function from another one. To explain the situation, let's assume the following ROS messages and services:
# mypack/msg/MyRosMsg.msg
uint8 v1
# ... other definitions
# mypack/srv/MyRosSrv1.srv
mypack/MyRosMsg msg
# mypack/srv/MyRosSrv2.srv
mypack/MyRosMsg msg
# ... other definitions
I have a ROS service function as below:
bool my_service_1(mypack::MyRosSrv1::Request &req, mypack::MyRosSrv1::Response &req)
{
// do some processing
return(true);
}
and I want to call my_service_1
from the second service function by copying msg
member of MyRosSrv2
into MyRosSrv1
as below:
bool my_service_2(mypack::MyRosSrv2::Request &req, mypack::MyRosSrv2::Response &req)
{
mypack::MyRosSrv1 srv1;
srv1.msg = req.msg;
// how to call properly my_service_1?
}
Edit 1
Both service functions are inside one node. The service my_service_1
performs a processing that I am trying to avoid repeating the code in the service my_service_2
.
Edit 2 As tbh answered, the following changes is the trick to make it work:
bool my_service_2(mypack::MyRosSrv2::Request &req, mypack::MyRosSrv2::Response &req)
{
mypack::MyRosSrv1 srv1;
srv1.request.msg = req.msg;
my_service_1(srv1.request, srv1.response);
// do other processing
}
Does the standard way of calling a service not work out of my_service_2?
srv1.msg doesn't exist. You mean srv1.request.msg.