Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
rc.h
00001 Timer tick; 00002 InterruptIn rc(p11); 00003 short buf_ppm[6]; 00004 char i = 0, idx, cnt = 0; 00005 00006 void get_PPM(){ 00007 switch (idx){ 00008 case 1: 00009 RC.roll = buf_ppm[2]; 00010 RC.throttle = buf_ppm[3]; 00011 RC.pitch = buf_ppm[4]; 00012 RC.yaw = buf_ppm[5]; 00013 RC.sw = buf_ppm[0]; 00014 break; 00015 00016 case 2: 00017 RC.roll = buf_ppm[3]; 00018 RC.throttle = buf_ppm[4]; 00019 RC.pitch = buf_ppm[5]; 00020 RC.yaw = buf_ppm[0]; 00021 RC.sw = buf_ppm[1]; 00022 break; 00023 00024 case 3: 00025 RC.roll = buf_ppm[4]; 00026 RC.throttle = buf_ppm[5]; 00027 RC.pitch = buf_ppm[0]; 00028 RC.yaw = buf_ppm[1]; 00029 RC.sw = buf_ppm[2]; 00030 break; 00031 00032 case 4: 00033 RC.roll = buf_ppm[5]; 00034 RC.throttle = buf_ppm[0]; 00035 RC.pitch = buf_ppm[1]; 00036 RC.yaw = buf_ppm[2]; 00037 RC.sw = buf_ppm[3]; 00038 break; 00039 00040 case 5: 00041 RC.roll = buf_ppm[0]; 00042 RC.throttle = buf_ppm[1]; 00043 RC.pitch = buf_ppm[2]; 00044 RC.yaw = buf_ppm[3]; 00045 RC.sw = buf_ppm[4]; 00046 break; 00047 00048 case 0: 00049 RC.roll = buf_ppm[1]; 00050 RC.throttle = buf_ppm[2]; 00051 RC.pitch = buf_ppm[3]; 00052 RC.yaw = buf_ppm[4]; 00053 RC.sw = buf_ppm[5]; 00054 break; 00055 00056 default: break; 00057 } 00058 return; 00059 } 00060 00061 void getrc(){ 00062 RC.rolls = (RC.roll - 1518) * 0.73; 00063 RC.throttles = (RC.throttle - 1105) * 0.3; 00064 RC.pitchs = (RC.pitch - 1514) * 0.73; 00065 RC.yaws = (RC.yaw - 1518) * 0.73; 00066 RC.sws = RC.sw - 1518; 00067 return; 00068 } 00069 00070 00071 short rc_roll(){ 00072 return (short)(RC.roll);// 1518); 00073 } 00074 00075 short rc_throttle(){ 00076 return (short)(RC.throttle);// - 1105); 00077 } 00078 00079 short rc_pitch(){ 00080 return (short)(RC.pitch);// - 1514); 00081 } 00082 00083 short rc_yaw(){ 00084 return (short)(RC.yaw);// - 1518); 00085 } 00086 00087 short rc_sw(){ 00088 return (short)(RC.sw);// - 1518); 00089 } 00090 00091 00092 void PPM_rise() { 00093 tick.stop(); // Stop timer 00094 buf_ppm[i]=tick.read_us(); // Read timer to buffer[i] i=turns 00095 tick.reset(); // Reset timer 00096 tick.start(); // Start timer 00097 i++; // increment i. 00098 if(buf_ppm[i]>5000) idx = i; 00099 if(i==6) i = 0; 00100 get_PPM(); 00101 return; 00102 } 00103 00104 00105 /* 00106 Channel 1 = Roll 00107 Channel 2 = Throttle 00108 Channel 3 = Pitch 00109 Channel 4 = Yaw 00110 Channel 5 = Switch 00111 */
Generated on Sun Jul 17 2022 00:27:14 by
