function [ xnew G] = motion_diff( x, u )
%MOTION_DIFF Compute differential drive motion model

l = 0.1; % distance between both wheels

theta = x(3);
sl = u(1);
sr = u(2);

% YOUR CODE STARTS HERE %
deltaTheta= (sr-sl)/l;
r= (sl+sr)/(sr-sl) *l/2;
% fill this with the result of applying the motion model
if(sr==sl)
xnew= x+ [r*(sin(theta+deltaTheta)-sin(theta));
          r*(-cos(theta+deltaTheta)-cos(theta));
          deltaTheta];
else
xnew= x+[sl*cos(theta);
        sl*sin(theta);
        0];
end    
% fill this with the motion Jacobian G
% G=zeros(3,3)
G = [1,0,r*(cos(theta+deltaTheta)-cos(theta));
    0,1,r*(sin(theta+deltaTheta)-sin(theta));
    0,0,1];


% YOUR CODE ENDS HERE %     

end

