kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
naoya1687
Date:
Thu Feb 16 07:08:54 2017 +0000
Revision:
32:13aba70baa4b
Parent:
31:cef6ee7af014
Child:
33:d939479e7b13
selector???????????xbee.h????Display???????batteryvolt???

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 32:13aba70baa4b 10 //servo回りはシリアルに変更
naoya1687 32:13aba70baa4b 11 //selector周りはコメントアウトしてる
naoya1687 31:cef6ee7af014 12
shimogamo 17:887cfe1d309f 13 //タスクの数に上限があるっぽい(6個以下)
naoya1687 27:5b897e2e0ac6 14 //
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 "Airspeed.h"
shimogamo 15:e73408fc6008 24 #include "Atmpress.h"
shimogamo 19:c6ad6b453b39 25 #include "BatteryChecker.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 31:cef6ee7af014 38 BatteryChecker batteryChecker(p18);//どのピンか確認
naoya1687 32:13aba70baa4b 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 Airspeed airspeed(PA_13, NC, NC);//p19,p20をInterruptInに使ってはいけない
naoya1687 31:cef6ee7af014 43 TweLite_Sensors tweLite_Sensors(PC_12,PD_2);
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 26:a53c3208ac35 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();
naoya1687 32:13aba70baa4b 67 servoManager.update();
naoya1687 31:cef6ee7af014 68 //selector.update();
shimogamo 26:a53c3208ac35 69 wdt = !wdt;//ウォッチドッグタイマのkickに相当
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 26:a53c3208ac35 76 //batteryCheckerとatmpressを入れ替えると10minくらいで停止する。わけわからん
shimogamo 0:2a15bd367891 77 airspeed.update();
naoya1687 31:cef6ee7af014 78 tweLite_Sensors.update(CADENCE);//こっちでそれぞれのbatteryをupdata
naoya1687 32:13aba70baa4b 79 tweLite_Sensors.update(ULTSONIC);//BatteryCheckerにまとめたい
shimogamo 21:b1419813f2d4 80 batteryChecker.update();
shimogamo 15:e73408fc6008 81 atmpress.update();
shimogamo 9:d1fc0805ec7d 82 Thread::wait(500);
shimogamo 0:2a15bd367891 83 }
shimogamo 0:2a15bd367891 84 }
shimogamo 14:11e71bf840b2 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);
shimogamo 0:2a15bd367891 104 Thread DisplayTask(displayTask);
shimogamo 0:2a15bd367891 105 printf("Task end\n");
shimogamo 0:2a15bd367891 106
shimogamo 0:2a15bd367891 107 Thread::wait(osWaitForever);
shimogamo 0:2a15bd367891 108 }