LP-67 Change label and tooltips to EasyTune name
[librepilot.git] / matlab / GCSPlugin / GCSControl.m
blob39e89ffc17290643c3f0b9f3c2d9afe0647b4bc7
1 % GCSCONTROL
2 %  This class allows the user to send 4-axis stick commands to OpenPilot
3 %  GCS.
5 % Create class by
6 %    control = GCSControl
8 % Open connection by 
9 %    control.connect('01.23.45.67', 89)
10 % where the first value is the IP address of the computer running GCS and
11 % the second value is the port on which GCS is listening.
13 % Send command by
14 %    control.command(pitch, yaw, roll, throttle)
15 % where all variables are between [-1,1]
17 % Close connection by
18 %    control.close()
20 classdef GCSControl < handle
21     
22     properties
23         udpObj;
24         isConnected=false;
25     end
26     
27     methods
28         function obj=GCSControl()
29             obj.isConnected = false;
30         end
31         function obj=connect(obj,rhost,rport)
32             obj.udpObj = udp(rhost,rport);
33             fopen(obj.udpObj);
34             obj.isConnected = true;
35         end
36         function obj=command(obj,pitch,yaw,roll,throttle)
37             if(obj.isConnected)
38                 fwrite(obj.udpObj,[42,pitch,yaw,roll,throttle,36],'double')
39             end
40         end
41         function obj=close(obj)
42             if(obj.isConnected)
43                 fclose(obj.udpObj);
44                 obj.isConnected = false;
45             end
46         end
47     end
48 end