Ask Your Question

Revision history [back]

ROS code optimization

Hi, I would like to ask you which are the best practices for creating optimized ROS projects.

I have some situations for which I'm not able to figure out what could be the best implementation (from a computational point of view). For each I have individuated some solutions, but maybe none of them is the correct one. I'm using ROS2 bouncy, but I think the issues applies to ROS1 as well.

A node computes data A and B. Then other nodes want to access this data through subscriptions or client requests. Some nodes require only A, some nodes only B and some nodes both data. How should be this data provided to other nodes?

  1. create two different publishers/services (one for A and one for B)
  2. create a message which contains both A and B and use only one publisher/service (even if some recipients will only use part of the message)

A process requires once in a while a continuous stream of sensors data for a relatively short amount of time (e.g. once every 3 minutes for 10 seconds at a 5Hz frequency). What's the best ways for accessing this data?

  1. creating a subscriber at startup and spinning only when the data is required.
  2. creating a subscriber every time data are required and then letting it go out of scope to unsubscribe
  3. use a service

Several functions (non methods, i.e. they are not part of a class) needs to access to some data through subscription/client requests. There are more functions than topics/services (e.g. 10 functions, 3 topics, 3 services); not all the functions needs all the available data (e.g. function A subscribes only to topic A and make requests to service A and B); there are not 2 functions running at the same time. What's the best way for accessing these data?

  1. each function has its own node and subscribers/clients (all global variables) initialized at the first function call
  2. there is only one node common to all functions, each function has its own subscribers/clients
  3. there is only one node with a subscriber/client for each available data

Thank you a lot

ROS code optimization

Hi, I would like to ask you which are the best practices for creating optimized ROS projects.

I have some situations for which I'm not able to figure out what could be the best implementation (from a computational point of view). For each I have individuated some solutions, but maybe none of them is the correct one. I'm using ROS2 bouncy, but I think the issues applies to ROS1 as well.

A node computes data A and B. Then other nodes want to access this data through subscriptions or client requests. Some nodes require only A, some nodes only B and some nodes both data. How should be this data provided to other nodes?

  1. create two different publishers/services (one for A and one for B)
  2. create a message which contains both A and B and use only one publisher/service (even if some recipients will only use part of the message)

A process requires once in a while a continuous stream of sensors data for a relatively short amount of time (e.g. once every 3 minutes for 10 seconds at a 5Hz frequency). What's the best ways for accessing this data?

  1. creating a subscriber at startup and spinning only when the data is required.
  2. creating a subscriber every time data are required and then letting it go out of scope to unsubscribe
  3. use a service

Several functions (non methods, i.e. they are not part of a class) needs to access to some data through subscription/client requests. There are more functions than topics/services (e.g. 10 functions, 3 topics, 3 services); not all the functions needs all the available data (e.g. function A subscribes only to topic A and make requests to service A and B); there are not 2 functions running at the same time. What's the best way for accessing these data?

  1. each function has its own node and subscribers/clients (all global variables) initialized at the first function call
  2. there is only one node common to all functions, each function has its own subscribers/clients
  3. there is only one node with a subscriber/client for each available data

Thank you a lot

ROS code optimizationBest practices for optimized data transmission

Hi, I would like to ask you which are the best practices for creating optimized ROS projects.

I have some situations for which I'm not able to figure out what could be the best implementation (from a computational point of view). For each I have individuated some solutions, but maybe none of them is the correct one. I'm using ROS2 bouncy, but I think the issues applies to ROS1 as well.

A node computes data A and B. Then other nodes want to access this data through subscriptions or client requests. Some nodes require only A, some nodes only B and some nodes both data. How should be this data provided to other nodes?

  1. create two different publishers/services (one for A and one for B)
  2. create a message which contains both A and B and use only one publisher/service (even if some recipients will only use part of the message)

