Ardiuno: библиотека PPMint

Потребовалось с тренерского разъема Futaba T7C получить сигнал PPM и обработать его с помощью Arduino. Принял, обработал – за основу подсмотрел идеи из AeroQuad. В результате имею готовую библиотеку для работы с суммированным PWM – то, что я называю PPM.
Как это работает:
- ко входу D2 Arduino Uno подключаем сигнал с аппаратуры (проверено с Futaba T7C 2.4, Futaba 8FG)
- закачиваем файл PPMint.zip(внизу поста ссылка)
- распаковываем в “libraries
- в рабочем скетче делаем #include “PPMint.h”;, инициализируем объект PPMint ppm;
- используем по тексту программы конструкцию realRaw[номер канала]
Same in english here…
It took a trainer connector Futaba T7C get PPM signal and process it using the Arduino. Received, processed – the basis of ideas spied AeroQuad . As a result, I have finished the library to work with the summarized PWM – what I call the PPM.
How it works:
- to the input D2 Arduino Uno connect the signal from the equipment (tested with Futaba T7C 2.4, Futaba 8FG)
- upload files PPMint.zip (at the bottom of the post link)
- unpack in “libraries
- in working sketch do # include “PPMint.h”; , initialize the object PPMint ppm;
- use the text of the program structure realRaw [channel number]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #ifndef PPMint_h #define PPMint_h #include "Arduino.h" #define _CHA_NUM 10 #define _PPM_PIN 2 #define _PPM_INT 0 class PPMint { public: PPMint(); int realRaw[10]; void PPMinterrupt(void); void setup(); private: uint8_t prevRealRaw[10]; uint8_t currentChannel; unsigned long lastms,diffms; boolean sync; }; #endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 #include <PPMint.h> //BEGIN // only one instance allowed - some hack here static PPMint *pclass = 0; void ppmInterrupt() {// dummy function if (pclass) pclass->PPMinterrupt(); } //END PPMint::PPMint() { } //PPMint void PPMint::setup() { realRaw[10]=0,0,0,0,0,0,0,0,0,0; prevRealRaw[10]=0,0,0,0,0,0,0,0,0,0; currentChannel=0; lastms = 0; sync = false; pinMode(_PPM_PIN,INPUT); pclass=this; //create an pointer to func attachInterrupt(_PPM_INT,ppmInterrupt,RISING); while(!sync) { delay(100); } } void PPMint::PPMinterrupt() { //here real work to come ;) long nowms = micros(); diffms = nowms - lastms; if(lastms>0) { if(diffms>5000) { sync = true; currentChannel = 0; } else { if(sync) { if(diffms<=2000 && diffms>=1000) { realRaw[currentChannel] = diffms; } currentChannel++; } } } lastms = nowms; }//PPMinterrupt
1 2 3 4 5 6 7 8 9 10 11 12 #include <PPMint.h> PPMint ppm; void setup() { Serial.begin(9600); ppm.setup(); } void loop() { delay(30); Serial.print("Channel 0: "); Serial.println(ppm.realRaw[0]); }
Все – в деталях
В конструкторе не получается зацепить прерывания (есть предположения – почему – блок BEGIN / END внутри конструктора не канает).
All – in detail:) In the constructor fails to catch interrupts (the assumption is – why – block BEGIN / END inside the constructor is not the channel).
Обещанная ссылка PPMint.zip.
The promised link PPMint.zip.
Спс/Tnx
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
