跪求MK德国人程序中RC.c程序的解析
各位大神,小弟在论坛里游荡了半年,看各种大神发的关于四旋翼的帖子,很有帮助。今天是第一次发帖子跪求帮助,小弟玩四旋翼也有半年了,当初就是为了怕麻烦,没选用PPM信号接收机,而是通过无线串口模块接收遥控器信号,已经调试成功,但近日觉得串口的处理速度还是太慢,用PPM编码解码速度要快的多。所以重新观摩德国人的PPM解码程序,想要在它的基础上进行修改,但是发现在它接收到脉宽信号后的处理程序,就完全看不懂了,跪求大神们指导。上程序。#include "rc.h"
#include "main.h"
//#define ACT_S3D_SUMMENSIGNAL
volatile int PPM_in;
volatile int PPM_diff;// das diffenzierte Stick-Signal
volatile char Channels,tmpChannels = 0;
volatile unsigned char NewPpmData = 1;
//############################################################################
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
//Capture Funktion benutzt:
void rc_sum_init (void)
//############################################################################
{
#ifndef ACT_S3D_SUMMENSIGNAL
TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
#else
TCCR1B=(1<<CS11)|(0<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64
#endif
TIMSK1 |= _BV(ICIE1);
AdNeutralGier = 0;
AdNeutralRoll = 0;
AdNeutralNick = 0;
return;
}
#ifndef ACT_S3D_SUMMENSIGNAL
//############################################################################
//Diese Routine startet und inizialisiert den Timer f黵 RC
SIGNAL(SIG_INPUT_CAPTURE1)
//############################################################################
{
if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC))
{
static unsigned int AltICR=0;
signed int signal = 0,tmp;
static int index;
signal = (unsigned int) ICR1 - AltICR;
AltICR = ICR1;
//Syncronisationspause? (3.52 ms < signal < 25.6 ms)
if((signal > 1100) && (signal < 8000))
{
Channels = index;
if(index >= 4)NewPpmData = 0;// Null bedeutet: Neue Daten
index = 1;
}
else
{
if(index < 10)
{
if((signal > 250) && (signal < 687))
{
signal -= 466;
// Stabiles Signal
if(abs(signal - PPM_in) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
tmp = (3 * (PPM_in) + signal) / 4;
if(tmp > signal+1) tmp--; else
if(tmp < signal-1) tmp++;
if(SenderOkay >= 195)PPM_diff = ((tmp - PPM_in) / 3) * 3;
else PPM_diff = 0;
PPM_in = tmp;
}
index++;
if(index == 5) J3High; else J3Low;// Servosignal an J3 anlegen
if(index == 6) J4High; else J4Low;// Servosignal an J4 anlegen
if(index == 7) J5High; else J5Low;// Servosignal an J5 anlegen
}
}
}
else
{
static unsigned int AltICR=0;
static int ppm_in;
static int ppm_diff;
static int old_ppm_in;
static int old_ppm_diff;
signed int signal = 0,tmp;
static unsigned char index, okay_cnt = 0;
signal = (unsigned int) ICR1 - AltICR;
AltICR = ICR1;
//Syncronisationspause? (3.52 ms < signal < 25.6 ms)
if((signal > 1100) && (signal < 8000))
{
tmpChannels = index;
if(tmpChannels >= 4 && Channels == tmpChannels)
{
if(okay_cnt > 10)
{
NewPpmData = 0;// Null bedeutet: Neue Daten
for(index = 0; index < 11; index++)
{
if(okay_cnt > 30)
{
old_ppm_in = PPM_in;
old_ppm_diff = PPM_diff;
}
PPM_in = ppm_in;
PPM_diff = ppm_diff;
}
}
if(okay_cnt < 255) okay_cnt++;
}
else
{
if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0;
ROT_ON;
}
index = 1;
if(!MotorenEin) Channels = tmpChannels;
}
else
{
if(index < 10)
{
if((signal > 250) && (signal < 687))
{
signal -= 466;
// Stabiles Signal
if((abs(signal - ppm_in) < 6))
{
if(okay_cnt > 25)SenderOkay += 10;
else
if(okay_cnt > 10)SenderOkay += 2;
if(SenderOkay > 200) SenderOkay = 200;
}
tmp = (3 * (ppm_in) + signal) / 4;
if(tmp > signal+1) tmp--; else
if(tmp < signal-1) tmp++;
if(SenderOkay >= 190)ppm_diff = ((tmp - ppm_in) / 3) * 3;
else ppm_diff = 0;
ppm_in = tmp;
}
else ROT_ON;
if(index == 5) J3High; else J3Low;// Servosignal an J3 anlegen #define J3High PORTD |= 0x20
if(index == 6) J4High; else J4Low;// Servosignal an J4 anlegen
if(index == 7) J5High; else J5Low;// Servosignal an J5 anlegen
}
if(index < 20) index++;
else
if(index == 20)
{
unsigned char i;
ROT_ON;
index = 30;
for(i=0;i<11;i++) // restore from older data
{
PPM_in = old_ppm_in;
PPM_diff = 0;
// okay_cnt /= 2;
}
}
}
}
}
#else
//############################################################################
//Diese Routine startet und inizialisiert den Timer f黵 RC
SIGNAL(SIG_INPUT_CAPTURE1)
//############################################################################
{
static unsigned int AltICR=0;
signed int signal = 0,tmp;
static int index;
signal = (unsigned int) ICR1 - AltICR;
DebugOut.Analog = signal;
signal /= 2;
AltICR = ICR1;
//Syncronisationspause?
if((signal > 1100*2) && (signal < 8000*2))
{
if(index >= 4)NewPpmData = 0;// Null bedeutet: Neue Daten
index = 1;
}
else
{
if(index < 10)
{
if((signal > 250) && (signal < 687*2))
{
signal -= 962;
// Stabiles Signal
if(abs(signal - PPM_in) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
tmp = (3 * (PPM_in) + signal) / 4;
if(tmp > signal+1) tmp--; else
if(tmp < signal-1) tmp++;
if(SenderOkay >= 195)PPM_diff = ((tmp - PPM_in) / 3) * 3;
else PPM_diff = 0;
PPM_in = tmp;
}
index++;
}
}
}
#endif
其中的PPM_in[],PPM_diff[],SenderOkay ,index分别是起什么作用的呀?跪求大神能给上中文注释,小弟感激不尽。
页:
[1]