How to achieve "Get parameters" in simulink with ROS2?

6 views (last 30 days)
Hello!
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?
Thanks!

Answers (1)

Cam Salzberger
Cam Salzberger on 19 Jan 2022
Hello Xiaochen,
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.
-Cam
  1 Comment
Michael
Michael on 31 May 2022
@Cam Salzberger Do you have any idea if R2022b is going to support ROS2 parameters? I can see your message is from January. I doubt you can discuss coming releases, but I'd rather not spend time implementing one of the above solutions if ros2 parameter support is going to come out in the R2022b prerelease. We a can implement some manual parameter set/get methods as you discussed, but these will likely be unnecessary as soon as parameters are supported. What is worse, is that a ros node generated in Matlab and deployed using Coder can't accept any input arguments, so I can't even pass it a path to a configuration file to set variables in my node once at start up. For this reason, it seems like every variable in the node has to be hard coded in my Matlab function currently. Am I missing something? This seems like a major hole in the current ROS2 support that I hope is plugged soon.
To be clear, it is incredible that I can build my code in Matlab and deploy to a standalone target with coder. I don't want to seem like I am complaining. I just love the tool and want it to have this feature asap!

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!