kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Mon Mar 28 09:01:00 2016 +0000
Revision:
17:887cfe1d309f
Parent:
16:7e36177b4435
Child:
18:d8a9c25d6137
??????1??????????????????????

Who changed what in which revision?

UserRevisionLine numberNew 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 17:887cfe1d309f 5 //@todo Controller値及びサーボ値の正負を定めておくべき(決めておかないとTFで混乱する)
shimogamo 17:887cfe1d309f 6
shimogamo 17:887cfe1d309f 7 //@todo Processing
shimogamo 8:ca92cb674004 8
shimogamo 12:8e39bb45c61c 9 //@todo Cadence, Airspeed内でNC,Encorderクラスから継承
shimogamo 16:7e36177b4435 10 //@todo Buttonクラスを作り,TrimとSelectorの親クラスにする
shimogamo 12:8e39bb45c61c 11
shimogamo 12:8e39bb45c61c 12 //@todo 使っているライブラリの関数の説明追加
shimogamo 12:8e39bb45c61c 13
shimogamo 17:887cfe1d309f 14 //タスクの数に上限があるっぽい(6個以下)
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"
shimogamo 0:2a15bd367891 20 #include "ServoManager.h"
shimogamo 0:2a15bd367891 21 #include "ControllerManager.h"
shimogamo 0:2a15bd367891 22 #include "Trim.h"
shimogamo 0:2a15bd367891 23 #include "Cadence.h"
shimogamo 0:2a15bd367891 24 #include "Airspeed.h"
shimogamo 14:11e71bf840b2 25 #include "Ultsonic.h"
shimogamo 15:e73408fc6008 26 #include "Atmpress.h"
shimogamo 0:2a15bd367891 27 #include "Display.h"
shimogamo 0:2a15bd367891 28 #include "XBee.h"
shimogamo 16:7e36177b4435 29 #include "Selector.h"
shimogamo 5:9a1ec02229dd 30
shimogamo 5:9a1ec02229dd 31
shimogamo 5:9a1ec02229dd 32 RawSerial pc(USBTX, USBRX);
shimogamo 0:2a15bd367891 33
shimogamo 15:e73408fc6008 34 Atmpress atmpress(p9, p10);//sda, scl
shimogamo 17:887cfe1d309f 35 Display display(p13, p14, NC);//tx, rx, sw
shimogamo 12:8e39bb45c61c 36 ControllerManager controllerManager(p15,p16,p17,p18);//ele, rud, eletrimup, eletrimdown
shimogamo 15:e73408fc6008 37 Ultsonic ultsonic(p20);//analogIn
shimogamo 12:8e39bb45c61c 38 ServoManager servoManager(p21, p22);//ele, rud
shimogamo 17:887cfe1d309f 39 Cadence cadence(p23, NC, NC);//p11, p12では動作しない=>使っていたmbedのピンが逝ってる可能性が微レ存
shimogamo 16:7e36177b4435 40 Selector selector(p25);
shimogamo 12:8e39bb45c61c 41 DigitalOut wdt(p26);
shimogamo 12:8e39bb45c61c 42 XBee xbee(p28, p27);//tx, rx
shimogamo 12:8e39bb45c61c 43 Airspeed airspeed(p29, NC, NC);//p19,p20をInterruptInに使ってはいけない
shimogamo 0:2a15bd367891 44
shimogamo 0:2a15bd367891 45
shimogamo 16:7e36177b4435 46
shimogamo 5:9a1ec02229dd 47 void pc_rx(){
shimogamo 5:9a1ec02229dd 48 while(pc.readable()==1){
shimogamo 10:0a4bf8c82493 49 //コマンドモードのon,offはここに入れる
shimogamo 9:d1fc0805ec7d 50 char buf = (char)pc.getc();
shimogamo 12:8e39bb45c61c 51 Global::initqueue.put((char*)buf);
shimogamo 0:2a15bd367891 52 }
shimogamo 0:2a15bd367891 53 }
shimogamo 0:2a15bd367891 54
shimogamo 5:9a1ec02229dd 55
shimogamo 9:d1fc0805ec7d 56
shimogamo 9:d1fc0805ec7d 57 void initializeTask(void const *pvParameters){
shimogamo 5:9a1ec02229dd 58 while(1){
shimogamo 9:d1fc0805ec7d 59 Init::getSerial();
shimogamo 5:9a1ec02229dd 60 }
shimogamo 5:9a1ec02229dd 61 }
shimogamo 5:9a1ec02229dd 62
shimogamo 0:2a15bd367891 63 void controlTask(void const *pvParameters){
shimogamo 0:2a15bd367891 64 while(1){
shimogamo 15:e73408fc6008 65 //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こる)
shimogamo 0:2a15bd367891 66 controllerManager.update();
shimogamo 0:2a15bd367891 67 servoManager.update();
shimogamo 17:887cfe1d309f 68 selector.update();
shimogamo 12:8e39bb45c61c 69 wdt = !wdt;
shimogamo 0:2a15bd367891 70 Thread::wait(50);
shimogamo 0:2a15bd367891 71 }
shimogamo 0:2a15bd367891 72 }
shimogamo 0:2a15bd367891 73
shimogamo 14:11e71bf840b2 74 void sensorTask500(void const *pvParameters){
shimogamo 0:2a15bd367891 75 while(1){
shimogamo 0:2a15bd367891 76 airspeed.update();
shimogamo 14:11e71bf840b2 77 cadence.update();
shimogamo 14:11e71bf840b2 78 ultsonic.update();
shimogamo 15:e73408fc6008 79 atmpress.update();
shimogamo 9:d1fc0805ec7d 80 Thread::wait(500);
shimogamo 0:2a15bd367891 81 }
shimogamo 0:2a15bd367891 82 }
shimogamo 14:11e71bf840b2 83
shimogamo 0:2a15bd367891 84
shimogamo 0:2a15bd367891 85 void displayTask(void const *pvParameters){
shimogamo 0:2a15bd367891 86 while(1){
shimogamo 0:2a15bd367891 87 display.update();
shimogamo 13:a8e10a69df45 88 Thread::wait(50);
shimogamo 0:2a15bd367891 89 }
shimogamo 0:2a15bd367891 90 }
shimogamo 0:2a15bd367891 91
shimogamo 0:2a15bd367891 92 void xbeeTask(void const *pvParameters){
shimogamo 0:2a15bd367891 93 while(1){
shimogamo 0:2a15bd367891 94 xbee.update();
shimogamo 13:a8e10a69df45 95 Thread::wait(50);
shimogamo 0:2a15bd367891 96 }
shimogamo 0:2a15bd367891 97 }
shimogamo 0:2a15bd367891 98
shimogamo 0:2a15bd367891 99
shimogamo 0:2a15bd367891 100 int main(void){
shimogamo 0:2a15bd367891 101 printf("start\n");
shimogamo 5:9a1ec02229dd 102
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 }