%% Perform Co-Simulation Between MATLAB and Gazebo
% 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")

% 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")

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

[position,selfcollide] = gzmodel("get","unit_box","Position","SelfCollide")

%
%% Assign and Retrieve Gazebo Model Link Information
% List the links available in the unit_box model.

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

% 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")

% 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")

%
%% Assign and Retrieve Gazebo Model Joint Information
% List the joints available in the unit_box model.

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

% 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)

% 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")

%
% Reset all Gazebo model configurations.

gzworld("reset")

%
% Copyright 2020 The MathWorks, Inc.