Refactored MATLAB client to use the Java client internally.
- Still need to implement selectDATA for all languages.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
function [ status ] = sendCTRL( ctrl, acft, IP, port )
|
||||
% sendCTRL Send X-Plane Aircraft Control Commands over UDP
|
||||
function sendCTRL( ctrl, ac, socket )
|
||||
% sendCTRL Sends command to X-Plane setting control surfaces on the specified aircraft.
|
||||
%
|
||||
% Inputs
|
||||
% ctrl: control array where the elements are as follows:
|
||||
@@ -9,56 +9,44 @@ function [ status ] = sendCTRL( ctrl, acft, IP, port )
|
||||
% 4. Throttle [-1, 1]
|
||||
% 5. Gear (0=up, 1=down)
|
||||
% 6. Flaps [0, 1]
|
||||
% acft (optional): Aircraft # (default is 0; 0 = own aircraft)
|
||||
% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
|
||||
% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
|
||||
% ac (optional): The aircraft to set. 0 for the player aircraft.
|
||||
% socket (optional): The client to use when sending the command.
|
||||
%
|
||||
% Outputs
|
||||
% status: If there was an error. Status<0 means there was an error.
|
||||
%
|
||||
% Use
|
||||
% 1. import XPlaneConnect.*;
|
||||
% 2. #Send the data array to port 49009 on the computer at IP address 172.0.100.54.
|
||||
% 3. status = sendCTRL([0, 0, 0, 0.8, 0, 1], 1, '172.0.100.54',49009);
|
||||
% 2. socket = openUDP();
|
||||
% 3. status = sendCTRL([0, 0, 0, 0.8, 0, 1], 0, socket); % Set throttle and flaps on the player aircraft.
|
||||
%
|
||||
% Note: send the value -998 to not overwrite that parameter. That is, if -998 is sent, the parameter will stay at the current X-Plane value
|
||||
% Note: send the value -998 to not overwrite that parameter. That is, if
|
||||
% -998 is sent, the parameter will stay at the current X-Plane value.
|
||||
%
|
||||
% Contributors
|
||||
% [CT] Christopher Teubert (SGT, Inc.)
|
||||
% christopher.a.teubert@nasa.gov
|
||||
%
|
||||
% To Do
|
||||
% 1. Verify Input
|
||||
%
|
||||
% BEGIN CODE
|
||||
% Christopher Teubert (SGT, Inc.) <christopher.a.teubert@nasa.gov>
|
||||
% Jason Watkins <jason.w.watkins@nasa.gov>
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Handle Input
|
||||
% Optional parameters
|
||||
if ~exist('IP','var'), IP = '127.0.0.1'; end
|
||||
if ~exist('port','var'), port = 49009; end
|
||||
if ~exist('acft','var'), acft = 0; end
|
||||
|
||||
% Check format of input-TODO
|
||||
|
||||
%%BODY
|
||||
header = ['CTRL'-0,0];
|
||||
dataStream = header; %TODO-ADD ACFT
|
||||
|
||||
% Deal with position update
|
||||
control = [-998.5, -998.5, -998.5, -998.5, -998.5, -998.5];
|
||||
|
||||
for i=1:min(length(ctrl),length(control))
|
||||
control(i) = ctrl(i);
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(istrue(length(clients) < 2), '[sendCTRL] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
openUDP();
|
||||
end
|
||||
dataStream = [dataStream, typecast(single(control(1:4)),'uint8')];
|
||||
dataStream = [dataStream, uint8(control(5))];
|
||||
dataStream = [dataStream, typecast(single(control(6)),'uint8')];
|
||||
dataStream = [dataStream, uint8(acft)];
|
||||
|
||||
% Send DATA
|
||||
status = sendUDP(dataStream, IP, port);
|
||||
|
||||
socket = clients(1);
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
ctrl = single(ctrl);
|
||||
if ~exist('ac', 'var')
|
||||
ac = 0;
|
||||
end
|
||||
ac = logical(ac);
|
||||
|
||||
%% Send command
|
||||
socket.sendCTRL(ctrl, ac);
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user