[ROS2] Temporary clients & publishers, good or bad?
I have a controller node that will be sending and reading a lot of messages, services, and parameters in individual functions.
Can I create a temporary instance of a client, make a service call, set a callback, then destroy the client (optionally inside the callback)?
Is this bad practice?
My reasons are that I know Foxy have had problems with too many publishers, clients etc. and I don't want to create a lot of clients in my node, I'd rather have a closed of function that handles everything regarding that ro
Asked by Fubbis on 2023-06-15 04:41:03 UTC
Comments
Quick comment as I don't have any nrs to back this up: regardless of whether it's a bad practice or not, I would avoid (re)creating objects for which the initialisation comes with a non-zero cost. And for nodes, service clients etc the cost is non-zero. For service clients fi, there is a noticable time overhead where discovery is needed to find the server. You'd be incurring that overhead every time you (re)create the service client.
Only you know whether that'd be a problem for your application though. Perhaps it's perfectly OK, given the time it takes for the actual business logic to complete its task.
Asked by gvdhoorn on 2023-06-15 11:06:27 UTC