Main Content

gzinit

Initialize connection settings for Gazebo Co-Simulation MATLAB interface

    Description

    gzinit initializes connection settings and checks connectivity with the Gazebo plugin running on localhost and port 14581. This syntax sets response timeout to 1 second.

    gzinit(HostIP) specifies the host name or IP address of the Gazebo plugin HostIP.

    example

    gzinit(HostIP,HostPort) specifies the port number HostPort.

    gzinit(HostIP,HostPort,Timeout) specifies the response timeout Timeout in seconds.

    Examples

    collapse all

    Set up a simulation between MATLAB and Gazebo, receive data from Gazebo, and send commands to Gazebo.

    Download the Linux virtual machine (VM) with Gazebo installed from Virtual Machine with ROS and Gazebo.

    Set up multiSensorPluginTest.world by following the Gazebo simulation environment setup and launch steps in Perform Co-Simulation between Simulink and Gazebo.

    Configure and Perform Gazebo Co-Simulation

    Initialize connection settings and check connectivity with the Gazebo plugin running on 192.168.198.129 and port 14581.

    gzinit("192.168.198.129",14581)

    Assign and Retrieve Gazebo Model Information

    List the models available in the Gazebo world.

    modelList = gzmodel("list")
    modelList = 1×11 string
        "ground_plane"    "unit_box"    "camera0"    "camera1"    "depth_camera0"    "depth_camera1"    "imu0"    "imu1"    "hokuyo0"    "hokuyo1"    "velodyne"
    
    

    Assign values to the Position and SelfCollide parameters of the unit_box model.

    [status,message] = gzmodel("set","unit_box","Position",[2 2 0.5],"SelfCollide","on")
    status = 1×2 logical array
    
       1   1
    
    
    message = 1×2 string
        "Position parameter set successfully."    "SelfCollide parameter set successfully."
    
    

    Retrieve the values of the Position and SelfCollide parameters of the unit_box model.

    [position,selfcollide] = gzmodel("get","unit_box","Position","SelfCollide")
    position = 1×3
    
                             2                         2           0.4999999999951
    
    
    selfcollide = logical
       1
    
    

    Assign and Retrieve Gazebo Model Link Information

    List the links available in the unit_box model.

    linkList = gzlink("list","unit_box")
    linkList = 
    "link"
    

    Assign values to the link parameters Mass and Gravity of the link link in the unit_box model.

    [status,message] = gzlink("set","unit_box","link","Mass",2,"Gravity","off")
    status = 1×2 logical array
    
       1   1
    
    
    message = 1×2 string
        "Mass parameter set successfully."    "Gravity parameter set successfully."
    
    

    Retrieve the values of the link parameters Mass and Gravity of the link link in the unit_box model.

    [mass,gravity] = gzlink("get","unit_box","link","Mass","Gravity")
    mass = 
         2
    
    
    gravity = logical
       0
    
    

    Assign and Retrieve Gazebo Model Joint Information

    List the joints available in the unit_box model.

    jointList = gzjoint("list","unit_box")
    jointList = 
    "joint"
    

    Assign a value to the joint parameter Damping of the axis Axis0 for the joint joint in the unit_box model.

    [status,message] = gzjoint("set","unit_box","joint","Axis","0","Damping",0.25)
    status = logical
       1
    
    
    message = 
    "Damping parameter set successfully."
    

    Retrieve the value of the joint parameter Damping of the axis Axis0 for the joint joint in the unit_box model.

    damping = gzjoint("get","unit_box","joint","Axis0","Damping")
    damping = 
                          0.25
    
    

    Reset all Gazebo model configurations.

    gzworld("reset")

    Input Arguments

    collapse all

    The host name or IP address of the machine with the Gazebo plugin, specified as a string scalar or character vector.

    Example: gzinit("172.18.250.191")

    Port number of the machine with the Gazebo plugin, specified as a positive integer. The port number must be the same as the value of 'portNumber' in the Gazebo '.world' file.

    Example: gzinit("172.18.250.191",14581)

    Response timeout, specified as a positive numeric scalar. This value determines how long the client will wait for a response from the server, in seconds. Set a higher Timeout value for a network with poor connectivity.

    Example: gzinit("172.18.250.191",14581,10)

    Limitations

    • gzinit function not supported with MATLAB® Compiler™.

    Introduced in R2021a