Confusion about ROS2 parameters in MATLAB Coder
Show older comments
Hello everyone,
my confusion stems from the fact, that is seems not be possible to get array-valued parameters from a node. I use the following MWE-node which gets code generated with MATLAB Coder (codegen).
function myNode() %#codegen
nodeParams.gains = [0.5, 1.0, 2.0];
node = ros2node("/my_node", Parameters=nodeParams);
r = ros2rate(node, 10);
while true
[gains, ok] = getParameter(node, "gains", Datatype="double");
if ok
fprintf("First gain: %f\n", gains(1));
else
fprintf("Status is false\n");
end
waitfor(r);
end
end
This will successfully generate code, which can be compiled into a standlaone ROS2 node. Analyzing the node:
name@host:~/ros_ws$ ros2 param get /my_node gains
Double values are: [0.5, 1.0, 2.0]
Which means, that the parameter is set correct. But the node will repeatedly print:
Status is false
The code generation will also fail when actively trying to index into gains(2). I see from the Simulink-Coder documentation that there you are able to specify the datatype="double[]" which would make it clear that i want to read an array of doubles. But this is not allowed for the getParameter method. Does this mean, that it is simply not possible?
I am looking for some clarification on this topic, or possible workarounds. Thank you :)
Answers (0)
Categories
Find more on Specialized Messages in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!