├── .gitattributes ├── .github └── workflows │ ├── main.yml │ └── release.yml ├── .gitignore ├── README.md ├── ROSMessageSerializer.prj ├── SECURITY.md ├── buildUtilities ├── buildfile.m ├── checkTask.m ├── releaseTask.m └── testTask.m ├── license.txt ├── resources └── project │ ├── Project.xml │ ├── ProjectData.type.Info.xml │ ├── Root.type.Categories │ ├── FileClassCategory.type.Category.xml │ └── FileClassCategory.type.Category │ │ ├── artifact.type.Label.xml │ │ ├── convenience.type.Label.xml │ │ ├── derived.type.Label.xml │ │ ├── design.type.Label.xml │ │ ├── none.type.Label.xml │ │ ├── other.type.Label.xml │ │ └── test.type.Label.xml │ ├── Root.type.EntryPoints │ └── 838235e9-f7b5-45c9-8161-e22b86c17175.type.EntryPoint.xml │ ├── Root.type.EnvironmentCustomizations │ └── environment.slCustomization.type.Command.xml │ ├── Root.type.Files │ ├── .gitattributes.type.File.xml │ ├── .gitignore.type.File.xml │ ├── .gitlab-ci.yml.type.File.xml │ ├── README.md.type.File.xml │ ├── SECURITY.md.type.File.xml │ ├── buildUtilities.type.File.xml │ ├── buildUtilities.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── buildfile.m.type.File.xml │ │ ├── checkTask.m.type.File.xml │ │ ├── releaseTask.m.type.File.xml │ │ └── testTask.m.type.File.xml │ ├── license.txt.type.File.xml │ ├── test.type.File.xml │ ├── test.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── regtests.mldatx.type.File.xml │ │ └── slrtBuildTests.m.type.File.xml │ ├── toolbox.type.File.xml │ └── toolbox.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── examples.type.File.xml │ │ ├── examples.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── message_ros2_deserialize_receive.slx.type.File.xml │ │ ├── message_ros2_deserialize_receive_slrt.slx.type.File.xml │ │ ├── message_ros2_serialize_send.slx.type.File.xml │ │ ├── message_ros2_serialize_send_slrt.slx.type.File.xml │ │ ├── message_ros_deserialize_receive.slx.type.File.xml │ │ └── message_ros_serialize_send.slx.type.File.xml │ │ ├── lib.type.File.xml │ │ └── lib.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── ROSMessageSerializer.slx.type.File.xml │ │ ├── private.type.File.xml │ │ ├── private.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── rosmsgSerializeStruct.m.type.File.xml │ │ └── rosmsgUnpack.m.type.File.xml │ │ ├── ros2deserialize.m.type.File.xml │ │ ├── ros2serialize.m.type.File.xml │ │ ├── rosdeserialize.m.type.File.xml │ │ ├── rosserialize.m.type.File.xml │ │ └── slblocks.m.type.File.xml │ ├── Root.type.ProjectPath │ ├── 05bfeeed-df41-4b39-8179-92646094d2cd.type.Reference.xml │ ├── 98e60f87-aedb-40cc-a307-8c31c3e9f1fd.type.Reference.xml │ ├── a0e55bf1-6e1b-457a-9d5c-af265f8d9f34.type.Reference.xml │ ├── a45e1e9a-d2d6-4110-8fa3-da911e155b1f.type.Reference.xml │ └── af86c749-8b6f-48a0-9e1b-5ccac593a6d7.type.Reference.xml │ ├── Root.type.WorkingFolders │ ├── ProjectStartupFolder.type.Reference.xml │ ├── SimulinkCacheFolder.type.Reference.xml │ └── SimulinkCodeGenFolder.type.Reference.xml │ └── uuid-f35aac45-33ad-45cb-900e-29d627a8b508.xml ├── test ├── regtests.mldatx └── slrtBuildTests.m └── toolbox ├── examples ├── message_ros2_deserialize_receive.slx ├── message_ros2_deserialize_receive_slrt.slx ├── message_ros2_serialize_send.slx ├── message_ros2_serialize_send_slrt.slx ├── message_ros_deserialize_receive.slx └── message_ros_serialize_send.slx └── lib ├── ROSMessageSerializer.slx ├── private ├── rosmsgSerializeStruct.m └── rosmsgUnpack.m ├── ros2deserialize.m ├── ros2serialize.m ├── rosdeserialize.m ├── rosserialize.m └── slblocks.m /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mlx -crlf -diff -merge 2 | *.mat -crlf -diff -merge 3 | *.fig -crlf -diff -merge 4 | *.mdl -crlf -diff -merge 5 | *.slx -crlf -diff -merge 6 | *.mlapp -crlf -diff -merge 7 | *.p -crlf -diff -merge 8 | *.mdlp -crlf -diff -merge 9 | *.slxp -crlf -diff -merge 10 | *.sldd -crlf -diff -merge 11 | *.slxc -crlf -diff -merge 12 | *.mlproj -crlf -diff -merge 13 | *.mldatx -crlf -diff -merge 14 | *.slreqx -crlf -diff -merge 15 | *.sfx -crlf -diff -merge 16 | *.sltx -crlf -diff -merge 17 | *.mexa64 -crlf -diff -merge 18 | *.mexw64 -crlf -diff -merge 19 | *.mexmaci64 -crlf -diff -merge 20 | *.xlsx -crlf -diff -merge 21 | *.docx -crlf -diff -merge 22 | *.pdf -crlf -diff -merge 23 | *.jpg -crlf -diff -merge 24 | *.png -crlf -diff -merge -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the main branch 8 | push: 9 | branches: [ main ] 10 | paths-ignore: 11 | - 'README.md' 12 | pull_request: 13 | branches: [ main ] 14 | 15 | # Allows you to run this workflow manually from the Actions tab 16 | workflow_dispatch: 17 | 18 | # Allows you to run this workflow calling it from another workflow 19 | workflow_call: 20 | 21 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 22 | jobs: 23 | check: 24 | runs-on: ubuntu-latest 25 | # Steps represent a sequence of tasks that will be executed as part of the job 26 | steps: 27 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 28 | - name: Check out repo 29 | uses: actions/checkout@v3 30 | 31 | - name: Set up MATLAB 32 | uses: matlab-actions/setup-matlab@v1 33 | 34 | - name: Run commands 35 | uses: matlab-actions/run-command@v1 36 | with: 37 | command: openProject(pwd); checkTask; 38 | 39 | - name: Archive check results 40 | uses: actions/upload-artifact@v3 41 | if: always() 42 | with: 43 | name: code-issues 44 | path: work/checkResults.json 45 | 46 | test: 47 | # The type of runner that the job will run on 48 | runs-on: ubuntu-latest 49 | 50 | # Steps represent a sequence of tasks that will be executed as part of the job 51 | steps: 52 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 53 | - name: Check out repo 54 | uses: actions/checkout@v3 55 | 56 | - name: Setup MATLAB 57 | # You may pin to the exact commit or the version. 58 | # uses: matlab-actions/setup-matlab@bfca1c30aa37e57792ad04e5c68bf4ff33218b6d 59 | uses: matlab-actions/setup-matlab@v1 60 | 61 | - name: Run MATLAB Command 62 | # You may pin to the exact commit or the version. 63 | # uses: matlab-actions/run-command@3a7e877e5c019883a1f5fe4635c84d74394bb70e 64 | uses: matlab-actions/run-command@v1 65 | with: 66 | # Script, function, or statement to execute 67 | command: openProject(pwd); testTask('github'); 68 | 69 | - name: Publish Test Results 70 | uses: EnricoMi/publish-unit-test-result-action@v2 71 | if: always() 72 | with: 73 | fail_on: "test failures" 74 | action_fail: true 75 | files: | 76 | results.xml 77 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Package toolbox and publish release 2 | 3 | # Run workflow when a tag is created 4 | on: 5 | push: 6 | tags: 7 | - 'v*' 8 | 9 | jobs: 10 | ci: 11 | uses: ./.github/workflows/main.yml 12 | 13 | package: 14 | needs: ci 15 | # The type of runner that the job will run on 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 20 | - uses: actions/checkout@v3 21 | 22 | - name: Set up MATLAB 23 | uses: matlab-actions/setup-matlab@v1 24 | 25 | - name: Run commands 26 | uses: matlab-actions/run-command@v1 27 | with: 28 | command: openProject(pwd); releaseTask('toolboxVersion',"${{ github.ref_name }}",'authorName',"${{ github.actor }}"); 29 | 30 | # Create new release 31 | - name: Release 32 | uses: softprops/action-gh-release@v1 33 | with: 34 | files: releases/Message-De-Serializer-for-ROS-installer.mltbx 35 | fail_on_unmatched_files: true 36 | generate_release_notes: true 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | work 2 | 3 | # Autosave files 4 | *.asv 5 | *.m~ 6 | *.autosave 7 | *.slx.r* 8 | *.mdl.r* 9 | 10 | # Compiled MEX files 11 | *.mex* 12 | 13 | # Packaged app and toolbox files 14 | *.mlappinstall 15 | *.mltbx 16 | 17 | # Deployable archives 18 | *.ctf 19 | 20 | # Generated helpsearch folders 21 | helpsearch*/ 22 | 23 | # Code generation folders 24 | slprj/ 25 | sccprj/ 26 | codegen/ 27 | releases/ 28 | 29 | # Cache files 30 | *.slxc 31 | 32 | # Cloud based storage dotfile 33 | .MATLABDriveTag -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Message De-Serializer for ROS 2 | [![CI](https://github.com/mathworks/Message-De-Serializer-for-ROS/actions/workflows/main.yml/badge.svg)](https://github.com/mathworks/Message-De-Serializer-for-ROS/actions/workflows/main.yml) [![GitHub issues by-label](https://img.shields.io/github/issues-raw/mathworks/Message-De-Serializer-for-ROS/bug)](https://github.com/mathworks/Message-De-Serializer-for-ROS/issues?q=is%3Aissue+is%3Aopen+label%3Abug) [![View Message-De-Serializer-for-ROS on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/105815-message-de-serializer-for-ros) 3 | 4 | This project relies on [ROS Toolbox](https://www.mathworks.com/products/ros.html) functionality to provide basic integration of Simulink® targets, with focus on [Simulink Real-Time™](https://www.mathworks.com/products/simulink-real-time.html) and [Speedgoat®](https://www.speedgoat.com), into ROS/ROS2 networks via message serialization. The project leverages existing API from the ROS Toolbox in some MATLAB® System blocks to process ROS/ROS2 messages over UDP or Serial communication. 5 | 6 | The project contains a small set of Serialize and De-Serialize blocks in a library together with some simple model examples. 7 | 8 | ## Setup 9 | ### MathWorks products 10 | Requires MATLAB release R2020b or newer. 11 | - MATLAB 12 | - Simulink 13 | - ROS Toolbox 14 | - Instrument Control Toolbox™ (optional) 15 | - Simulink Real-Time (optional) 16 | 17 | ## Getting Started 18 | 1. Start the Simulink project `ROSMessageSerializer.prj`. 19 | 2. ROS/ROS2 (De-)Serializer blocks will be added to the Simulink library, available via the library browser or the Simulink block search. 20 | 3. Open any Simulink model example located in the `examples` folder and get familiar with different set-ups. 21 | 22 | ## Examples 23 | To learn how to use this in testing workflows, see the included examples. 24 | 25 | ## License 26 | The license is available in the [License file](license.txt) within this repository. 27 | 28 | # Community Support 29 | [MATLAB Central](https://www.mathworks.com/matlabcentral) 30 | 31 | Copyright 2022 The MathWorks, Inc. 32 | -------------------------------------------------------------------------------- /ROSMessageSerializer.prj: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting Security Vulnerabilities 2 | 3 | If you believe you have discovered a security vulnerability, please report it to 4 | [security@mathworks.com](mailto:security@mathworks.com). Please see 5 | [MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html) 6 | for additional information. -------------------------------------------------------------------------------- /buildUtilities/buildfile.m: -------------------------------------------------------------------------------- 1 | function plan = buildfile 2 | 3 | import matlab.buildtool.Task 4 | 5 | % Create a plan with no tasks 6 | plan = buildplan; 7 | 8 | % Create the "check" task and add it to the plan 9 | plan("check") = Task( ... 10 | Description = "Identify code issues", ... 11 | Actions = @(~) checkTask); 12 | 13 | % Create the "test" task and add it to the plan 14 | plan("test") = Task( ... 15 | Description = "Run unit tests", ... 16 | Actions = @(~,tags) testTask(tags)); 17 | 18 | % Make the "release" task dependent on the "check" and "test" tasks 19 | plan("package") = Task( ... 20 | Description = "Package toolbox", ... 21 | Dependencies = ["check" "test"], ... 22 | Actions = @(~) releaseTask); 23 | 24 | % Set default tasks in the plan 25 | plan.DefaultTasks = ["check" "test"]; 26 | 27 | end -------------------------------------------------------------------------------- /buildUtilities/checkTask.m: -------------------------------------------------------------------------------- 1 | function issues = checkTask 2 | 3 | projObj = currentProject; 4 | 5 | % Identify code issues 6 | issues = codeIssues(projObj.RootFolder); 7 | 8 | % Encode results in JSON file and export 9 | if batchStartupOptionUsed 10 | jsonIssues = jsonencode(issues); 11 | fid = fopen('checkResults.json','w'); 12 | fprintf(fid,'%s',jsonIssues); 13 | fclose(fid); 14 | end 15 | 16 | % Assert code results 17 | assert(isempty(issues.Issues),... 18 | formattedDisplayText(issues.Issues(:,["Location" "Severity" "Description"]))); 19 | 20 | end -------------------------------------------------------------------------------- /buildUtilities/releaseTask.m: -------------------------------------------------------------------------------- 1 | function toolboxOptions = releaseTask(options) 2 | %GENERATETOOLBOX Function that generates a toolbox for the boss device API 3 | 4 | arguments 5 | options.toolboxVersion {mustBeTextScalar} = '0.0' 6 | options.authorName {mustBeTextScalar} = "MathWorks" % Use committer name when packaging from CI 7 | end 8 | 9 | % Get current project object 10 | projObj = currentProject; 11 | 12 | % Remove v from toolboxVersion 13 | options.toolboxVersion = erase(options.toolboxVersion,"v"); 14 | 15 | % Toolbox Parameter Configuration 16 | toolboxOptions = matlab.addons.toolbox.ToolboxOptions(fullfile(projObj.RootFolder,"toolbox"), "Message-De-Serializer-for-ROS"); 17 | 18 | toolboxOptions.ToolboxName = projObj.Name; 19 | toolboxOptions.ToolboxVersion = options.toolboxVersion; 20 | toolboxOptions.Summary = projObj.Description; 21 | % toolboxOptions.Description = projObj.Description; 22 | toolboxOptions.AuthorName = options.authorName; 23 | toolboxOptions.AuthorEmail = "promero@mathworks.com"; 24 | toolboxOptions.AuthorCompany = "MathWorks"; 25 | % toolboxOptions.ToolboxGettingStartedGuide = fullfile(projObj.RootFolder,"toolbox/gettingStarted.mlx"); 26 | 27 | if ~exist(fullfile(projObj.RootFolder,"releases"), 'dir') 28 | mkdir(fullfile(projObj.RootFolder,"releases")) 29 | end 30 | toolboxOptions.OutputFile = fullfile(projObj.RootFolder,"releases/Message-De-Serializer-for-ROS-installer.mltbx"); 31 | 32 | toolboxOptions.MinimumMatlabRelease = "R2020b"; 33 | % toolboxOptions.MaximumMatlabRelease = "R2023a"; % Won't limit maximum MATLAB release 34 | toolboxOptions.SupportedPlatforms.Glnxa64 = true; 35 | toolboxOptions.SupportedPlatforms.Maci64 = true; 36 | toolboxOptions.SupportedPlatforms.MatlabOnline = false; 37 | toolboxOptions.SupportedPlatforms.Win64 = true; 38 | 39 | % Generate toolbox 40 | matlab.addons.toolbox.packageToolbox(toolboxOptions); 41 | 42 | end -------------------------------------------------------------------------------- /buildUtilities/testTask.m: -------------------------------------------------------------------------------- 1 | function results = testTask(tags) 2 | % Run unit tests 3 | 4 | arguments 5 | tags {mustBeText} = ''; 6 | end 7 | 8 | import matlab.unittest.TestRunner; 9 | import matlab.unittest.TestSuite; 10 | import matlab.unittest.Verbosity; 11 | import matlab.unittest.plugins.XMLPlugin; 12 | import matlab.unittest.selectors.HasTag; 13 | 14 | projObj = currentProject; 15 | 16 | suite = TestSuite.fromProject(projObj); 17 | if ~isempty(tags) 18 | suite = suite.selectIf(HasTag(tags)); 19 | else 20 | disp('No tag was passed as input. All test cases will be executed.'); 21 | end 22 | 23 | if isempty(suite) 24 | warning('No tests were found with tag(s) "%s" and none will be executed.',strjoin(tags,', ')); 25 | end 26 | 27 | runner = TestRunner.withTextOutput('OutputDetail', Verbosity.Detailed); 28 | runner.addPlugin(XMLPlugin.producingJUnitFormat(fullfile(projObj.RootFolder,'results.xml'))); 29 | 30 | results = runner.run(suite); 31 | 32 | % CI workflows evaluate test success from Test Report 33 | if ~batchStartupOptionUsed 34 | results.assertSuccess; 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021, The MathWorks, Inc. 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | 3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings. 7 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /resources/project/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/ProjectData.type.Info.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/artifact.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/convenience.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/derived.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/design.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/none.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/other.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/test.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.EntryPoints/838235e9-f7b5-45c9-8161-e22b86c17175.type.EntryPoint.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.EnvironmentCustomizations/environment.slCustomization.type.Command.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/.gitattributes.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/.gitignore.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/.gitlab-ci.yml.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/README.md.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SECURITY.md.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/buildUtilities.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/buildUtilities.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/buildUtilities.type.File/buildfile.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/buildUtilities.type.File/checkTask.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/buildUtilities.type.File/releaseTask.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/buildUtilities.type.File/testTask.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/license.txt.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/test.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/test.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/test.type.File/regtests.mldatx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/test.type.File/slrtBuildTests.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/message_ros2_deserialize_receive.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/message_ros2_deserialize_receive_slrt.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/message_ros2_serialize_send.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/message_ros2_serialize_send_slrt.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/message_ros_deserialize_receive.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/examples.type.File/message_ros_serialize_send.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/ROSMessageSerializer.slx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/private.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/private.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/private.type.File/rosmsgSerializeStruct.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/private.type.File/rosmsgUnpack.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/ros2deserialize.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/ros2serialize.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/rosdeserialize.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/rosserialize.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/toolbox.type.File/lib.type.File/slblocks.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.ProjectPath/05bfeeed-df41-4b39-8179-92646094d2cd.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.ProjectPath/98e60f87-aedb-40cc-a307-8c31c3e9f1fd.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.ProjectPath/a0e55bf1-6e1b-457a-9d5c-af265f8d9f34.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.ProjectPath/a45e1e9a-d2d6-4110-8fa3-da911e155b1f.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.ProjectPath/af86c749-8b6f-48a0-9e1b-5ccac593a6d7.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.WorkingFolders/ProjectStartupFolder.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.WorkingFolders/SimulinkCacheFolder.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.WorkingFolders/SimulinkCodeGenFolder.type.Reference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/uuid-f35aac45-33ad-45cb-900e-29d627a8b508.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/regtests.mldatx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/test/regtests.mldatx -------------------------------------------------------------------------------- /test/slrtBuildTests.m: -------------------------------------------------------------------------------- 1 | classdef slrtBuildTests < matlab.unittest.TestCase 2 | 3 | properties (TestParameter) 4 | model = {'message_ros2_deserialize_receive_slrt','message_ros2_serialize_send_slrt'}; 5 | end 6 | 7 | methods (Test) 8 | % Test methods 9 | function slrtBuild(testCase, model) 10 | testCase.verifyWarningFree(@() slbuild(model)); 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /toolbox/examples/message_ros2_deserialize_receive.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/examples/message_ros2_deserialize_receive.slx -------------------------------------------------------------------------------- /toolbox/examples/message_ros2_deserialize_receive_slrt.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/examples/message_ros2_deserialize_receive_slrt.slx -------------------------------------------------------------------------------- /toolbox/examples/message_ros2_serialize_send.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/examples/message_ros2_serialize_send.slx -------------------------------------------------------------------------------- /toolbox/examples/message_ros2_serialize_send_slrt.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/examples/message_ros2_serialize_send_slrt.slx -------------------------------------------------------------------------------- /toolbox/examples/message_ros_deserialize_receive.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/examples/message_ros_deserialize_receive.slx -------------------------------------------------------------------------------- /toolbox/examples/message_ros_serialize_send.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/examples/message_ros_serialize_send.slx -------------------------------------------------------------------------------- /toolbox/lib/ROSMessageSerializer.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/Message-De-Serializer-for-ROS/df14a0c3d1996e69dc1d56b2f8e6131138e6b471/toolbox/lib/ROSMessageSerializer.slx -------------------------------------------------------------------------------- /toolbox/lib/private/rosmsgSerializeStruct.m: -------------------------------------------------------------------------------- 1 | function [ y, jj_out ] = rosmsgSerializeStruct(msg, packed, jj) 2 | %rosmsgSerializeStruct Serialize a message structure into a byte stream 3 | 4 | % Copyright 2017 The MathWorks, Inc. 5 | 6 | %#codegen 7 | 8 | p = fieldnames(msg); 9 | 10 | for ii = 1:numel(p) 11 | name = char(p{ii}); 12 | obj = msg.(name); 13 | if isstruct(obj) 14 | [packed, jj] = rosmsgSerializeStruct(obj, packed, jj); 15 | else 16 | new_vec = typecast(obj, 'uint8'); 17 | numel_new_vec = numel(new_vec); 18 | new_vec_len = typecast(numel_new_vec, 'uint8'); 19 | 20 | if iscolumn(new_vec_len) 21 | %packed = horzcat(packed, new_vec_len'); 22 | packed(jj:jj+8-1) = new_vec_len'; 23 | else 24 | %packed = horzcat(packed, new_vec_len); 25 | packed(jj:jj+8-1) = new_vec_len; 26 | end 27 | 28 | jj = jj + 8; 29 | 30 | if iscolumn(new_vec) 31 | %packed = horzcat(packed, new_vec'); 32 | packed(jj:jj+numel_new_vec-1) = new_vec'; 33 | else 34 | packed(jj:jj+numel_new_vec-1) = new_vec; 35 | end 36 | 37 | jj = jj + numel_new_vec; 38 | end 39 | end 40 | 41 | y = packed; 42 | jj_out = jj; 43 | 44 | end -------------------------------------------------------------------------------- /toolbox/lib/private/rosmsgUnpack.m: -------------------------------------------------------------------------------- 1 | function [ msg_out ] = rosmsgUnpack( arr, msg_in ) 2 | %rosmsgUnpack Populate a structure based on a byte array 3 | 4 | % Copyright 2017 The MathWorks, Inc. 5 | 6 | %#codegen 7 | 8 | msg_out = inject_data(msg_in, arr, 1); 9 | 10 | end 11 | 12 | function [msg_out, depth_out] = inject_data(msg, inarr, jj) 13 | p = fieldnames(msg); 14 | for ii = 1:numel(p) 15 | name = char(p{ii}); 16 | obj = msg.(name); 17 | 18 | if isstruct(obj) 19 | [msg.(name), jj] = inject_data(obj, inarr, jj); 20 | else 21 | leaf_len = typecast(inarr(jj:jj+8-1), 'double'); 22 | jj = jj + 8; 23 | c = class(msg.(name)); 24 | temp = typecast(inarr(jj:jj+leaf_len(1)-1), c); 25 | msg.(name) = temp(1:numel(msg.(name))); 26 | jj = jj + leaf_len(1); 27 | end 28 | end 29 | msg_out = msg; 30 | depth_out = jj; 31 | end -------------------------------------------------------------------------------- /toolbox/lib/ros2deserialize.m: -------------------------------------------------------------------------------- 1 | classdef ros2deserialize < matlab.System 2 | %rosdeserialize Deserialize a byte array into a ROS2 message 3 | % 4 | % This system object deserializes a byte array into a ROS2 message. 5 | % This object assumes that the byte array has been created by the 6 | % rosserialize system object. 7 | % 8 | % See also ros2serialize. 9 | % 10 | % Copyright 2020 The MathWorks, Inc. 11 | 12 | %#codegen 13 | 14 | properties (Nontunable) 15 | MessageType = 'geometry_msgs/Point'; 16 | end 17 | 18 | % These are the options for the dropdown lists 19 | % The properties are constant, hidden, and transient based on the 20 | % system object documentation 21 | properties (Hidden, Transient) 22 | %MessageTypeSet - Dropdown choices for ROS2 message type 23 | MessageTypeSet = matlab.system.StringSet(ros2("msg","list")); 24 | end 25 | 26 | methods 27 | function obj = rosdeserialize(obj, varargin) 28 | % Support name-value pair arguments when constructing the object. 29 | setProperties(obj, nargin, varargin{:}); 30 | end 31 | end 32 | 33 | methods (Access = protected) 34 | function num = getNumInputsImpl(~) 35 | num = 3; 36 | end 37 | 38 | function num = getNumOutputsImpl(~) 39 | num = 1; 40 | end 41 | 42 | function outSizeBool = isOutputFixedSizeImpl(~) 43 | outSizeBool = true; 44 | end 45 | 46 | function outSize = getOutputSizeImpl(~) 47 | outSize = 1; 48 | end 49 | 50 | function isComplex = isOutputComplexImpl(~) 51 | isComplex = false; 52 | end 53 | 54 | function outType = getOutputDataTypeImpl(obj) 55 | [~, outType] = ros.slros2.internal.bus.Util.rosMsgTypeToDataTypeStr(obj.MessageType); 56 | end 57 | 58 | function Msg = stepImpl(~, Data, Length, BlankMsg) 59 | if Length > 0 60 | Msg = rosmsgUnpack(Data(1:Length), BlankMsg); 61 | elseif Length == -1 62 | s = size(Data); 63 | Msg = rosmsgUnpack(Data(1:s(1)), BlankMsg); 64 | else 65 | Msg = BlankMsg; 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /toolbox/lib/ros2serialize.m: -------------------------------------------------------------------------------- 1 | classdef ros2serialize < matlab.System 2 | %rosserialize Serialize a ROS2 message into a byte array 3 | % 4 | % This system object serializes a ROS2 message into a byte array. This 5 | % byte array can then be sent over a non-ROS communication channel, 6 | % e.g. a UDP or serial channel. 7 | % 8 | % Use the rosdeserialize system object to reverse the process. 9 | % 10 | % See also rosdeserialize. 11 | % 12 | % Copyright 2020 The MathWorks, Inc. 13 | 14 | %#codegen 15 | 16 | properties(Logical, Nontunable) 17 | fixedSize = true; % Use fixed output size (for code generation) 18 | end 19 | 20 | properties(Nontunable) 21 | maxSizeBytes = 2048; % Maximum message size in bytes 22 | end 23 | 24 | methods(Access = protected) 25 | function dataout = getOutputDataTypeImpl(~) 26 | dataout = 'uint8'; 27 | end 28 | 29 | function outVarBool = isOutputFixedSizeImpl(obj) 30 | outVarBool = obj.fixedSize; 31 | end 32 | 33 | function maxSize = getOutputSizeImpl(obj) 34 | maxSize = [1,obj.maxSizeBytes]; 35 | end 36 | 37 | function Data = stepImpl(obj, Msg) 38 | 39 | packed = uint8(zeros([1,obj.maxSizeBytes])); 40 | [y_intermediate, jj_final] = rosmsgSerializeStruct(Msg, packed, 1); 41 | 42 | if obj.fixedSize 43 | Data = y_intermediate; 44 | else 45 | Data = y_intermediate(1,1:jj_final-1); 46 | end 47 | end 48 | end 49 | end -------------------------------------------------------------------------------- /toolbox/lib/rosdeserialize.m: -------------------------------------------------------------------------------- 1 | classdef rosdeserialize < matlab.System & matlab.system.mixin.Propagates 2 | %rosdeserialize Deserialize a byte array into a ROS message 3 | % 4 | % This system object deserializes a byte array into a ROS message. 5 | % This object assumes that the byte array has been created by the 6 | % rosserialize system object. 7 | % 8 | % See also rosserialize. 9 | % 10 | % Copyright 2017 The MathWorks, Inc. 11 | 12 | %#codegen 13 | 14 | properties (Nontunable) 15 | MessageType = 'geometry_msgs/Point'; 16 | end 17 | 18 | % These are the options for the dropdown lists 19 | % The properties are constant, hidden, and transient based on the 20 | % system object documentation 21 | properties (Hidden, Transient) 22 | %MessageTypeSet - Dropdown choices for ROS message type 23 | MessageTypeSet = matlab.system.StringSet(rosmsg('list')); 24 | end 25 | 26 | methods 27 | function obj = rosdeserialize(varargin) 28 | % Support name-value pair arguments when constructing the object. 29 | setProperties(obj, nargin, varargin{:}); 30 | end 31 | end 32 | 33 | methods (Access = protected) 34 | function num = getNumInputsImpl(~) 35 | num = 3; 36 | end 37 | 38 | function num = getNumOutputsImpl(~) 39 | num = 1; 40 | end 41 | 42 | function outSizeBool = isOutputFixedSizeImpl(~) 43 | outSizeBool = true; 44 | end 45 | 46 | function outSize = getOutputSizeImpl(~) 47 | outSize = 1; 48 | end 49 | 50 | function isComplex = isOutputComplexImpl(~) 51 | isComplex = false; 52 | end 53 | 54 | function outType = getOutputDataTypeImpl(obj) 55 | [~, outType] = ros.slros.internal.bus.Util.rosMsgTypeToDataTypeStr(obj.MessageType, bdroot); 56 | end 57 | 58 | function Msg = stepImpl(~, Data, Length, BlankMsg) 59 | if Length > 0 60 | Msg = rosmsgUnpack(Data(1:Length), BlankMsg); 61 | elseif Length == -1 62 | s = size(Data); 63 | Msg = rosmsgUnpack(Data(1:s(1)), BlankMsg); 64 | else 65 | Msg = BlankMsg; 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /toolbox/lib/rosserialize.m: -------------------------------------------------------------------------------- 1 | classdef rosserialize < matlab.System & matlab.system.mixin.Propagates 2 | %rosserialize Serialize a ROS message into a byte array 3 | % 4 | % This system object serializes a ROS message into a byte array. This 5 | % byte array can then be sent over a non-ROS communication channel, 6 | % e.g. a UDP or serial channel. 7 | % 8 | % Use the rosdeserialize system object to reverse the process. 9 | % 10 | % See also rosdeserialize. 11 | % 12 | % Copyright 2017 The MathWorks, Inc. 13 | 14 | %#codegen 15 | 16 | properties(Logical, Nontunable) 17 | fixedSize = true; % Use fixed output size (for code generation) 18 | end 19 | 20 | properties(Nontunable) 21 | maxSizeBytes = 2048; % Maximum message size in bytes 22 | end 23 | 24 | methods(Access = protected) 25 | function dataout = getOutputDataTypeImpl(~) 26 | dataout = 'uint8'; 27 | end 28 | 29 | function outVarBool = isOutputFixedSizeImpl(obj) 30 | outVarBool = obj.fixedSize; 31 | end 32 | 33 | function maxSize = getOutputSizeImpl(obj) 34 | maxSize = [1,obj.maxSizeBytes]; 35 | end 36 | 37 | function Data = stepImpl(obj, Msg) 38 | packed = uint8(zeros([1,obj.maxSizeBytes])); 39 | [y_intermediate, jj_final] = rosmsgSerializeStruct(Msg, packed, 1); 40 | 41 | if obj.fixedSize 42 | Data = y_intermediate; 43 | else 44 | Data = y_intermediate(1,1:jj_final-1); 45 | end 46 | end 47 | end 48 | end -------------------------------------------------------------------------------- /toolbox/lib/slblocks.m: -------------------------------------------------------------------------------- 1 | function blkStruct = slblocks 2 | Browser.Library ='ROSMessageSerializer'; 3 | Browser.Name ='ROS/ROS2 Message (De)Serializer'; 4 | blkStruct.Browser = Browser; 5 | end 6 | --------------------------------------------------------------------------------