kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Mon Dec 21 14:00:22 2015 +0000
Revision:
14:11e71bf840b2
Parent:
13:a8e10a69df45
Child:
15:e73408fc6008
????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimogamo 14:11e71bf840b2 1 //@todo 時間のクラスの作成(Global中に)
shimogamo 14:11e71bf840b2 2
shimogamo 12:8e39bb45c61c 3 //@todo Initのコマンドモード化or別プログラム化
shimogamo 10:0a4bf8c82493 4
shimogamo 10:0a4bf8c82493 5 //@todo ソフトウェアシリアルの確認等
shimogamo 8:ca92cb674004 6
shimogamo 8:ca92cb674004 7 //@todo 高度計の追加
shimogamo 8:ca92cb674004 8
shimogamo 12:8e39bb45c61c 9 //@todo Cadence, Airspeed内でNC,Encorderクラスから継承
shimogamo 12:8e39bb45c61c 10
shimogamo 12:8e39bb45c61c 11 //@todo 使っているライブラリの関数の説明追加
shimogamo 12:8e39bb45c61c 12
shimogamo 14:11e71bf840b2 13 //@todo Processing
shimogamo 14:11e71bf840b2 14
shimogamo 14:11e71bf840b2 15 //タスクの数に上限があるっぽい?(6個以下)
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"
shimogamo 0:2a15bd367891 21 #include "ServoManager.h"
shimogamo 0:2a15bd367891 22 #include "ControllerManager.h"
shimogamo 0:2a15bd367891 23 #include "Trim.h"
shimogamo 0:2a15bd367891 24 #include "Cadence.h"
shimogamo 0:2a15bd367891 25 #include "Airspeed.h"
shimogamo 14:11e71bf840b2 26 #include "Ultsonic.h"
shimogamo 0:2a15bd367891 27 #include "Display.h"
shimogamo 0:2a15bd367891 28 #include "XBee.h"
shimogamo 5:9a1ec02229dd 29
shimogamo 5:9a1ec02229dd 30
shimogamo 5:9a1ec02229dd 31 RawSerial pc(USBTX, USBRX);
shimogamo 0:2a15bd367891 32
shimogamo 12:8e39bb45c61c 33 Display display(p13, p14);//tx, rx
shimogamo 12:8e39bb45c61c 34 ControllerManager controllerManager(p15,p16,p17,p18);//ele, rud, eletrimup, eletrimdown
shimogamo 14:11e71bf840b2 35 Ultsonic ultsonic(p20);
shimogamo 12:8e39bb45c61c 36 ServoManager servoManager(p21, p22);//ele, rud
shimogamo 13:a8e10a69df45 37 Cadence cadence(p23, p24, NC);//p11, p12では動作しない
shimogamo 12:8e39bb45c61c 38 DigitalOut wdt(p26);
shimogamo 12:8e39bb45c61c 39 XBee xbee(p28, p27);//tx, rx
shimogamo 12:8e39bb45c61c 40 Airspeed airspeed(p29, NC, NC);//p19,p20をInterruptInに使ってはいけない
shimogamo 0:2a15bd367891 41
shimogamo 0:2a15bd367891 42
shimogamo 5:9a1ec02229dd 43 void pc_rx(){
shimogamo 5:9a1ec02229dd 44 while(pc.readable()==1){
shimogamo 10:0a4bf8c82493 45 //コマンドモードのon,offはここに入れる
shimogamo 9:d1fc0805ec7d 46 char buf = (char)pc.getc();
shimogamo 12:8e39bb45c61c 47 Global::initqueue.put((char*)buf);
shimogamo 0:2a15bd367891 48 }
shimogamo 0:2a15bd367891 49 }
shimogamo 0:2a15bd367891 50
shimogamo 5:9a1ec02229dd 51
shimogamo 9:d1fc0805ec7d 52
shimogamo 9:d1fc0805ec7d 53 void initializeTask(void const *pvParameters){
shimogamo 5:9a1ec02229dd 54 while(1){
shimogamo 9:d1fc0805ec7d 55 Init::getSerial();
shimogamo 5:9a1ec02229dd 56 }
shimogamo 5:9a1ec02229dd 57 }
shimogamo 5:9a1ec02229dd 58
shimogamo 0:2a15bd367891 59 void controlTask(void const *pvParameters){
shimogamo 0:2a15bd367891 60 while(1){
shimogamo 13:a8e10a69df45 61 //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こります)
shimogamo 0:2a15bd367891 62 controllerManager.update();
shimogamo 0:2a15bd367891 63 servoManager.update();
shimogamo 12:8e39bb45c61c 64 wdt = !wdt;
shimogamo 0:2a15bd367891 65 Thread::wait(50);
shimogamo 0:2a15bd367891 66 }
shimogamo 0:2a15bd367891 67 }
shimogamo 0:2a15bd367891 68
shimogamo 14:11e71bf840b2 69 void sensorTask500(void const *pvParameters){
shimogamo 0:2a15bd367891 70 while(1){
shimogamo 0:2a15bd367891 71 airspeed.update();
shimogamo 14:11e71bf840b2 72 cadence.update();
shimogamo 14:11e71bf840b2 73 ultsonic.update();
shimogamo 9:d1fc0805ec7d 74 Thread::wait(500);
shimogamo 0:2a15bd367891 75 }
shimogamo 0:2a15bd367891 76 }
shimogamo 14:11e71bf840b2 77
shimogamo 0:2a15bd367891 78
shimogamo 0:2a15bd367891 79 void displayTask(void const *pvParameters){
shimogamo 0:2a15bd367891 80 while(1){
shimogamo 0:2a15bd367891 81 display.update();
shimogamo 13:a8e10a69df45 82 Thread::wait(50);
shimogamo 0:2a15bd367891 83 }
shimogamo 0:2a15bd367891 84 }
shimogamo 0:2a15bd367891 85
shimogamo 0:2a15bd367891 86 void xbeeTask(void const *pvParameters){
shimogamo 0:2a15bd367891 87 while(1){
shimogamo 0:2a15bd367891 88 xbee.update();
shimogamo 13:a8e10a69df45 89 Thread::wait(50);
shimogamo 0:2a15bd367891 90 }
shimogamo 0:2a15bd367891 91 }
shimogamo 0:2a15bd367891 92
shimogamo 0:2a15bd367891 93
shimogamo 0:2a15bd367891 94 int main(void){
shimogamo 0:2a15bd367891 95 printf("start\n");
shimogamo 5:9a1ec02229dd 96
shimogamo 5:9a1ec02229dd 97 pc.attach(pc_rx,Serial::RxIrq);
shimogamo 5:9a1ec02229dd 98
shimogamo 6:0d9fa7152934 99 Global::initialize();
shimogamo 5:9a1ec02229dd 100 Thread InitializeTask(initializeTask);
shimogamo 9:d1fc0805ec7d 101 Thread ControlTask(controlTask, NULL, osPriorityRealtime);
shimogamo 14:11e71bf840b2 102 Thread SensorTask500(sensorTask500);
shimogamo 0:2a15bd367891 103 Thread DisplayTask(displayTask);
shimogamo 0:2a15bd367891 104 Thread XbeeTask(xbeeTask);
shimogamo 0:2a15bd367891 105 printf("Task end\n");
shimogamo 0:2a15bd367891 106
shimogamo 0:2a15bd367891 107 Thread::wait(osWaitForever);
shimogamo 0:2a15bd367891 108 }