A process requires once in a while a continuous stream of sensors data for a relatively short amount of time (e.g. once every 3 minutes for 10 seconds at a 5Hz frequency). What's the best ways for accessing this data?

  1. creating a subscriber at startup and spinning only when the data is required.
  2. creating a subscriber every time data are required and then letting it go out of scope to unsubscribe
  3. use a service

Several functions (non methods, i.e. they are not part of a class) needs to access to some data through subscription/client requests. There are more functions than topics/services (e.g. 10 functions, 3 topics, 3 services); not all the functions needs all the available data (e.g. function A subscribes only to topic A and make requests to service A and B); there are not 2 functions running at the same time. What's the best way for accessing these data?

  1. each function has its own node and subscribers/clients (all global variables) initialized at the first function call
  2. there is only one node common to all functions, each function has its own subscribers/clients
  3. there is only one node with a subscriber/client for each available data

How does this last answer change if we have only subscribers or only clients?

Thank you a lot

Best practices for optimized data transmission

Hi, I would like to ask you which are the best practices for creating optimized ROS projects.

I have some situations for which I'm not able to figure out what could be the best implementation (from a computational point of view). For each I have individuated some solutions, but maybe none of them is the correct one. I'm using ROS2 bouncy, but I think the issues applies to ROS1 as well.

A node computes data A and B. Then other nodes want to access this data through subscriptions or client requests. Some nodes require only A, some nodes only B and some nodes both data. How should be this data provided to other nodes?

  1. create two different publishers/services (one for A and one for B)
  2. create a message which contains both A and B and use only one publisher/service (even if some recipients will only use part of the message)

A process requires once in a while a continuous stream of sensors data for a relatively short amount of time (e.g. once every 3 minutes for 10 seconds at a 5Hz frequency). What's the best ways for accessing this data?

  1. creating a subscriber at startup and spinning only when the data is required.
  2. creating a subscriber every time data are required and then letting it go out of scope to unsubscribe
  3. use a service

Several functions (non methods, i.e. they are not part of a class) needs to access to some data through subscription/client requests. There are more functions than topics/services (e.g. 10 functions, 3 topics, 3 services); not all the functions needs all the available data (e.g. function A subscribes only to topic A and make requests to service A and B); there are not 2 functions running at the same time. What's the best way for accessing these data?

  1. each function has its own node and subscribers/clients (all global variables) initialized at the first function call
  2. there is only one node common to all functions, each function has its own subscribers/clients
  3. there is only one node with a subscriber/client for each available data

How does this last answer change if we have only subscribers or only clients?

Thank you a lot

Best practices for optimized data transmission

Hi, I would like to ask you which are the best practices for creating optimized ROS projects.

I have some situations for which I'm not able to figure out what could be the best implementation (from a computational point of view). For each I have individuated some solutions, but maybe none of them is the correct one. I'm using ROS2 bouncy, but I think the issues applies to ROS1 as well.

A node computes data A and B. Then other nodes want to access this data through subscriptions or client requests. Some nodes require only A, some nodes only B and some nodes both data. How should be this data provided to other nodes?

  1. create two different publishers/services (one for A and one for B)
  2. create a message which contains both A and B and use only one publisher/service (even if some recipients will only use part of the message)

A process requires once in a while a continuous stream of sensors data for a relatively short amount of time (e.g. once every 3 minutes for 10 seconds at a 5Hz frequency). What's the best ways for accessing this data?

  1. creating a subscriber at startup and spinning only when the data is required.
  2. creating a subscriber every time data are required and then letting it go out of scope to unsubscribe
  3. use a service

Several functions (non methods, i.e. they are not part of a class) needs to access to some data through subscription/client requests. There are more functions than topics/services (e.g. 10 functions, 3 topics, 3 services); not all the functions needs all the available data (e.g. function A subscribes only to topic A and make requests to service A and B); there are not requests.

    void f1()
    {
        auto response1 = ... client 1 request ...
        cout << response1->data <<endl;
    }

    void f2()
    {
        auto response2 = ... client 2 functions running at the same time. request ...
        cout << response2->data <<endl;
    }

    void f3()
    {
        auto response1 = ... client 1 request ...
        auto response2 = ... client 2 request ...
        cout << response1->data << " " << response2->data <<endl;
    }

