function [ new_agent, keepTurning, lastDistanceStraight, lastDistanceRight,...
    lastDistanceLeft ] = LeftSensorControl(  t, dt, agent, rectangles,...
    numberOfRectangles, target, keepTurning, lastDistanceStraight,...
    lastDistanceRight, lastDistanceLeft)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
    uMax = 1;
    ignoreDistance = 3*uMax;
    
    %get agent's info
    x = agent(t-1, 1);
    y = agent(t-1, 2);
    v = agent(t-1, 3);
    theta1 = agent(t-1, 4);   
    u = agent(t-1, 5);  
    
    %calculate new info except curvature
    theta2 = theta1 + u*v*dt;
    agent(t, 1) = x + v*dt*cos(theta1);
    agent(t, 2) = y + v*dt*sin(theta1);
	agent(t, 3) = v;
	agent(t, 4) = theta2;
    
    %calculate theta to target
    targetx = target(1);
    targety = target(2);
    thetaToTarget = atan((targety-y)/(targetx-x)) - theta1;
    if (targetx - x) < 0
        thetaToTarget = thetaToTarget + pi;
    end
    thetaToTarget = mod(thetaToTarget, 2*pi);
    %stop if very near target
    if (abs(x - targetx) < 0.1 && abs(y - targety) < 0.1)
        agent(t, 3) = 0;
    end
        
    %find distances to barriers, straight, right and left
    distanceStraight = IRSensorAll(rectangles, numberOfRectangles,...
        agent(t,1), agent(t,2), agent(t,4));
    distanceRight = IRSensorRightAll(rectangles, numberOfRectangles,...
        agent(t,1), agent(t,2), agent(t,4));
    distanceLeft = IRSensorLeftAll(rectangles, numberOfRectangles,...
        agent(t,1), agent(t,2), agent(t,4));

end

