source: orbit/octave/GenerateAudioCommand/throttleYawPitch.m @ 33cfd5c

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 33cfd5c was 33cfd5c, checked in by dorabot <dorabot@…>, 8 years ago

fix bug and update read.me

  • Property mode set to 100644
File size: 1.4 KB
Line 
1%Copyright: Puzzlebox Productions LLC
2%This code is released under GPL v2.
3%Nov. 29th, 2012
4
5function code=throttleYawPitch(throttle,yaw,pitch,_channel)
6
7  checkSum=0;
8 mainCode=0;
9
10mainCode=bitset(mainCode,29,1);
11  %throttle
12for n=1:7
13mainCode=bitset(mainCode,21+n,bitget(throttle,n));%getting the first 7 digits to mainCode
14endfor 
15
16
17  mainCode=bitset(mainCode,21,1);  %meaning unclear, possibly left button.
18 
19  %channel selection first half
20  if (_channel=='C') mainCode=bitset(mainCode,20,1);
21  else mainCode=bitset(mainCode,20,0); %this digit equals 0 in channel A or B
22  endif
23
24for n=1:7
25mainCode=bitset(mainCode,12+n,bitget(yaw,n));%yaw
26endfor
27
28  %channel selection second half
29  if (_channel=='A') mainCode=bitset(mainCode,12,1);
30  else mainCode=bitset(mainCode,12,0); %if channel B or C, this digit equals 0;
31endif
32 
33  mainCode=bitset(mainCode,11,0);% meaning unclear, possibly right button.
34 
35for n=1:6
36mainCode=bitset(mainCode,4+n,bitget(pitch,n));%pitch 
37endfor
38
39  % CheckSum
40  for n=1:6  checkSum += bitand(bitshift(mainCode,-(4*n)),15);%sum up every 4 digits in the code
41  endfor
42
43  checkSum=bitand(checkSum,15); %get the last 4 bits of the sum
44  checkSum=bitand(bitcmp(checkSum,4)+1,15);%16-sum is the formula of this helicopter
45  for n=1:4
46  mainCode=bitset(mainCode,n,bitget(checkSum,n)); %get the last 4 digit of CheckSum
47 endfor
48  codeString=dec2bin(mainCode);
49code=[];
50for n=2:29
51code=[code str2num(codeString(n))];
52endfor
Note: See TracBrowser for help on using the repository browser.