I am trying to simulate the motion of a sphere on a flat surface under an applied torque T = [Tx, Ty, Tz] expressed in the body coordinate frame, and a viscous damping force F = [Fx, Fy, Fz] expressed in the inertial reference frame.
I created a sphere model in CoppeliaSim 4.9.0 (rev. 6) and used the MATLAB Remote API to run the simulation. In parallel, I built the same system in MATLAB SimScape Multibody and also derived the analytical dynamic model of the sphere. The results from SimScape match the analytical model very closely.
However, the simulation results in CoppeliaSim differ significantly from both the SimScape model and the analytical dynamics. I have tested both the Bullet 2.78 and 2.83, and MuJoCo physics engines, and although they agree with each other, their results still do not match the MATLAB-based simulations.
Here is the MATLAB code I developed to perform the simulations:
Code: Select all
close all
clear
clc
tf = 15;
Dt = 0.05;
sigma = 1;
Ms = 2;
Rs = 0.3;
g = 9.81;
% Stablish a Connection to V-REP:
client = RemoteAPIClient();
sim = client.getObject('sim');
client.setStepping(true);
sim.startSimulation();
% Get objects Handle:
Sphere_handle = sim.getObject("/Sphere");
% Start V-REP Simulation:
N = fix(tf / Dt) + 1;
SR_trajectory = zeros(N, 3);
i = 1;
for t = 0: Dt: tf
Pc = sim.getObjectPosition(Sphere_handle, sim.handle_world);
Vc = sim.getObjectVelocity(Sphere_handle, sim.handle_world);
Vx = Vc{1};
Vy = Vc{2};
Vz = Vc{3};
Zc = Pc{3};
local_Tx = 0.03 * t;
local_Ty = -0.5 * cos(t);
local_Tz = 0.06 * sin(1.2*t);
Fx = -sigma * Vx;
Fy = -sigma * Vy;
Fz = 0;
local_T = [local_Tx, local_Ty, local_Tz]';
F = [Fx, Fy, Fz]';
matrix = sim.getObjectMatrix(Sphere_handle, -1);
R = [matrix{1}, matrix{2}, matrix{3};
matrix{5}, matrix{6}, matrix{7};
matrix{9}, matrix{10}, matrix{11}];
T = R * local_T;
sim.addForceAndTorque(Sphere_handle, F, T);
client.step();
Position = sim.getObjectPosition(Sphere_handle, sim.handle_world);
X = Position{1};
Y = Position{2};
SR_trajectory(i, :) = [t, X, Y];
i = i + 1;
end
sim.stopSimulation();
plot(SR_trajectory(:,2), SR_trajectory(:, 3), 'blue', 'Marker','o')
Thanks.