關于電調的控制信號:電調信號是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滿油門正轉。
|