Main Content

gazebogenmsg

Generate dependencies for Gazebo custom message support

Since R2020b

    Description

    gazebogenmsg(folderpath) generates dependencies for Gazebo custom message support using the protocol buffer (protobuf) files (.proto) in the specified folder folderpath. It then outputs the generated dependency files to the same folder. The function expects one or more .proto files in the same folder. See Algorithms for more information about using Simulink® to communicate with Gazebo, as well as sending and receiving custom messages.

    example

    gazebogenmsg(folderpath,Name,Value) specifies options using one or more name-value pair arguments.

    For example, 'GazeboVersion','Gazebo 10' sets the Gazebo message version to Gazebo 10.

    example

    Examples

    collapse all

    Create a folder in a local directory.

    folderPath = fullfile(pwd,'customMessage')
    folderPath = 
    '/tmp/Bdoc24b_2725827_1779694/tp07d7d716/robotics-ex62907275/customMessage'
    
    mkdir(folderPath)

    Create a .proto file inside the folder and define protobuf custom message fields.

    messageDefinition = {'message MyPose'
                         '{'
                         '   required double x = 1;'
                         '   required double y = 2;'
                         '   required double z = 3;'
                         '}'};
    fileID = fopen(fullfile(folderPath,'MyPose.proto'),'w');
    fprintf(fileID,'%s\n',messageDefinition{:});
    fclose(fileID);

    Use the gazebogenmsg function to generate dependences in the created folder.

    gazebogenmsg(folderPath)
    Validating ...
    Selected compiler details: "g++ 12.3.0"
    [libprotobuf WARNING] No syntax specified for the proto file: MyPose.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
    Building shared library ...
    Building MEX for "MyPose.proto" file ...
    Building with 'g++'.
    MEX completed successfully.
    Building with 'g++'.
    MEX completed successfully.
    Building custom message utilities  ...
    DONE.
     
    To use the gazebo custom messages, execute following commands:
     
    addpath('/tmp/Bdoc24b_2725827_1779694/tp07d7d716/robotics-ex62907275/customMessage/install')
    savepath
    

    Use the following commands to add and save the install path.

    addpath(fullfile(folderPath,'install'))

    savepath

    Create a Gazebo plugin package 'MyPlugin' inside the custom message folder using the packageGazeboPlugin function.

    packageGazeboPlugin(fullfile(folderPath,'MyPlugin'),folderPath)

    Create a folder in a local directory.

    folderPath = fullfile(pwd,'customMessage');
    mkdir(folderPath)
    cd(folderPath)

    Use the gazebogenmsg function to generate dependencies for a built-in gazebo message in the specified folder.

    gazebogenmsg(folderPath,"GazeboMessageList","gazebo.msgs.Image");
    Validating ...
    Selected compiler details: "g++ 12.3.0"
    Building shared library ...
    Building MEX for "image.proto" file ...
    Building with 'g++'.
    MEX completed successfully.
    Building with 'g++'.
    MEX completed successfully.
    Building custom message utilities  ...
    DONE.
     
    To use the gazebo custom messages, execute following commands:
     
    addpath('/tmp/Bdoc24b_2725827_1779694/tp07d7d716/robotics-ex40128733/customMessage/install')
    savepath
    

    Use the following commands to add and save the install path.

    addpath(fullfile(folderPath,'install'))

    savepath

    Create a Gazebo plugin package using the packageGazeboPlugin function.

    packageGazeboPlugin

    Input Arguments

    collapse all

    Path of the custom message folder, specified as a string scalar or character vector. The folder must contain one or more .proto files. The path also specifies the location in which to output the generated dependency files.

    Example: gazebogenmsg('C:\GazeboCustomMsg')

    Data Types: char | string

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: 'GazeboMessageList','gazebo.msgs.IMU' generates dependences for the built-in Gazebo message gazebo.msgs.IMU.

    Gazebo message version, specified as the comma-separated pair consisting of 'GazeboVersion' and either 'Gazebo 9', 'Gazebo 10' or 'Gazebo 11'.

    Example: 'GazeboVersion','Gazebo 10'

    Data Types: char | string

    Gazebo built-in messages, specified as the comma-separated pair consisting of 'GazeboMessageList' and one or more built-in messages from the list of valid Gazebo messages.

    To get a list of valid Gazebo messages, press Tab after entering the 'GazeboMessageList' argument name. You can select a valid Gazebo message value from the list.

    Example: 'GazeboMessageList','gazebo.msgs.Altimeter'

    Data Types: char | string

    Limitations

    • The gazebogenmsg function supports the proto2 version of the protobuf language. The function does not support the proto2 fields map, group, extend, extensions, and reserved.

    • You can run the Simulink model multiple times but you need to restart MATLAB® to run gazebogenmsg function again.​

    • gazebogenmsg function not supported with MATLAB Compiler™.

    Tips

    Supported Compilers

    Windows: Microsoft Visual C++ 14.0 and later

    Linux: g++ 6.0.0 and later​

    Mac: Xcode Clang++ 10.0.0 and later

    Algorithms

    1. Add and save the install path by running the command presented at the end of gazebogenmsg function output.

    2. Use the packageGazeboPlugin function to package the plugin.

    3. Copy, install and run the plugin on the Gazebo machine.

    4. Use the Gazebo Publish Simulink block to send the custom messages to the Gazebo machine.

    5. Use the Gazebo Subscribe Simulink block to receive the custom messages from the Gazebo machine.

    References

    [1] Google Developers. “Language Guide | Protocol Buffers.” Accessed July 17, 2020. https://protobuf.dev/programming-guides/proto/.

    Version History

    Introduced in R2020b