function [x, y, theta, r, phi, state] = motionModel(v,omega,xold,yold,thetaold,dt,state)

[numRobots,z] = size(v);

wheelMax = [100; 100];
wheelMin = [-100; -100];

R = 2.5;
L = 12;

transform = [ R/2 R/2; -R/L R/L];
inverseTransform = inv(transform);

for i=1:numRobots,
	
    wheels = inverseTransform * [v(i); omega(i)];
    wheels = min(wheels, wheelMax);
	wheels = max(wheels, wheelMin);
	q = transform * wheels;
	v(i) = q(1);
	omega(i) = q(2);
	
end 


x = zeros(numRobots,1);
y = zeros(numRobots,1);
theta = zeros(numRobots,1);
r = zeros(numRobots,1);
phi = zeros(numRobots,1);

for i=1:numRobots,

    x(i) = xold(i) + cos(thetaold(i))*v(i)*dt;
    y(i) = yold(i) + sin(thetaold(i))*v(i)*dt;
    theta(i) = thetaold(i) + omega(i)*dt;
    
    r(i) = sqrt((x(i)-x(1))^2 + (y(i)-y(1))^2);
    phi(i) = theta(1) - atan2(y(i)-y(1), x(i)-x(1));

end

end