What's the best way for accessing implementing the node and the subscribers/clients for these data?functions ? There is a noticeable difference in performances between the different solutions when the number of functions/nodes/topics increases ?

  1. each function has its own node and subscribers/clients (all global variables) initialized at the first function call
  2. there is only one node common to all functions, each function has its own subscribers/clients
  3. there is only one node with a subscriber/client for each available data

How does this last answer change if we have only subscribers or only clients?

Thank you a lot

Best practices for optimized data transmission

Hi, I would like to ask you which are the best practices for creating optimized ROS projects.

I have some situations for which I'm not able to figure out what could be the best implementation (from a computational point of view). For each I have individuated some solutions, but maybe none of them is the correct one. I'm using ROS2 bouncy, but I think the issues applies to ROS1 as well.

A well. I have some nodes which publish sensor data and many other nodes which require only the data coming from specific sensors. There are different threads, some nodes are on the same thread. All sensors data are published more or less at the same frequency.

One node computes provides data A and B. Then other nodes want to access this data through subscriptions or client requests. Some nodes require only A, some nodes only B and some nodes both data.

    void f1()
    {
        auto dataA = ... coming from subscription/client to dataA ...
        cout << dataA <<endl;
    }

    void f2()
    {
        auto dataB = ... coming from subscription/client to dataB ...
        cout << dataB <<endl;
    }

    void f3()
    {
        auto dataA = ... coming from subscription/client to dataA ...
        auto dataB = ... coming from subscription/client to dataB ...
        cout << dataA<< " " << dataB <<endl;
    }

How should this data be this data provided to other nodes?by the first node?

  1. create two different separate publishers/services (one for A and one for B)
  2. create a message which contains both A and B and use only one B, to provide it through a unique publisher/service (even if some recipients will only use part of the message)

A process requires once in a while a continuous stream of sensors data for a relatively short amount of time (e.g. once every 3 minutes for 10 seconds at a 5Hz frequency). What's the best ways for accessing this data?

  1. creating a subscriber at startup and spinning only when the data is required.
  2. creating a subscriber every time data How should the functions use the subscription/client API ? Note that they are required and then letting it go out of scope to unsubscribe
  3. use a service

Several all non method functions (non methods, i.e. (i.e. they are not part of a class) needs to access to some data through subscription/client requests.

    void f1()
    {
        auto response1 = ... client 1 request ...
        cout << response1->data <<endl;
    }

    void f2()
    {
        auto response2 = ... client 2 request ...
        cout << response2->data <<endl;
    }

    void f3()
    {
        auto response1 = ... client 1 request ...
        auto response2 = ... client 2 request ...
        cout << response1->data << " " << response2->data <<endl;
    }

What's the best way for implementing the node and the subscribers/clients for these functions ? There is a noticeable difference in performances between the different solutions when the number of functions/nodes/topics increases ?class)

  1. each function has its own node and subscribers/clients (all global variables) initialized at the first function call
  2. there is only one node common to all functions, each function has its own subscribers/clients
  3. there is only one node with a subscriber/client for each available data

How does A process requires once in a while a continuous stream of sensors data for a relatively short amount of time.

    void f_loop()
    {
        while(1){

             sleep(5 minutes);
             start_time = time;
             while (time <= start_time + 15 seconds){

                   auto response1 = ... client 1 request ...
                   cout << response1->data <<endl;
      } } }

What's the best ways for accessing this last answer change if we have data?

  1. creating a subscriber at startup and spinning only subscribers or only clients?

    when the data is required.
  2. creating a subscriber every time data are required and then letting it go out of scope to unsubscribe
  3. use a service

Thank you a lot