Max frequency to look up parameters
I'm in the early stages of building the brains of my robot and have a question about best practices. The nodes that I'm working on have certain values that will change frequently during tuning, so they're stored in the parameter server.
In the case of my joystick teleop node, every Joy message uses some scale to determine outputs but if you called getparam for every message, I'm assuming you'd overload the server, given they'll be received multiple times per second. It's the same story for other nodes so I came up with multiple solutions that I'm hoping others have already figured out, and can provide feedback (using the teleop node as an example)
- Call getParam to look up the scale values with each message (not recommended, could overload server)
- Call getCached in each message (tutorial seems to suggest this isn't a good idea either, as it has more overhead)
- Load parameters when the node starts (good, but requires resetting the node to update values)
- Load parameters at start, but also include an empty service that updates the values while the node is running (useful for complex nodes, like PID controllers)
At the moment my more advanced nodes are using #4. Is there another solution I've missed, or perhaps a generally accepted retrieval rate for given hardware?
How are those parameters changed? If you change them by hand have a look at dynamic reconfigure. This will call a callback function in your node each time a parameter is changed in the dynamic reconfigure rqt plugin.
Which tutorial suggest that getCachedParam has more overhead? In what way more overhead?
On the page about the parameter server, it says "Cached parameters are a significant speed increase (after the first call), but should be used sparingly to avoid overloading the master." I'm not sure why it overloads, though
This is a warning about overusing parameters. You don't want to use parameters for all local variables and store them all on the parameter server. Any individual cached parameter is not going to overload the parameter server, but if everything goes through the paremeter server it will not scale.
Did some testing. I called rospy.get_param() at 100Hz. It added around 9% of CPU usage which is A LOT. Knowing this I can confirm that using parameter server for in-loop updates is very inefficient and should never be used. Parameter server is only for initialization. For frequent updates I would use latched topics instead.