ROS2 Message Received Callback for Code Generation
显示 更早的评论
The Question
I'm trying to receive messages on a ROS2 network and exectute a callback function when messages are received. I need to deploy this with Code Generation to a C++ executable. When I run my code below in Matlab I get no errors, but when I try code generation I get the error show at the end of this question. I have included a simplified code and the script I used to deploy this code to my target machine. Any idea what the problem is? It seems there is an issue with the inputs to the callback but I am following the example shown in the section Subscribe Using Callback Functions in the Matlab ROS2 subscriber help file. Thanks in advance for any help with this.
The Program
function [] = multirate_tag_sorter_test_simple()
node = ros2node("myNode",0);
myMsg = ros2message("builtin_interfaces/Time");
mySub = ros2subscriber(node,"/myTopic","builtin_interfaces/Time", @receivedMessageCallback);
while true
fprintf('Waiting for messages to arrive...')
[~,~,~] = receive(mySub);
fprintf('Pulse received and processed.')
end
end
function receivedMessageCallback(msg)
fprintf('MESSAGE RECEIVED!');
end
The Code Generation Script
cfg = coder.config('exe');
cfg.Hardware = coder.hardware('Robot Operating System 2 (ROS 2)');
%cfg.Hardware.BuildAction = 'Build and run';
cfg.Hardware.BuildAction = 'Build and load';
cfg.Hardware.RemoteDeviceAddress = 'XXX.XXX.XXX.XXX';
cfg.Hardware.RemoteDeviceUsername = 'XXXXX';
cfg.Hardware.RemoteDevicePassword = 'XXXXXXX';
cfg.Hardware.DeployTo = 'Remote Device';
cfg.Hardware.ROS2Folder = '/opt/ros/galactic';
cfg.Hardware.ROS2Workspace = '~/uavrt_ws';
cfg.HardwareImplementation.ProdHWDeviceType = 'Intel->x86-64 (Linux 64)';
cfg.RuntimeChecks = true;%Disable for final deployments.
codegen multirate_tag_sorter_test_simple -args {} -config cfg
Error I am seeing:
??? Error calling
'multirate_tag_sorter_test_simple/receivedMessageCallback'.
This call-site passes more inputs to this function
than it can accept.
Error in ==> ros2subscriber Line: 288 Column: 21
Code generation failed: View Error Report
Error using codegen
Error in multirate_tag_sorter_test_codegen_script (line 22)
codegen multirate_tag_sorter_test_simple -args {} -config cfg
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Node Generation and Deployment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!