Main Content

gazebogenmsg

Generate dependencies for Gazebo custom message support

    Description

    example

    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.

    Examples

    collapse all

    This example shows how to generate dependencies for user-defined gazebo custom message.

    Create a folder in the local directory.

    folderPath = fullfile(pwd,'customMessage')
    folderPath = 
    '/tmp/Bdoc20b_1465442_44205/tpead699b1/robotics-ex62907275/customMessage'
    
    mkdir(folderPath)

    Create one or more '.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);

    Run the gazebogenmsg function and specify the folder path.

    gazebogenmsg(folderPath)
    Validating ...
    Selected compiler details: "g++ 8.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/Bdoc20b_1465442_44205/tpead699b1/robotics-ex62907275/customMessage/install')
    savepath
    

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

    %addpath(fullfile(folderPath,'install'))
    %savepath

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

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

    This example shows how to generate dependencies for built-in Gazebo message.

    Create a folder in the local directory.

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

    Run the gazebogenmsg function and specify the folder path and select one or more built-in gazebo message from the list.

    gazebogenmsg(folderPath,"GazeboMessageList","gazebo.msgs.Image");
    Validating ...
    Selected compiler details: "g++ 8.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/Bdoc20b_1465442_44205/tpead699b1/robotics-ex40128733/customMessage/install')
    savepath
    

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

    % addpath(fullfile(folderPath,'install'))
    % savepath

    Create 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 Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    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' or 'Gazebo 10'.

    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.​

    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://developers.google.com/protocol-buffers/docs/proto.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Introduced in R2020b