关于电调的控制信号:电调信号是pwm信号,信号频率为50Hz,一个周期为20ms。对于电调来讲,高电平脉宽为1ms表示停转,高电平脉宽为2ms表示满油门运转;对于舵机来说1.5ms是归中,1ms和2ms分别为左右满舵。(因此下面才直接用Servo库来给实现ESC信号的输出)。 关于Servo.write()和Servo.writeMicroseconds() 0.Servo.writeMicroseconds(): Writes a value in microseconds (uS) tothe servo, controlling the shaft accordingly. On a standard servo, this willset the angle of the shaft. On standard servos a parameter value of 1000 isfully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle. 1.servo.write() allows a maximum of 180 servo positions servo.writeMicroseconds() allows a maximum of 1000 servo positions 2.The "write" method simply maps the"degrees" to microseconds and calls the "writeMicroseconds"method anyway. The "degree" of turn is simply a convenientabstraction, and few bother to calibrate it. 控制程序:
1. #include<Servo.h> // Using servo library to control ESC 2. Servo esc; //Creating a servo class with name as esc 3. int val; //Creating a variable val 4. void setup() 5. { 6. esc.attach(9); //Specify the esc signal pin,Here as D9 7. esc.writeMicroseconds(1000);// initialize the signal to 1000 8. Serial.begin(9600); 9. } 10. void loop() 11. { 12. val=analogRead(A0); // Read input from analog pin a0 and store in val 13. val= map(val, 0,1023,1000,2000); // mapping val to minimum and maximum(Change if needed) 14. Serial.println(val); 15. esc.writeMicroseconds(val);// using val as the signal to esc 16. } 补充:电调1ms停转,2ms满油门运转,是指的单向电调,且是方波脉冲。而一般双向电调,1ms反转最大油门,1.5油门中点,2ms满油门正转。
|