function ExampleSend();
%ExampleSend - a simple example using the AVDSNetwork send functions
%
%  USAGE - This function runs a simple simulation and send out the resulting
%    vehicle packets on the local network. AVDS is used to view the vehicles.
%
%    - Run AVDS
%    - In AVDS, select "Network" and "Observer" modes. 
%    - Run ExampleSend()
%    - In AVDS, select the vehicle to view from AVDS's "Aircraft Image" menu:
%      select "Initialize->Aircraft Image"
%    - Press the AVDS Start button.
%
%  NOTE: The number of vehicles and trajectories can be changed in the PARAMETERS 
%    section below

%   Steve Rasmussen, April 2001
%   Copyright (c) 2001 by RasSimTech Ltd
%   $Revision: 1.0.0 $  $Date: 2001/04/15 00:00:00 $



%%%%%%%%%%%%%%
% PARAMETERS
%%%%%%%%%%%%%%

iNumberVehicles = 10;
%iNumberVehicles = 1;

iHorizontalSpacing = 50;
iVerticalSpacing = 10;
iInitAltitude = 1000;

NorthVelocity = 250.0;	%feet/sec	
EastVelocity = 0.0;	%feet/sec	
VerticalVelocity = 0.0;	%feet/sec

XAngularRate = 10.0; %degrees/sec
YAngularRate = 0.0; %degrees/sec
ZAngularRate = 0.0; %degrees/sec

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initialize vehicles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for (iCount = 1:iNumberVehicles),
   % This will cause AVDS to display a different type vehicle for each if that
   % number of vehicles is a vailable in the craftcap.txt file.
   VehicleType = iCount-1;
	VehicleID = iCount;
   InitLongitudeDegDecimal = -122.063400;
   InitLatitudeDegDecimal = 37.981523;
   Data2Network = [VehicleType,InitLongitudeDegDecimal,InitLatitudeDegDecimal,iInitAltitude];
   AVDSNetwork('InitializeVehicle',VehicleID,Data2Network);
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initailize vehicle trajectories
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NorthPosition = zeros(iNumberVehicles,1);
EastPosition = [iHorizontalSpacing:iHorizontalSpacing:iNumberVehicles*iHorizontalSpacing]';
UpPosition = [iNumberVehicles*iVerticalSpacing:-iVerticalSpacing:iVerticalSpacing]'+iInitAltitude;
XRotation = zeros(iNumberVehicles,1);
YRotation = zeros(iNumberVehicles,1);
ZRotation = zeros(iNumberVehicles,1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% build vehicle trajectories and store data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TimeIncrement = 0.1;

NorthVelocityInc = NorthVelocity*TimeIncrement;
EastVelocityInc = EastVelocity*TimeIncrement;
VerticalVelocityInc = VerticalVelocity*TimeIncrement;

XAngularRateInc = XAngularRate*TimeIncrement;
YAngularRateInc = YAngularRate*TimeIncrement;
ZAngularRateInc = ZAngularRate*TimeIncrement;

EngineLevel = 200;
DeltaElevator = 0;
DeltaAileron = 0;
DeltaRudder = 0;

for (CountTime = [0.0:TimeIncrement:30.0]),
   NorthPosition = NorthPosition + NorthVelocityInc;
   EastPosition = EastPosition + EastVelocityInc;
   UpPosition = UpPosition + VerticalVelocityInc;
   XRotation = XRotation + XAngularRateInc;
   YRotation = YRotation + YAngularRateInc;
   ZRotation = ZRotation + ZAngularRateInc;
   for (iEntities = 1:iNumberVehicles),
      VehicleID = iEntities;
      Data2Network = [NorthPosition(iEntities),EastPosition(iEntities),UpPosition(iEntities), ...
            XRotation(iEntities), YRotation(iEntities), ZRotation(iEntities), ...
            DeltaElevator,DeltaAileron,DeltaRudder,EngineLevel, ...
            0,0,0, ...
            0,0,0 ...
         ];
         AVDSNetwork('SendData',VehicleID,Data2Network);
      end;	%for (iEntities = 1:iNumberVehicles),
   pause(0.1);
end;	%for (CountTime = dTime1),

AVDSNetwork('CloseConnections');

return;		%ExampleSend