-
Notifications
You must be signed in to change notification settings - Fork 6
Tutorial2: Receive Feedback from Car model in MATLAB
Description: This tutorial shows how to receive joint states and link states during simulaton from Gazebo
Prerequisites: Controlling car model from MATLAB
keywords: Gazebo, MATLAB
Run Gazebo world file from previous tutorial.
gazebo tutorial.world
We start by creating the bridge between Matlab and Gazebo.
h = GazeboMatlabSimulator; %Creates a Matlab Bridge using a helper class
Next we apply a torque of 1 Nm to rear wheel joints for 1 second and get the state of joints at the end of the 1 second:
h.ActuatedJoints = [1;3];% The rear wheel joints
u = [1;1]; %Torques to be applied
[LinkData, JointData] = h.Step(1.0,u);%Simulate the trajectory for 1 second with u as the torque
The LinkData obtained in the above process is a cell of rigid body states of all the links mentioned in the tutorial.world from the previous section. In our case, we mentioned only one link i.e the car body link. The output of the LinkData can be deciphered using below code
>> LinkData =
[1x1 MatlabRigidBodyState]
>> LinkData{1}
MatlabRigidBodyState with properties:
position: [3x1 double]
orientation: [4x1 double]
linearvelocity: [3x1 double]
angularvelocity: [3x1 double]
>> LinkData{1}.position
0.9526
-0.0099
0.0490
>> LinkData{1}.linearvelocity
1.9013
-0.0404
-0.0057
>> LinkData{1}.angularvelocity
0.0037
-0.0101
-0.0361
Similar to link data, the joint data is the data of all the joints mentioned in the tutorial.world file. In our case we mentioned four joints in total. Hence the output is 2X4 matrix where each column gives the joint position and joint velocity.
JointData =
19.1124 -0.0058 18.9936 -0.0038
38.1564 0.0410 37.9543 -0.0088
Notice that since we applied torque to rear wheels they have large non zero angular velocity and the angle should be interpreted as modulo 2*pi.
Previous:controlling-rccar-from-MATLAB