source: orbit/octave/GenerateAudioCommand/throttleYawPitch.m @ 389c84b

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 389c84b was 389c84b, checked in by AzureViolin <zhanghaotz@…>, 8 years ago

auto generate wav from throttle, pitch and yaw

  • 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
10  %throttle
11for n=1:7
12mainCode=bitset(mainCode,21+n,bitget(throttle,n));%getting the first 7 digits to mainCode
13endfor 
14
15
16  mainCode=bitset(mainCode,21,1);  %meaning unclear, possibly left button.
17 
18  %channel selection first half
19  if (_channel=='C') mainCode=bitset(mainCode,20,1);
20  else mainCode=bitset(mainCode,20,0); %this digit equals 0 in channel A or B
21  endif
22
23for n=1:7
24mainCode=bitset(mainCode,12+n,bitget(yaw,n));%yaw
25endfor
26
27  %channel selection second half
28  if (_channel=='A') mainCode=bitset(mainCode,12,1);
29  else mainCode=bitset(mainCode,12,0); %if channel B or C, this digit equals 0;
30endif
31 
32  mainCode=bitset(mainCode,11,0);% meaning unclear, possibly right button.
33 
34for n=1:6
35mainCode=bitset(mainCode,4+n,bitget(pitch,n));%pitch 
36endfor
37
38  % CheckSum
39  for n=1:6  checkSum += bitand(bitshift(mainCode,-(4*n)),15);%sum up every 4 digits in the code
40  endfor
41
42  checkSum=bitand(checkSum,15); %get the last 4 bits of the sum
43  checkSum=bitand(bitcmp(checkSum,4)+1,15);%16-sum is the formula of this helicopter
44  for n=1:4
45  mainCode=bitset(mainCode,n,bitget(checkSum,n)); %get the last 4 digit of CheckSum
46 endfor
47  codeString=dec2bin(mainCode);
48code=[];
49for n=1:28
50code=[code str2num(codeString(n))];
51endfor
Note: See TracBrowser for help on using the repository browser.