Main Content

gzworld

Interact with Gazebo world

    Description

    example

    gzworld("reset")resets all Gazebo model configurations and Gazebo simulation time.

    Examples

    collapse all

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

    Prerequisite

    Follow the instructions inPerform Co-Simulation between Simulink and Gazeboto download the Linux virtual machine (VM) with Gazebo and set upmultiSensorPluginTest.world.

    Configure and Perform Gazebo Co-Simulation

    Initialize connection settings and check connectivity with the Gazebo plugin running on192.168.198.129and port14581.

    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 thePositionandSelfCollideparameters of theunit_boxmodel.

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

    Retrieve the values of thePositionandSelfCollideparameters of theunit_boxmodel.

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

    Assign and Retrieve Gazebo Model Link Information

    List the links available in theunit_boxmodel.

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

    Assign values to the link parametersMassandGravityof the linklinkin theunit_boxmodel.

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

    Retrieve the values of the link parametersMassandGravityof the linklinkin theunit_boxmodel.

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

    Assign and Retrieve Gazebo Model Joint Information

    List the joints available in theunit_boxmodel.

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

    Assign a value to the joint parameter阻尼of the axisAxis0for the jointjointin theunit_boxmodel.

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

    Retrieve the value of the joint parameter阻尼of the axisAxis0for the jointjointin theunit_boxmodel.

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

    Reset all Gazebo model configurations.

    gzworld("reset")

    Limitations

    • gzworldfunction not supported withMATLAB®Compiler™.

    Version History

    Introduced in R2021a