Publishing /diagnostics ros2 Topic in Simulink

7 views (last 30 days)
Hello,
I am trying to publish a ROS2 diagnostics topic in Simulink. The topic uses the DiagnosticArray message type, which makes it difficult to use the Bus Assignment block. To address this, I created a custom function for the task. Here is the function I implemented:
function msg = assignNestedArrayMessages(blankMessage)
blankMessage.status_SL_Info.CurrentLength = uint32(2);
blankMessage.status(1).level = uint8(1);
blankMessage.status(2).level = uint8(2);
blankMessage.header.stamp.sec = int32(1);
msg =blankMessage;
end
However, despite the simplicity of the function, I encountered the following error:
One or more signal names in the input bus to block 'pp/pub_diagnostics/SignalSpecification' does not match the signal names in the bus specified by the bus object 'SL_Bus_diagnostic_msgs_DiagnosticArray' on the block dialog. Signal Specification blocks always treat element name mismatches as errors, regardless of the 'Element name mismatch' option setting. Either change the specified bus object or rename the input bus element signals to match the bus object.
I would appreciate it if you could provide guidance on how to resolve this issue.

Accepted Answer

Shishir Reddy
Shishir Reddy on 7 Jan 2025
Hi Yubin
To resolve the issue encountered with the ROS2 diagnostics topic in Simulink, it should be ensured that the bus structure used in the custom function matches exactly with the bus object specified in the Simulink model. Here are some steps and tips to help you address the error:
1. Ensure that the structure of SL_Bus_diagnostic_msgs_DiagnosticArray matches the structure you are using in your custom function.
2. When the Bus Assignment block is used, it must be ensured that values are assigned to the correct signals.
3. It should be ensured that blankMessage is initialized correctly before being passed to the function.
Here's an example of how you might initialize and use the message in your function
function msg = assignNestedArrayMessages(blankMessage)
blankMessage.status_SL_Info.CurrentLength = uint32(2);
blankMessage.status(1).level = uint8(1);
blankMessage.status(1).name = '';
blankMessage.status(1).message = '';
blankMessage.status(1).hardware_id = '';
blankMessage.status(1).values_SL_Info.CurrentLength = uint32(0);
blankMessage.status(2).level = uint8(2);
blankMessage.status(2).name = '';
blankMessage.status(2).message = '';
blankMessage.status(2).hardware_id = '';
blankMessage.status(2).values_SL_Info.CurrentLength = uint32(0);
blankMessage.header.stamp.sec = int32(1);
blankMessage.header.stamp.nanosec = uint32(0);
blankMessage.header.frame_id = '';
msg = blankMessage;
end
By following these steps and ensuring consistency between the Simulink model and the custom function, the error should be resolved.
I hope this helps.
  2 Comments
chaechae
chaechae on 8 Jan 2025
I still cannot solve the problem.
I don’t understand "Ensure that the structure of SL_Bus_diagnostic_msgs_DiagnosticArray matches the structure you are using in your custom function".
Isn’t it ensured when the message type is set to diagnostic_msgs/DiagnosticArray in the ROS2 Publish block? Do I need to change configurations or other ROS settings?
The Simulink file is simple. These three blocks shown below are all there is. The assignNestedArrayMessages function block is written exactly as in the example you provided.
Shishir Reddy
Shishir Reddy on 8 Jan 2025
Setting the message type in the ROS 2 Publish block to diagnostic_msgs/DiagnosticArray should automatically configure the expected message structure in Simulink. However, the internal representation in Simulink might still require manual verification to ensure all fields are correctly set up, especially for nested arrays and structures.
Kindly refer to the following steps to understand the root cause of the issue:
1. Open the Bus Editor in Simulink (Simulink > Tools > Bus Editor) and examine the bus object SL_Bus_diagnostic_msgs_DiagnosticArray.
Verify that all fields (including nested fields) match the expected structure of the DiagnosticArray message. This includes checking for arrays and nested messages like DiagnosticStatus.
2. Ensure that your custom function initializes and assigns values to all necessary fields in the blankMessage. This includes nested fields and arrays.
3. Ensure that the Bus Assignment block is correctly configured to use this bus object. Check if there are any mismatches in signal names or types between the bus object and the input signals to the Bus Assignment block.
4. Use Simulink's diagnostic viewer to trace the error. It might provide insights into which specific field or signal is causing the mismatch
By following these steps and ensuring that the message structure in Simulink is correctly configured, the issue should be resolved.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!