ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A few things to note:

  • your trying to achieve a 1kHz loop rate with a Python script: not impossible, but certainly not the first combination of runtime environment and performance requirements I'd choose.
  • using parameters is always good (improves reusability of your code), but in this case for your service variable to be initialised you're incurring the overhead of communicating with the parameter server by using get_param(..) there. That's a full XML-RPC session setup, communication (ie: transmit and receive), (de)serialisation and teardown just to read a single parameter.
  • you don't appear to be using a persistent connection. That causes rospy to always do a full lookup and rebinding of the ServiceProxy upon invoking it. That is a lot of overhead as the network stack and multiple other nodes are involved (ie: service server and the master).

Finally: from this:

This all causes the one service call to result in about 4 ms of delay and I want to get my program to 1 ms precision.

I get two impressions:

  1. you're executing this piece of code in an inner / performance critical loop
  2. you're using services for something they are not really suited for

If my first impression is correct: don't do that. If you must, only invoke the already initialised (ie: bound) service call in your loop. The rest should be done in the initialisation phase of your script.

For the second: I would personally not use services for something like this, but that is of course your choice and would depend on many things we do not know.

A few things to note:

  • your trying to achieve a 1kHz loop rate with a Python script: not impossible, but certainly not the first combination of runtime environment and performance requirements I'd choose.choose. Have you considered the amount of jitter this is going to experience?
  • using parameters is always good (improves reusability of your code), but in this case for your service variable to be initialised you're incurring the overhead of communicating with the parameter server by using get_param(..) there. That's a full XML-RPC session setup, communication (ie: transmit and receive), (de)serialisation and teardown just to read a single parameter.
  • you don't appear to be using a persistent connection. That causes rospy to always do a full lookup and rebinding of the ServiceProxy upon invoking it. That is a lot of overhead as the network stack and multiple other nodes are involved (ie: service server and the master).

Finally: from this:

This all causes the one service call to result in about 4 ms of delay and I want to get my program to 1 ms precision.

I get two impressions:

  1. you're executing this piece of code in an inner / performance critical loop
  2. you're using services for something they are not really suited for

If my first impression is correct: don't do that. If you must, only invoke the already initialised (ie: bound) service call in your loop. The rest should be done in the initialisation phase of your script.

For the second: I would personally not use services for something like this, but that is of course your choice and would depend on many things we do not know.

A few things to note:

  • your trying to achieve a 1kHz loop rate with a Python script: not impossible, but certainly not the first combination of runtime environment and performance requirements I'd choose. Have you considered the amount of jitter this is going to experience?
  • using parameters is always good (improves reusability of your code), but in this case for your service variable to be initialised you're incurring the overhead of communicating with the parameter server by using get_param(..) there. That's a full XML-RPC session setup, communication (ie: transmit and receive), (de)serialisation and teardown just to read a single parameter.
  • you don't appear to be using a persistent connection. That causes rospy to always do a full lookup and rebinding of the ServiceProxy upon invoking it. That is a lot of overhead as the network stack and multiple other nodes are involved (ie: service server and the master).

Finally: And from this:

This all causes the one service call to result in about 4 ms of delay and I want to get my program to 1 ms precision.

I get two impressions:

  1. you're executing this piece of code in an inner / performance critical loop
  2. you're using services for something they are not really suited for

If my first impression is correct: don't do that. If you must, only invoke the already initialised (ie: bound) service call in your loop. The rest should be done in the initialisation phase of your script.

For the second: I would personally not use services for something like this, but that is of course your choice and would depend on many things we do not know.

Finally: in #q328017 you mention the word "real-time". You're most likely already aware, but a standard Python interpreter is not a deterministic runtime environment. rospy is incapable of deterministic execution, and the TCP/IP based communication system used is also non-deterministic. If "real-time" was meant to say "fast enough", then it's probably possible, but it won't be deterministic.

A few things to note:

  • your you're trying to achieve a 1kHz loop rate with a Python script: not impossible, but certainly not the first combination of runtime environment and performance requirements I'd choose. Have you considered the amount of jitter this is going to experience?
  • using parameters is always good (improves reusability of your code), but in this case for your service variable to be initialised you're incurring the overhead of communicating with the parameter server by using get_param(..) there. That's a full XML-RPC session setup, communication (ie: transmit and receive), (de)serialisation and teardown just to read a single parameter.
  • you don't appear to be using a persistent connection. That causes rospy to always do a full lookup and rebinding of the ServiceProxy upon invoking it. That is a lot of overhead as the network stack and multiple other nodes are involved (ie: service server and the master).

And from this:

This all causes the one service call to result in about 4 ms of delay and I want to get my program to 1 ms precision.

I get two impressions:

  1. you're executing this piece of code in an inner / performance critical loop
  2. you're using services for something they are not really suited for

If my first impression is correct: don't do that. If you must, only invoke the already initialised (ie: bound) service call in your loop. The rest should be done in the initialisation phase of your script.

For the second: I would personally not use services for something like this, but that is of course your choice and would depend on many things we do not know.

Finally: in #q328017 you mention the word "real-time". You're most likely already aware, but a standard Python interpreter is not a deterministic runtime environment. rospy is incapable of deterministic execution, and the TCP/IP based communication system used is also non-deterministic. If "real-time" was meant to say "fast enough", then it's probably possible, but it won't be deterministic.