function Orient(x,y,min_err,vis_port,com_port,avg_spd,RobotId,Front,Back)
% Input:
%    x = X destination pixel
%    y = Y destination pixel
%    min_err = Minimum acceptable angle error in radians
%    vis_port = Port to the vision server
%    com_port = Port to the communication server
%    avg_spd = Robot average speed
%    RobotId = Radio Turret Id of robot to control
%    Front = Text Label of a dot on the robot's front
%    Back = Text Label of a dot on the robot's back
% Output:
%    The robot's angle is lined up with the given pixel with the min error
%% 
%% Simple align angle to point using prportinoal control
%% Copyright 2000  William Micheal Siever 

% Get the robot's current position
RobotFront=mVision('get',vis_port,Front);
RobotBack=mVision('get',vis_port,Back);
Rx=(RobotFront(1)+RobotFront(3)/2 + RobotBack(1)+RobotBack(3)/2)/2;
Ry=(RobotFront(2)+RobotFront(4)/2 + RobotBack(2)+RobotBack(4)/2)/2;
% Calculate Rt:
Rt=[RobotFront(1)-RobotBack(1) RobotFront(2)-RobotBack(2)];
Rt=Rt/sqrt(Rt*Rt');

% Determine the angle between the robot and the destination
delta_t=DeltaAngle(Rx,Ry,Rt,x,y);

while delta_t>min_err
    if delta_t>0
        lm=-avg_spd;
        rm=avg_spd;
    elseif delta_t<0
        lm=avg_spd;
        rm=-avg_spd;
    else
        lm=0;
        rm=0;
    end
    
    % motor velocities have to be integers
    lm=floor(lm);
    rm=floor(rm);

    if mComm('set',com_port,RobotId,lm,rm)~=0 
        disp('Error Setting Speed');
    end

    % Get the robot's current position
    RobotFront=mVision('get',vis_port,Front);
    RobotBack=mVision('get',vis_port,Back);
    Rx=(RobotFront(1)+RobotFront(3)/2 + RobotBack(1)+RobotBack(3)/2)/2;
    Ry=(RobotFront(2)+RobotFront(4)/2 + RobotBack(2)+RobotBack(4)/2)/2;
    % Calculate Rt:
    Rt=[RobotFront(1)-RobotBack(1) RobotFront(2)-RobotBack(2)];
    Rt=Rt/sqrt(Rt*Rt');

    % Determine the angle between the robot and the destination
    delta_t=DeltaAngle(Rx,Ry,Rt,x,y);
end

if mComm('set',com_port,RobotId,0,0)~=0 
    disp('Error Setting Speed');
end

