How to properly use ROS service
Right now, I got some array of geometry_msgs::Point (geometry_msgs::Point[]) by C++. Now I want to use some clustering algorithm implemented in python. I think ros service might be a good choice for different programming language communication, So I have included the clustering algorithm in the ROS server.
I am confused by the client node. I don't want to have a main function since I cannot save the result for later. Instead, I want to have a regular c++ function which the input parameters are the data (geometry_msgs::Point[]) and the return is results from clustering node.
Is there a proper way to do this? or any other options?
For example:
// e.g. return the clustering center for the data, this is the function I would like to write
std::vector<geometry_msgs::Point> functionUseClusterServer(std::vector<geometry_msgs::Point> data){
// call ROS server written by python
...
return result_from_server;
}
// I want that the functionUseClusterServer can be used in the main:
int main(int argc, chat** argv){
...
result = functionUseClusterServer(data);
something_else = otherFunction(result);
...
{
Every node must have a
main
function. It's a fundamental requirement of writing software in C++.Your question is not clear. What are you trying to do? What do you mean by "save the result for later", and "have a regular C++ function"?
I mean I would like to have a C++ function that returns the result from the "server". I don't want to use directly call the server in the main function. I am not sure if you can understand this. I have included the example in the problem description.
You could just create a C++ class on the node side and save the returned value from the server as a class variable.