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@18:d8a9c25d6137, 2016-05-10 (annotated)
- Committer:
- shimogamo
- Date:
- Tue May 10 07:50:40 2016 +0000
- Revision:
- 18:d8a9c25d6137
- Parent:
- 17:887cfe1d309f
- Child:
- 19:c6ad6b453b39
??????
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 | |
shimogamo | 17:887cfe1d309f | 10 | //タスクの数に上限があるっぽい(6個以下) |
shimogamo | 14:11e71bf840b2 | 11 | |
shimogamo | 0:2a15bd367891 | 12 | #include "mbed.h" |
shimogamo | 0:2a15bd367891 | 13 | #include "rtos.h" |
shimogamo | 0:2a15bd367891 | 14 | #include "Global.h" |
shimogamo | 9:d1fc0805ec7d | 15 | #include "Init.h" |
shimogamo | 0:2a15bd367891 | 16 | #include "ServoManager.h" |
shimogamo | 0:2a15bd367891 | 17 | #include "ControllerManager.h" |
shimogamo | 0:2a15bd367891 | 18 | #include "Trim.h" |
shimogamo | 0:2a15bd367891 | 19 | #include "Cadence.h" |
shimogamo | 0:2a15bd367891 | 20 | #include "Airspeed.h" |
shimogamo | 14:11e71bf840b2 | 21 | #include "Ultsonic.h" |
shimogamo | 15:e73408fc6008 | 22 | #include "Atmpress.h" |
shimogamo | 0:2a15bd367891 | 23 | #include "Display.h" |
shimogamo | 0:2a15bd367891 | 24 | #include "XBee.h" |
shimogamo | 16:7e36177b4435 | 25 | #include "Selector.h" |
shimogamo | 5:9a1ec02229dd | 26 | |
shimogamo | 5:9a1ec02229dd | 27 | |
shimogamo | 5:9a1ec02229dd | 28 | RawSerial pc(USBTX, USBRX); |
shimogamo | 0:2a15bd367891 | 29 | |
shimogamo | 15:e73408fc6008 | 30 | Atmpress atmpress(p9, p10);//sda, scl |
shimogamo | 17:887cfe1d309f | 31 | Display display(p13, p14, NC);//tx, rx, sw |
shimogamo | 12:8e39bb45c61c | 32 | ControllerManager controllerManager(p15,p16,p17,p18);//ele, rud, eletrimup, eletrimdown |
shimogamo | 15:e73408fc6008 | 33 | Ultsonic ultsonic(p20);//analogIn |
shimogamo | 12:8e39bb45c61c | 34 | ServoManager servoManager(p21, p22);//ele, rud |
shimogamo | 17:887cfe1d309f | 35 | Cadence cadence(p23, NC, NC);//p11, p12では動作しない=>使っていたmbedのピンが逝ってる可能性が微レ存 |
shimogamo | 16:7e36177b4435 | 36 | Selector selector(p25); |
shimogamo | 12:8e39bb45c61c | 37 | DigitalOut wdt(p26); |
shimogamo | 12:8e39bb45c61c | 38 | XBee xbee(p28, p27);//tx, rx |
shimogamo | 12:8e39bb45c61c | 39 | Airspeed airspeed(p29, NC, NC);//p19,p20をInterruptInに使ってはいけない |
shimogamo | 0:2a15bd367891 | 40 | |
shimogamo | 0:2a15bd367891 | 41 | |
shimogamo | 16:7e36177b4435 | 42 | |
shimogamo | 5:9a1ec02229dd | 43 | void pc_rx(){ |
shimogamo | 5:9a1ec02229dd | 44 | while(pc.readable()==1){ |
shimogamo | 10:0a4bf8c82493 | 45 | //コマンドモードのon,offはここに入れる |
shimogamo | 9:d1fc0805ec7d | 46 | char buf = (char)pc.getc(); |
shimogamo | 12:8e39bb45c61c | 47 | Global::initqueue.put((char*)buf); |
shimogamo | 0:2a15bd367891 | 48 | } |
shimogamo | 0:2a15bd367891 | 49 | } |
shimogamo | 0:2a15bd367891 | 50 | |
shimogamo | 5:9a1ec02229dd | 51 | |
shimogamo | 9:d1fc0805ec7d | 52 | |
shimogamo | 9:d1fc0805ec7d | 53 | void initializeTask(void const *pvParameters){ |
shimogamo | 5:9a1ec02229dd | 54 | while(1){ |
shimogamo | 9:d1fc0805ec7d | 55 | Init::getSerial(); |
shimogamo | 5:9a1ec02229dd | 56 | } |
shimogamo | 5:9a1ec02229dd | 57 | } |
shimogamo | 5:9a1ec02229dd | 58 | |
shimogamo | 0:2a15bd367891 | 59 | void controlTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 60 | while(1){ |
shimogamo | 15:e73408fc6008 | 61 | //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こる) |
shimogamo | 0:2a15bd367891 | 62 | controllerManager.update(); |
shimogamo | 0:2a15bd367891 | 63 | servoManager.update(); |
shimogamo | 17:887cfe1d309f | 64 | selector.update(); |
shimogamo | 12:8e39bb45c61c | 65 | wdt = !wdt; |
shimogamo | 0:2a15bd367891 | 66 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 67 | } |
shimogamo | 0:2a15bd367891 | 68 | } |
shimogamo | 0:2a15bd367891 | 69 | |
shimogamo | 14:11e71bf840b2 | 70 | void sensorTask500(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 71 | while(1){ |
shimogamo | 0:2a15bd367891 | 72 | airspeed.update(); |
shimogamo | 14:11e71bf840b2 | 73 | cadence.update(); |
shimogamo | 14:11e71bf840b2 | 74 | ultsonic.update(); |
shimogamo | 15:e73408fc6008 | 75 | atmpress.update(); |
shimogamo | 9:d1fc0805ec7d | 76 | Thread::wait(500); |
shimogamo | 0:2a15bd367891 | 77 | } |
shimogamo | 0:2a15bd367891 | 78 | } |
shimogamo | 14:11e71bf840b2 | 79 | |
shimogamo | 0:2a15bd367891 | 80 | |
shimogamo | 0:2a15bd367891 | 81 | void displayTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 82 | while(1){ |
shimogamo | 0:2a15bd367891 | 83 | display.update(); |
shimogamo | 13:a8e10a69df45 | 84 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 85 | } |
shimogamo | 0:2a15bd367891 | 86 | } |
shimogamo | 0:2a15bd367891 | 87 | |
shimogamo | 0:2a15bd367891 | 88 | void xbeeTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 89 | while(1){ |
shimogamo | 0:2a15bd367891 | 90 | xbee.update(); |
shimogamo | 13:a8e10a69df45 | 91 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 92 | } |
shimogamo | 0:2a15bd367891 | 93 | } |
shimogamo | 0:2a15bd367891 | 94 | |
shimogamo | 0:2a15bd367891 | 95 | |
shimogamo | 0:2a15bd367891 | 96 | int main(void){ |
shimogamo | 0:2a15bd367891 | 97 | printf("start\n"); |
shimogamo | 5:9a1ec02229dd | 98 | pc.attach(pc_rx,Serial::RxIrq); |
shimogamo | 5:9a1ec02229dd | 99 | |
shimogamo | 6:0d9fa7152934 | 100 | Global::initialize(); |
shimogamo | 5:9a1ec02229dd | 101 | Thread InitializeTask(initializeTask); |
shimogamo | 9:d1fc0805ec7d | 102 | Thread ControlTask(controlTask, NULL, osPriorityRealtime); |
shimogamo | 14:11e71bf840b2 | 103 | Thread SensorTask500(sensorTask500); |
shimogamo | 0:2a15bd367891 | 104 | Thread DisplayTask(displayTask); |
shimogamo | 0:2a15bd367891 | 105 | Thread XbeeTask(xbeeTask); |
shimogamo | 0:2a15bd367891 | 106 | printf("Task end\n"); |
shimogamo | 0:2a15bd367891 | 107 | |
shimogamo | 0:2a15bd367891 | 108 | Thread::wait(osWaitForever); |
shimogamo | 0:2a15bd367891 | 109 | } |