function Track(this, img, timestamp)

% Update the tracker with this frame
converged = this.LKtracker.track(img, ...
    'MaxIterations', 50, ...
    'ConvergenceTolerance', .25,...
    'ErrorTolerance', 0.5);

if converged
    set(this.h_title, 'String', 'Tracking Converged');
    
    corners = this.LKtracker.corners;
    
    set(this.h_track, ...
        'XData', corners([1 2 4 3 1],1), ...
        'YData', corners([1 2 4 3 1],2));
    
    [distError, midPointErr, angleError] = computeError(this);
    msgStruct = struct( ...
        'timestamp', timestamp, ...
        'x_distErr', single(distError), ...
        'y_horErr',  single(midPointErr), ...
        'angleErr',  single(angleError), ...
        'didTrackingSucceed', uint8(true));
    
    if msgStruct.x_distErr == 0 && msgStruct.y_horErr == 0 && msgStruct.angleErr == 0
       error('Sending all zero error signal with didTrackingSucceed=true.') 
    end
    
else
    set(this.h_title, 'String', 'Tracking Failed');
    msgStruct = struct( ...
        'timestamp', timestamp, ...
        'x_distErr', single(0), ...
        'y_horErr',  single(0), ...
        'angleErr',  single(0), ...
        'didTrackingSucceed', uint8(false));
    
    % We are expecting to start receiving detection images again, now that
    % tracking has failed
    this.desiredBufferSize = this.computeDesiredBufferLength(this.detectionResolution);
end


packet = this.SerializeMessageStruct(msgStruct);
this.SendPacket('CozmoMsg_DockingErrorSignal', packet);

end % FUNCTION Track()