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@33:d939479e7b13, 2017-03-01 (annotated)
- Committer:
- naoya1687
- Date:
- Wed Mar 01 08:05:52 2017 +0000
- Revision:
- 33:d939479e7b13
- Parent:
- 32:13aba70baa4b
- Child:
- 34:770a6bbb4d63
BatteryChecker.h???twelite_sensors??
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 | 33:d939479e7b13 | 12 | //cadence,ultsonicまわりをfloatにかえる |
naoya1687 | 31:cef6ee7af014 | 13 | |
shimogamo | 17:887cfe1d309f | 14 | //タスクの数に上限があるっぽい(6個以下) |
naoya1687 | 27:5b897e2e0ac6 | 15 | // |
shimogamo | 14:11e71bf840b2 | 16 | |
shimogamo | 0:2a15bd367891 | 17 | #include "mbed.h" |
shimogamo | 0:2a15bd367891 | 18 | #include "rtos.h" |
shimogamo | 0:2a15bd367891 | 19 | #include "Global.h" |
shimogamo | 9:d1fc0805ec7d | 20 | #include "Init.h" |
shimogamo | 0:2a15bd367891 | 21 | #include "ServoManager.h" |
shimogamo | 0:2a15bd367891 | 22 | #include "ControllerManager.h" |
shimogamo | 0:2a15bd367891 | 23 | #include "Trim.h" |
shimogamo | 0:2a15bd367891 | 24 | #include "Airspeed.h" |
shimogamo | 15:e73408fc6008 | 25 | #include "Atmpress.h" |
shimogamo | 0:2a15bd367891 | 26 | #include "Display.h" |
naoya1687 | 31:cef6ee7af014 | 27 | //#include "Selector.h" |
naoya1687 | 30:6d3a78bc1925 | 28 | #include "TweLite_Sensors.h" |
naoya1687 | 31:cef6ee7af014 | 29 | #define CADENCE 0 |
naoya1687 | 31:cef6ee7af014 | 30 | #define ULTSONIC 1 |
shimogamo | 5:9a1ec02229dd | 31 | |
shimogamo | 5:9a1ec02229dd | 32 | |
shimogamo | 5:9a1ec02229dd | 33 | RawSerial pc(USBTX, USBRX); |
shimogamo | 0:2a15bd367891 | 34 | |
naoya1687 | 31:cef6ee7af014 | 35 | Atmpress atmpress(PB_7, PA_15);//sda, scl |
naoya1687 | 31:cef6ee7af014 | 36 | Display display(PC_4, PA_10, NC);//tx, rx, sw |
naoya1687 | 31:cef6ee7af014 | 37 | ControllerManager controllerManager(PC_0,PC_1,PA_4,PA_1);//ele, rud, eletrimup, eletrimdown |
naoya1687 | 32:13aba70baa4b | 38 | ServoManager servoManager(p21, p22);//ele, rud // 要変更 |
naoya1687 | 31:cef6ee7af014 | 39 | //Selector selector(p25); |
naoya1687 | 31:cef6ee7af014 | 40 | DigitalOut wdt(PA_14); |
naoya1687 | 31:cef6ee7af014 | 41 | Airspeed airspeed(PA_13, NC, NC);//p19,p20をInterruptInに使ってはいけない |
naoya1687 | 31:cef6ee7af014 | 42 | TweLite_Sensors tweLite_Sensors(PC_12,PD_2); |
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(); |
naoya1687 | 32:13aba70baa4b | 66 | servoManager.update(); |
naoya1687 | 31:cef6ee7af014 | 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 | 15:e73408fc6008 | 77 | atmpress.update(); |
shimogamo | 9:d1fc0805ec7d | 78 | Thread::wait(500); |
shimogamo | 0:2a15bd367891 | 79 | } |
shimogamo | 0:2a15bd367891 | 80 | } |
shimogamo | 14:11e71bf840b2 | 81 | |
naoya1687 | 33:d939479e7b13 | 82 | void twesensorTask(void const *pvParameters){ |
naoya1687 | 33:d939479e7b13 | 83 | while(1){ |
naoya1687 | 33:d939479e7b13 | 84 | tweLite_Sensors.update();//こっちでそれぞれのbatteryをupdata |
naoya1687 | 33:d939479e7b13 | 85 | } |
naoya1687 | 33:d939479e7b13 | 86 | } |
naoya1687 | 33:d939479e7b13 | 87 | |
shimogamo | 0:2a15bd367891 | 88 | |
shimogamo | 0:2a15bd367891 | 89 | void displayTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 90 | while(1){ |
shimogamo | 0:2a15bd367891 | 91 | display.update(); |
shimogamo | 13:a8e10a69df45 | 92 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 93 | } |
shimogamo | 0:2a15bd367891 | 94 | } |
shimogamo | 0:2a15bd367891 | 95 | |
shimogamo | 0:2a15bd367891 | 96 | |
shimogamo | 0:2a15bd367891 | 97 | |
shimogamo | 0:2a15bd367891 | 98 | int main(void){ |
shimogamo | 0:2a15bd367891 | 99 | printf("start\n"); |
shimogamo | 5:9a1ec02229dd | 100 | pc.attach(pc_rx,Serial::RxIrq); |
shimogamo | 5:9a1ec02229dd | 101 | |
shimogamo | 6:0d9fa7152934 | 102 | Global::initialize(); |
shimogamo | 5:9a1ec02229dd | 103 | Thread InitializeTask(initializeTask); |
shimogamo | 9:d1fc0805ec7d | 104 | Thread ControlTask(controlTask, NULL, osPriorityRealtime); |
shimogamo | 14:11e71bf840b2 | 105 | Thread SensorTask500(sensorTask500); |
naoya1687 | 33:d939479e7b13 | 106 | Thread TwesensorTask(twesensorTask); |
shimogamo | 0:2a15bd367891 | 107 | Thread DisplayTask(displayTask); |
shimogamo | 0:2a15bd367891 | 108 | printf("Task end\n"); |
shimogamo | 0:2a15bd367891 | 109 | |
shimogamo | 0:2a15bd367891 | 110 | Thread::wait(osWaitForever); |
shimogamo | 0:2a15bd367891 | 111 | } |