无线遥控便是运用高频无线电波完成对模型的操控。如六合飞的的6通道2.4 GHz遥控器,一套200多块,具有主动跳频抗搅扰才能,从理论上讲能够让上百人在同一场所一起遥控自己的模型而不会彼此搅扰。并且在遥控间隔方面也颇具优势,2.4 GHz遥控体系的功率仅仅在100 mW以下,而它的遥控间隔能够到达1km以上。
遥控器发射机、接收机原理
每个通道信号脉宽0~2ms,改变规模为1~2ms之间。1帧PPM信号长度为20ms,理论上最多能够有10个通道,可是同步脉冲也需求时刻,模型遥控器最多9个通道。
PPM格局
只连接了通道3(油门)
arduino要丈量脉宽时刻很简单。有专门的库函数pulseIn( )。问题在于这个库函数运用查询方法,程序在丈量期间一向陷在这儿,CPU运用率太低。因而下面代码选用中止方法,功率很高。
代码参阅:http://arduino.cc/forum/index.php/topic,42286.0.html
ARDUINO 代码仿制打印
-
//read PPM signals from 2 channels of an RC reciever
-
//http://arduino.cc/forum/index.php/topic,42286.0.html
-
-
//接收机两个通道别离接arduino的数字口2、3脚
-
//Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3).
-
//The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).
-
intppm1 =2;
-
intppm2 =3;
-
-
unsignedlongrc1_PulseStartTicks,rc2_PulseStartTicks;
-
volatileintrc1_val, rc2_val;
-
-
voidsetup(){
-
-
Serial.begin(9600); -
-
//PPM inputs from RC receiver -
pinMode(ppm1,INPUT); -
pinMode(ppm2,INPUT); -
-
// 电平改变即触发中止 -
attachInterrupt(0, rc1, CHANGE); -
attachInterrupt(1, rc2, CHANGE); -
}
-
-
voidrc1()
-
{
-
// did the pin change to high or low? -
if(digitalRead(ppm1)==HIGH) -
rc1_PulseStartTicks =micros(); // store the current micros() value -
else -
rc1_val =micros()- rc1_PulseStartTicks; -
}
-
-
voidrc2()
-
{
-
// did the pin change to high or low? -
if(digitalRead(ppm2)==HIGH) -
rc2_PulseStartTicks =micros(); -
else -
rc2_val =micros()- rc2_PulseStartTicks; -
}
-
-
voidloop(){
-
-
//print values -
Serial.print(“channel 1: “); -
Serial.print(rc1_val); -
Serial.print(“ “); -
Serial.print(“channel 2: “); -
Serial.println(rc2_val); -
}