kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
naoya1687
Date:
Mon Feb 13 06:08:05 2017 +0000
Revision:
31:cef6ee7af014
Parent:
30:6d3a78bc1925
Child:
32:13aba70baa4b
?????? todo????

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 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 31:cef6ee7af014 10 //selctor回りの削除 servo回りはシリアルに変更 xbee周りの削除とvoltをDisplayで送るよう変更
naoya1687 31:cef6ee7af014 11
shimogamo 17:887cfe1d309f 12 //タスクの数に上限があるっぽい(6個以下)
naoya1687 27:5b897e2e0ac6 13 //
shimogamo 14:11e71bf840b2 14
shimogamo 0:2a15bd367891 15 #include "mbed.h"
shimogamo 0:2a15bd367891 16 #include "rtos.h"
shimogamo 0:2a15bd367891 17 #include "Global.h"
shimogamo 9:d1fc0805ec7d 18 #include "Init.h"
shimogamo 0:2a15bd367891 19 #include "ServoManager.h"
shimogamo 0:2a15bd367891 20 #include "ControllerManager.h"
shimogamo 0:2a15bd367891 21 #include "Trim.h"
shimogamo 0:2a15bd367891 22 #include "Airspeed.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"
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 31:cef6ee7af014 38 BatteryChecker batteryChecker(p18);//どのピンか確認
naoya1687 31:cef6ee7af014 39 //ServoManager servoManager(p21, p22);//ele, rud // 要変更
naoya1687 31:cef6ee7af014 40 //Selector selector(p25);
naoya1687 31:cef6ee7af014 41 DigitalOut wdt(PA_14);
naoya1687 31:cef6ee7af014 42 //XBee xbee(p28, p27);//tx, rx
naoya1687 31:cef6ee7af014 43 Airspeed airspeed(PA_13, NC, NC);//p19,p20をInterruptInに使ってはいけない
naoya1687 31:cef6ee7af014 44 TweLite_Sensors tweLite_Sensors(PC_12,PD_2);
shimogamo 0:2a15bd367891 45
shimogamo 0:2a15bd367891 46
shimogamo 16:7e36177b4435 47
shimogamo 5:9a1ec02229dd 48 void pc_rx(){
shimogamo 5:9a1ec02229dd 49 while(pc.readable()==1){
shimogamo 26:a53c3208ac35 50 //コマンドモードのon,offはここに入れるといい
shimogamo 9:d1fc0805ec7d 51 char buf = (char)pc.getc();
shimogamo 12:8e39bb45c61c 52 Global::initqueue.put((char*)buf);
shimogamo 0:2a15bd367891 53 }
shimogamo 0:2a15bd367891 54 }
shimogamo 0:2a15bd367891 55
shimogamo 5:9a1ec02229dd 56
shimogamo 9:d1fc0805ec7d 57
shimogamo 9:d1fc0805ec7d 58 void initializeTask(void const *pvParameters){
shimogamo 5:9a1ec02229dd 59 while(1){
shimogamo 9:d1fc0805ec7d 60 Init::getSerial();
shimogamo 5:9a1ec02229dd 61 }
shimogamo 5:9a1ec02229dd 62 }
shimogamo 5:9a1ec02229dd 63
shimogamo 0:2a15bd367891 64 void controlTask(void const *pvParameters){
shimogamo 0:2a15bd367891 65 while(1){
shimogamo 15:e73408fc6008 66 //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こる)
shimogamo 0:2a15bd367891 67 controllerManager.update();
naoya1687 31:cef6ee7af014 68 //servoManager.update();
naoya1687 31:cef6ee7af014 69 //selector.update();
shimogamo 26:a53c3208ac35 70 wdt = !wdt;//ウォッチドッグタイマのkickに相当
shimogamo 0:2a15bd367891 71 Thread::wait(50);
shimogamo 0:2a15bd367891 72 }
shimogamo 0:2a15bd367891 73 }
shimogamo 0:2a15bd367891 74
shimogamo 14:11e71bf840b2 75 void sensorTask500(void const *pvParameters){
shimogamo 0:2a15bd367891 76 while(1){
shimogamo 26:a53c3208ac35 77 //batteryCheckerとatmpressを入れ替えると10minくらいで停止する。わけわからん
shimogamo 0:2a15bd367891 78 airspeed.update();
naoya1687 31:cef6ee7af014 79 tweLite_Sensors.update(CADENCE);//こっちでそれぞれのbatteryをupdata
naoya1687 31:cef6ee7af014 80 tweLite_Sensors.update(ULTSONIC);
shimogamo 21:b1419813f2d4 81 batteryChecker.update();
shimogamo 15:e73408fc6008 82 atmpress.update();
shimogamo 9:d1fc0805ec7d 83 Thread::wait(500);
shimogamo 0:2a15bd367891 84 }
shimogamo 0:2a15bd367891 85 }
shimogamo 14:11e71bf840b2 86
shimogamo 0:2a15bd367891 87
shimogamo 0:2a15bd367891 88 void displayTask(void const *pvParameters){
shimogamo 0:2a15bd367891 89 while(1){
shimogamo 0:2a15bd367891 90 display.update();
shimogamo 13:a8e10a69df45 91 Thread::wait(50);
shimogamo 0:2a15bd367891 92 }
shimogamo 0:2a15bd367891 93 }
shimogamo 0:2a15bd367891 94
shimogamo 0:2a15bd367891 95 void xbeeTask(void const *pvParameters){
shimogamo 0:2a15bd367891 96 while(1){
shimogamo 0:2a15bd367891 97 xbee.update();
shimogamo 13:a8e10a69df45 98 Thread::wait(50);
shimogamo 0:2a15bd367891 99 }
shimogamo 0:2a15bd367891 100 }
shimogamo 0:2a15bd367891 101
shimogamo 0:2a15bd367891 102
shimogamo 0:2a15bd367891 103 int main(void){
shimogamo 0:2a15bd367891 104 printf("start\n");
shimogamo 5:9a1ec02229dd 105 pc.attach(pc_rx,Serial::RxIrq);
shimogamo 5:9a1ec02229dd 106
shimogamo 6:0d9fa7152934 107 Global::initialize();
shimogamo 5:9a1ec02229dd 108 Thread InitializeTask(initializeTask);
shimogamo 9:d1fc0805ec7d 109 Thread ControlTask(controlTask, NULL, osPriorityRealtime);
shimogamo 14:11e71bf840b2 110 Thread SensorTask500(sensorTask500);
shimogamo 0:2a15bd367891 111 Thread DisplayTask(displayTask);
shimogamo 0:2a15bd367891 112 Thread XbeeTask(xbeeTask);
shimogamo 0:2a15bd367891 113 printf("Task end\n");
shimogamo 0:2a15bd367891 114
shimogamo 0:2a15bd367891 115 Thread::wait(osWaitForever);
shimogamo 0:2a15bd367891 116 }