![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1497729/image.png)
Error in rosReadBinaryOccupancyGrid
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
SEUNGSHIN
le 29 Sep 2023
Réponse apportée : Josh Chen
le 30 Sep 2023
Hello I'm trying to subscribe /map topic from ROS and make occupancy map in simulink
So I use subscribe block in Simulink and connect msg to MATLAB function block.
the code of MATLAB function block is below
function fcn(u)
map = rosReadBinaryOccupancyGrid(u);
show(map)
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496495/image.png)
But there is an error
This structure does not have a field 'MessageType'. Function 'rosReadBinaryOccupancyGrid.m'(#222.2006.2009)
Is there any solution or another way to plot occupancy map in simulink?
0 commentaires
Réponse acceptée
Josh Chen
le 30 Sep 2023
Hi SEUNGSHIN,
Thanks for bringing this use case to our attention. As for now, there is no Simulink block for reading binary occupancy grid. We will consider to provide this functionality in a future release.
Meanwhile, as a workaround, you can use a combination of "MATLAB Function" and "Video Viewer" block to plot occupancy map in Simulink.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1497729/image.png)
Here is the script in MATLAB function block for your reference:
function y = fcn(u)
% Specify the expected dimension of the occupancyMatrix
y = zeros(10,10,'logical');
dataLen = u.Data_SL_Info.CurrentLength;
if dataLen>0
% Create MATLAB message
msg = rosmessage("nav_msgs/OccupancyGrid","DataFormat","struct");
% Assign message fields based on input Simulink message bus
msg.Info.Height = u.Info.Height;
msg.Info.Width = u.Info.Width;
msg.Info.Resolution = u.Info.Resolution;
msg.Data = u.Data(1:dataLen);
% Use rosReadBinaryOccupancyGrid to read occupancy grid
map = rosReadBinaryOccupancyGrid(msg);
% output occupancyMatrix
occupancyMatrix = map.occupancyMatrix;
y = occupancyMatrix(1:10,1:10);
end
Hope that helps,
Thanks,
Josh
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specialized Messages dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!