關(guān)于電調(diào)的控制信號(hào):電調(diào)信號(hào)是pwm信號(hào),信號(hào)頻率為50Hz,一個(gè)周期為20ms。對(duì)于電調(diào)來(lái)講,高電平脈寬為1ms表示停轉(zhuǎn),高電平脈寬為2ms表示滿油門(mén)運(yùn)轉(zhuǎn);對(duì)于舵機(jī)來(lái)說(shuō)1.5ms是歸中,1ms和2ms分別為左右滿舵。(因此下面才直接用Servo庫(kù)來(lái)給實(shí)現(xiàn)ESC信號(hào)的輸出)。
arduino.png (74.11 KB, 下載次數(shù): 111)
下載附件
2018-11-14 18:45 上傳
關(guān)于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. } 補(bǔ)充:電調(diào)1ms停轉(zhuǎn),2ms滿油門(mén)運(yùn)轉(zhuǎn),是指的單向電調(diào),且是方波脈沖。而一般雙向電調(diào),1ms反轉(zhuǎn)最大油門(mén),1.5油門(mén)中點(diǎn),2ms滿油門(mén)正轉(zhuǎn)。
|