How to achieve "Get parameters" in simulink with ROS2?
10 views (last 30 days)
I'm now modifying Simulink ROS1 blocks to ROS2. But there are no "Get paramaters" blocks in ROS2 toolbox.
What I found is to use the "Call service'' block, and the structure I built is shown in picture.
I don't konw how to input the parameter name to let the simulink tell ROS2 which paramater I want to know, the names in the bus assignment are "names" and "names.data". But I don't konw which block I should use to set as input.
Could you please maybe give me an example?
Cam Salzberger on 19 Jan 2022
Parameters are not yet available for use with ROS 2 in MATLAB or Simulink. They are on our radar as we work to bring ROS 2 up to feature-parity with ROS, but are not yet in the toolbox.
Unfortunately, there isn't really a workaround to access parameters using other techniques in MATLAB alone. There are a couple of ways I can think of to access parameters, or have a parameter-like feature:
One works if the parameters are not expected to be modified external to a node. You can have a publisher that serves a simliar function to your parameter server on each node. Its message is just a list of parameter names and values. It only needs to publish once (or any time the parameter values change), but should use the value "Transient Local" for the "Durability" and a value of 1 for the "Depth" Quality of Service settings. Then when you need the parameter values, you can create a subscriber (also with Transient Local), and it will receive the most recently published message on that topic.
Another way would be to create a service server to act as the parameter server in ROS code outside of MATLAB. You could create it so that the request message provides the name of the parameter to get (or name and value to set, and indicates which it wants to do), and the response contains the current value. It would simply be querying the real parameter server under the hood, but this would depend on you having ROS installed on your system outside of MATLAB.