kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
naoya1687
Date:
Thu Dec 29 11:36:49 2016 +0000
Revision:
30:6d3a78bc1925
Parent:
27:5b897e2e0ac6
Child:
31:cef6ee7af014
TweLite_Sensors????????????main???

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