View Single Post
Old May 30, 2010, 03:33 PM
Darkstar2000 is offline
Find More Posts by Darkstar2000
Registered User
Germany
Joined Mar 2007
200 Posts
Howto identify IR codes - part 4

Ok lets go on with our little Howto. From the last part we know everything how to tell if there is a 1 and a 0 and when a new package starts. So if we just let mode2 run we actually only need the spaces: a space of less then 400Ás is a 0, a space greater then 400 but less then 1000Ás is a 1 and a space longer then 10000Ás means a new package begins. So lets print the bits and see if we can recognize a pattern while we move the controls:
Code:
./mode2 | awk '{if($1~/space/){if($2<400)printf"0";if($2>400&&$2<1000)printf"1";if($2>10000){printf"\n";next}}}'
The awk script does the following: IF the first column contains "space" then do something. If the number in the 2nd column is less then 400 print a "0", if it is between 400 and 1000 print a "1" and if it is greater then 10000 then go to the next line. If we let it run then something like this will be printed out:
Code:
001111110011111110000000
000111110011111110000000
001111110011111110000000
001111110011111110000000
01001100011111110011100
010011010011111111001101
010011000011111111110101
010011000011111111111110
010011000011111111111110
Most of the lines are 24 characters long so we ignore the lines with less or more characters. A little bit difficult to read isn't it? So lets insert some spaces to group the bits in hmm 3 groups of 8?
Code:
./mode2 | awk '{if($1~/space/){if($2<400)printf"0";if($2>400&&$2<1000)printf"1";if($2>10000){printf"\n";bit=0;next}if(bit==8||bit==16)printf" ";bit++}}'
Code:
01001100 00111111 11010100
01001100 00111111 11100000
01001100 00111111 11101110
01001100 00111111 11110100
01001100 00111111 11111000
01001100 00111111 11111011
01001100 00111111 11110111
Looks good eh? If we only move the throttle from idle to full power (all lines with less then 24bit cut out) we see this:
Code:
00111111 00111111 10000000
01001100 00111111 10011001
01001100 00111111 10110101
01001100 00111111 11101000
01001100 00111111 11110100
01001100 00111111 11111011
Hey, there is a pattern: the last seven bits are changing with moving the throttle: full down and everything is 0 and with increasing throttle the numbers go up. But what means the first bit in the 3rd group? Whatever control you move nothing happen, but try the channel switch: if channel A there is a 0 and if channel B there is a 1. The transmitter is always sending even if the throttle is zero (not like the SanHuan transmitter) but the other bits are not moving even if we move the stick around. So to identify the yaw and pitch we just move the throttle to max and hold it there. With throttle at max we try to move the stick only in the x axis (yaw) and thats what we see (moving from full left to full right):
Code:
01111110 00111111 01111110
01111011 00111111 01111110
01111001 00111111 01111110
00111111 00111111 01111110
00011011 00111111 01111111
00000000 00111111 01111110
Thats easy: full left means all 7 bits set and full right means all bits unset or in decimal numbers: full left is 127 and full right is 0. The first bit is always zero. The zero would be 63 (11111) but as soon as we only move the trim we see what happens: the trim directly affects the yaw axis, how simple!
The pitch axis is as simple as that:
Code:
01000001 01111000 01111111
01000001 00111111 01111110
01000001 00101101 01111110
01000001 00000000 01111110
Full forward means (nearly) all bits set. Ok the lower three are not but this could also be a problem of the physical limits of the stick movement. Middle position is 63 and full backward is 0. And also here the 1st bit is 0.

It's done! The IR protocol is so simple that it will be very easy to implement. To sum up:

Bit Meaning
0 First bit always zero (in all protocols I have seen so far)
1-7 Yaw axis, full left is 127, full right is 0, trim changes the middle position around 63
8 Always zero
9-15 Pitch axis, full backward is 127 (probably), full forward is 0, middle position is 63
16 Channel (A = 0, B = 1)
17-24 Throttle ranging from 0 to 127

Next part will be the way how we put these numbers into a byte structure.
Darkstar2000 is offline Find More Posts by Darkstar2000
Last edited by Darkstar2000; Jun 01, 2010 at 07:01 AM. Reason: Pitch axis reversed
Reply With Quote