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@34:770a6bbb4d63, 2017-03-01 (annotated)
- Committer:
- naoya1687
- Date:
- Wed Mar 01 14:34:27 2017 +0000
- Revision:
- 34:770a6bbb4d63
- Parent:
- 33:d939479e7b13
- Child:
- 35:63ccdae58da4
ServoSend.h
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" |
naoya1687 | 34:770a6bbb4d63 | 21 | #include "ServoSend.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" |
shimogamo | 5:9a1ec02229dd | 29 | |
shimogamo | 5:9a1ec02229dd | 30 | |
shimogamo | 5:9a1ec02229dd | 31 | RawSerial pc(USBTX, USBRX); |
shimogamo | 0:2a15bd367891 | 32 | |
naoya1687 | 31:cef6ee7af014 | 33 | Atmpress atmpress(PB_7, PA_15);//sda, scl |
naoya1687 | 31:cef6ee7af014 | 34 | Display display(PC_4, PA_10, NC);//tx, rx, sw |
naoya1687 | 31:cef6ee7af014 | 35 | ControllerManager controllerManager(PC_0,PC_1,PA_4,PA_1);//ele, rud, eletrimup, eletrimdown |
naoya1687 | 34:770a6bbb4d63 | 36 | ServoSend servoSend(PC_10, PC_11);//tx, rx |
naoya1687 | 31:cef6ee7af014 | 37 | //Selector selector(p25); |
naoya1687 | 31:cef6ee7af014 | 38 | DigitalOut wdt(PA_14); |
naoya1687 | 31:cef6ee7af014 | 39 | Airspeed airspeed(PA_13, NC, NC);//p19,p20をInterruptInに使ってはいけない |
naoya1687 | 31:cef6ee7af014 | 40 | TweLite_Sensors tweLite_Sensors(PC_12,PD_2); |
shimogamo | 0:2a15bd367891 | 41 | |
shimogamo | 0:2a15bd367891 | 42 | |
shimogamo | 16:7e36177b4435 | 43 | |
shimogamo | 5:9a1ec02229dd | 44 | void pc_rx(){ |
shimogamo | 5:9a1ec02229dd | 45 | while(pc.readable()==1){ |
shimogamo | 26:a53c3208ac35 | 46 | //コマンドモードのon,offはここに入れるといい |
shimogamo | 9:d1fc0805ec7d | 47 | char buf = (char)pc.getc(); |
naoya1687 | 34:770a6bbb4d63 | 48 | pc.putc(buf); |
shimogamo | 12:8e39bb45c61c | 49 | Global::initqueue.put((char*)buf); |
shimogamo | 0:2a15bd367891 | 50 | } |
shimogamo | 0:2a15bd367891 | 51 | } |
shimogamo | 0:2a15bd367891 | 52 | |
shimogamo | 5:9a1ec02229dd | 53 | |
shimogamo | 9:d1fc0805ec7d | 54 | |
shimogamo | 9:d1fc0805ec7d | 55 | void initializeTask(void const *pvParameters){ |
shimogamo | 5:9a1ec02229dd | 56 | while(1){ |
shimogamo | 9:d1fc0805ec7d | 57 | Init::getSerial(); |
shimogamo | 5:9a1ec02229dd | 58 | } |
shimogamo | 5:9a1ec02229dd | 59 | } |
shimogamo | 5:9a1ec02229dd | 60 | |
shimogamo | 0:2a15bd367891 | 61 | void controlTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 62 | while(1){ |
shimogamo | 15:e73408fc6008 | 63 | //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こる) |
shimogamo | 0:2a15bd367891 | 64 | controllerManager.update(); |
naoya1687 | 34:770a6bbb4d63 | 65 | servoSend.send(); |
naoya1687 | 31:cef6ee7af014 | 66 | //selector.update(); |
shimogamo | 26:a53c3208ac35 | 67 | wdt = !wdt;//ウォッチドッグタイマのkickに相当 |
shimogamo | 0:2a15bd367891 | 68 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 69 | } |
shimogamo | 0:2a15bd367891 | 70 | } |
shimogamo | 0:2a15bd367891 | 71 | |
shimogamo | 14:11e71bf840b2 | 72 | void sensorTask500(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 73 | while(1){ |
shimogamo | 0:2a15bd367891 | 74 | airspeed.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 | |
naoya1687 | 33:d939479e7b13 | 80 | void twesensorTask(void const *pvParameters){ |
naoya1687 | 33:d939479e7b13 | 81 | while(1){ |
naoya1687 | 33:d939479e7b13 | 82 | tweLite_Sensors.update();//こっちでそれぞれのbatteryをupdata |
naoya1687 | 33:d939479e7b13 | 83 | } |
naoya1687 | 33:d939479e7b13 | 84 | } |
naoya1687 | 33:d939479e7b13 | 85 | |
shimogamo | 0:2a15bd367891 | 86 | |
shimogamo | 0:2a15bd367891 | 87 | void displayTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 88 | while(1){ |
shimogamo | 0:2a15bd367891 | 89 | display.update(); |
shimogamo | 13:a8e10a69df45 | 90 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 91 | } |
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); |
naoya1687 | 33:d939479e7b13 | 104 | Thread TwesensorTask(twesensorTask); |
shimogamo | 0:2a15bd367891 | 105 | Thread DisplayTask(displayTask); |
shimogamo | 0:2a15bd367891 | 106 | printf("Task end\n"); |
shimogamo | 0:2a15bd367891 | 107 | |
shimogamo | 0:2a15bd367891 | 108 | Thread::wait(osWaitForever); |
shimogamo | 0:2a15bd367891 | 109 | } |