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