Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@41:013df90be273, 2017-03-25 (annotated)
- Committer:
- shimogamo
- Date:
- Sat Mar 25 07:09:30 2017 +0000
- Revision:
- 41:013df90be273
- Parent:
- 40:fa6c39f853f1
marge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimogamo | 12:8e39bb45c61c | 1 | //@todo Initのコマンドモード化or別プログラム化 |
shimogamo | 17:887cfe1d309f | 2 | //@todo Initで設定した値の反映をスマートに(ServoMやControllerMでupdate毎にGlobalから設定値を取り込むのではなく,paramSet的な関数を作って更新時に呼び出し) |
shimogamo | 17:887cfe1d309f | 3 | //てかそもそもInit情報Globalに入れる必要ないのでは? |
shimogamo | 10:0a4bf8c82493 | 4 | |
shimogamo | 12:8e39bb45c61c | 5 | //@todo Cadence, Airspeed内でNC,Encorderクラスから継承 |
shimogamo | 16:7e36177b4435 | 6 | //@todo Buttonクラスを作り,TrimとSelectorの親クラスにする |
shimogamo | 12:8e39bb45c61c | 7 | |
shimogamo | 12:8e39bb45c61c | 8 | //@todo 使っているライブラリの関数の説明追加 |
shimogamo | 12:8e39bb45c61c | 9 | |
naoya1687 | 32:13aba70baa4b | 10 | //servo回りはシリアルに変更 |
naoya1687 | 32:13aba70baa4b | 11 | //selector周りはコメントアウトしてる |
naoya1687 | 31:cef6ee7af014 | 12 | |
shimogamo | 17:887cfe1d309f | 13 | //タスクの数に上限があるっぽい(6個以下) |
naoya1687 | 27:5b897e2e0ac6 | 14 | // |
shimogamo | 14:11e71bf840b2 | 15 | |
shimogamo | 0:2a15bd367891 | 16 | #include "mbed.h" |
shimogamo | 0:2a15bd367891 | 17 | #include "rtos.h" |
shimogamo | 0:2a15bd367891 | 18 | #include "Global.h" |
shimogamo | 9:d1fc0805ec7d | 19 | #include "Init.h" |
naoya1687 | 34:770a6bbb4d63 | 20 | #include "ServoSend.h" |
shimogamo | 0:2a15bd367891 | 21 | #include "ControllerManager.h" |
shimogamo | 0:2a15bd367891 | 22 | #include "Trim.h" |
shimogamo | 0:2a15bd367891 | 23 | #include "Airspeed.h" |
shimogamo | 15:e73408fc6008 | 24 | #include "Atmpress.h" |
shimogamo | 0:2a15bd367891 | 25 | #include "Display.h" |
naoya1687 | 31:cef6ee7af014 | 26 | //#include "Selector.h" |
naoya1687 | 30:6d3a78bc1925 | 27 | #include "TweLite_Sensors.h" |
shimogamo | 5:9a1ec02229dd | 28 | |
shimogamo | 5:9a1ec02229dd | 29 | RawSerial pc(USBTX, USBRX); |
shimogamo | 0:2a15bd367891 | 30 | |
naoya1687 | 31:cef6ee7af014 | 31 | Atmpress atmpress(PB_7, PA_15);//sda, scl |
naoya1687 | 31:cef6ee7af014 | 32 | Display display(PC_4, PA_10, NC);//tx, rx, sw |
naoya1687 | 31:cef6ee7af014 | 33 | ControllerManager controllerManager(PC_0,PC_1,PA_4,PA_1);//ele, rud, eletrimup, eletrimdown |
naoya1687 | 34:770a6bbb4d63 | 34 | ServoSend servoSend(PC_10, PC_11);//tx, rx |
naoya1687 | 31:cef6ee7af014 | 35 | //Selector selector(p25); |
naoya1687 | 31:cef6ee7af014 | 36 | DigitalOut wdt(PA_14); |
naoya1687 | 31:cef6ee7af014 | 37 | Airspeed airspeed(PA_13, NC, NC);//p19,p20をInterruptInに使ってはいけない |
naoya1687 | 31:cef6ee7af014 | 38 | TweLite_Sensors tweLite_Sensors(PC_12,PD_2); |
shimogamo | 35:63ccdae58da4 | 39 | //FlashMemoryのpin指定は Global.cpp 内 |
shimogamo | 16:7e36177b4435 | 40 | |
shimogamo | 5:9a1ec02229dd | 41 | void pc_rx(){ |
shimogamo | 5:9a1ec02229dd | 42 | while(pc.readable()==1){ |
shimogamo | 26:a53c3208ac35 | 43 | //コマンドモードのon,offはここに入れるといい |
shimogamo | 9:d1fc0805ec7d | 44 | char buf = (char)pc.getc(); |
naoya1687 | 34:770a6bbb4d63 | 45 | pc.putc(buf); |
shimogamo | 36:ad6b2b81bb89 | 46 | Global::initqueue.put((char*)buf); |
shimogamo | 0:2a15bd367891 | 47 | } |
shimogamo | 0:2a15bd367891 | 48 | } |
shimogamo | 0:2a15bd367891 | 49 | |
shimogamo | 5:9a1ec02229dd | 50 | |
shimogamo | 9:d1fc0805ec7d | 51 | |
shimogamo | 9:d1fc0805ec7d | 52 | void initializeTask(void const *pvParameters){ |
shimogamo | 5:9a1ec02229dd | 53 | while(1){ |
shimogamo | 9:d1fc0805ec7d | 54 | Init::getSerial(); |
shimogamo | 5:9a1ec02229dd | 55 | } |
shimogamo | 5:9a1ec02229dd | 56 | } |
shimogamo | 5:9a1ec02229dd | 57 | |
shimogamo | 0:2a15bd367891 | 58 | void controlTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 59 | while(1){ |
shimogamo | 15:e73408fc6008 | 60 | //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こる) |
shimogamo | 0:2a15bd367891 | 61 | controllerManager.update(); |
naoya1687 | 34:770a6bbb4d63 | 62 | servoSend.send(); |
naoya1687 | 31:cef6ee7af014 | 63 | //selector.update(); |
shimogamo | 26:a53c3208ac35 | 64 | wdt = !wdt;//ウォッチドッグタイマのkickに相当 |
shimogamo | 0:2a15bd367891 | 65 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 66 | } |
shimogamo | 0:2a15bd367891 | 67 | } |
shimogamo | 0:2a15bd367891 | 68 | |
shimogamo | 14:11e71bf840b2 | 69 | void sensorTask500(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 70 | while(1){ |
shimogamo | 0:2a15bd367891 | 71 | airspeed.update(); |
shimogamo | 15:e73408fc6008 | 72 | atmpress.update(); |
shimogamo | 9:d1fc0805ec7d | 73 | Thread::wait(500); |
shimogamo | 0:2a15bd367891 | 74 | } |
shimogamo | 0:2a15bd367891 | 75 | } |
shimogamo | 14:11e71bf840b2 | 76 | |
naoya1687 | 33:d939479e7b13 | 77 | void twesensorTask(void const *pvParameters){ |
naoya1687 | 33:d939479e7b13 | 78 | while(1){ |
shimogamo | 35:63ccdae58da4 | 79 | tweLite_Sensors.update(); |
shimogamo | 35:63ccdae58da4 | 80 | //こっちでそれぞれのbatteryをupdata |
shimogamo | 35:63ccdae58da4 | 81 | //更新周期はTickerのインターバルで指定 |
naoya1687 | 33:d939479e7b13 | 82 | } |
naoya1687 | 33:d939479e7b13 | 83 | } |
naoya1687 | 33:d939479e7b13 | 84 | |
shimogamo | 0:2a15bd367891 | 85 | |
shimogamo | 0:2a15bd367891 | 86 | void displayTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 87 | while(1){ |
shimogamo | 0:2a15bd367891 | 88 | display.update(); |
shimogamo | 13:a8e10a69df45 | 89 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 90 | } |
shimogamo | 0:2a15bd367891 | 91 | } |
shimogamo | 0:2a15bd367891 | 92 | |
shimogamo | 0:2a15bd367891 | 93 | |
shimogamo | 0:2a15bd367891 | 94 | |
shimogamo | 0:2a15bd367891 | 95 | int main(void){ |
shimogamo | 35:63ccdae58da4 | 96 | pc.printf("start\n"); |
shimogamo | 5:9a1ec02229dd | 97 | pc.attach(pc_rx,Serial::RxIrq); |
shimogamo | 6:0d9fa7152934 | 98 | Global::initialize(); |
shimogamo | 5:9a1ec02229dd | 99 | Thread InitializeTask(initializeTask); |
shimogamo | 9:d1fc0805ec7d | 100 | Thread ControlTask(controlTask, NULL, osPriorityRealtime); |
shimogamo | 14:11e71bf840b2 | 101 | Thread SensorTask500(sensorTask500); |
naoya1687 | 33:d939479e7b13 | 102 | Thread TwesensorTask(twesensorTask); |
shimogamo | 0:2a15bd367891 | 103 | Thread DisplayTask(displayTask); |
shimogamo | 35:63ccdae58da4 | 104 | pc.printf("Task end\n"); |
shimogamo | 0:2a15bd367891 | 105 | |
shimogamo | 36:ad6b2b81bb89 | 106 | Thread::wait(osWaitForever); |
shimogamo | 0:2a15bd367891 | 107 | } |