kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Tue Feb 09 13:07:29 2016 +0000
Revision:
16:7e36177b4435
Parent:
15:e73408fc6008
Child:
17:887cfe1d309f
Selector??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimogamo 12:8e39bb45c61c 1 //@todo Initのコマンドモード化or別プログラム化
shimogamo 10:0a4bf8c82493 2
shimogamo 10:0a4bf8c82493 3 //@todo ソフトウェアシリアルの確認等
shimogamo 8:ca92cb674004 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 14:11e71bf840b2 10 //@todo Processing
shimogamo 14:11e71bf840b2 11
shimogamo 14:11e71bf840b2 12 //タスクの数に上限があるっぽい?(6個以下)
shimogamo 14:11e71bf840b2 13
shimogamo 0:2a15bd367891 14 #include "mbed.h"
shimogamo 0:2a15bd367891 15 #include "rtos.h"
shimogamo 0:2a15bd367891 16 #include "Global.h"
shimogamo 9:d1fc0805ec7d 17 #include "Init.h"
shimogamo 0:2a15bd367891 18 #include "ServoManager.h"
shimogamo 0:2a15bd367891 19 #include "ControllerManager.h"
shimogamo 0:2a15bd367891 20 #include "Trim.h"
shimogamo 0:2a15bd367891 21 #include "Cadence.h"
shimogamo 0:2a15bd367891 22 #include "Airspeed.h"
shimogamo 14:11e71bf840b2 23 #include "Ultsonic.h"
shimogamo 15:e73408fc6008 24 #include "Atmpress.h"
shimogamo 0:2a15bd367891 25 #include "Display.h"
shimogamo 0:2a15bd367891 26 #include "XBee.h"
shimogamo 16:7e36177b4435 27 #include "Selector.h"
shimogamo 5:9a1ec02229dd 28
shimogamo 5:9a1ec02229dd 29
shimogamo 5:9a1ec02229dd 30 RawSerial pc(USBTX, USBRX);
shimogamo 0:2a15bd367891 31
shimogamo 15:e73408fc6008 32 Atmpress atmpress(p9, p10);//sda, scl
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 15:e73408fc6008 35 Ultsonic ultsonic(p20);//analogIn
shimogamo 12:8e39bb45c61c 36 ServoManager servoManager(p21, p22);//ele, rud
shimogamo 13:a8e10a69df45 37 Cadence cadence(p23, p24, NC);//p11, p12では動作しない
shimogamo 16:7e36177b4435 38 Selector selector(p25);
shimogamo 12:8e39bb45c61c 39 DigitalOut wdt(p26);
shimogamo 12:8e39bb45c61c 40 XBee xbee(p28, p27);//tx, rx
shimogamo 12:8e39bb45c61c 41 Airspeed airspeed(p29, NC, NC);//p19,p20をInterruptInに使ってはいけない
shimogamo 0:2a15bd367891 42
shimogamo 0:2a15bd367891 43
shimogamo 16:7e36177b4435 44
shimogamo 5:9a1ec02229dd 45 void pc_rx(){
shimogamo 5:9a1ec02229dd 46 while(pc.readable()==1){
shimogamo 10:0a4bf8c82493 47 //コマンドモードのon,offはここに入れる
shimogamo 9:d1fc0805ec7d 48 char buf = (char)pc.getc();
shimogamo 12:8e39bb45c61c 49 Global::initqueue.put((char*)buf);
shimogamo 0:2a15bd367891 50 }
shimogamo 0:2a15bd367891 51 }
shimogamo 0:2a15bd367891 52
shimogamo 5:9a1ec02229dd 53
shimogamo 9:d1fc0805ec7d 54
shimogamo 9:d1fc0805ec7d 55 void initializeTask(void const *pvParameters){
shimogamo 5:9a1ec02229dd 56 while(1){
shimogamo 9:d1fc0805ec7d 57 Init::getSerial();
shimogamo 5:9a1ec02229dd 58 }
shimogamo 5:9a1ec02229dd 59 }
shimogamo 5:9a1ec02229dd 60
shimogamo 0:2a15bd367891 61 void controlTask(void const *pvParameters){
shimogamo 0:2a15bd367891 62 while(1){
shimogamo 15:e73408fc6008 63 //この中でpc.printfはしないほうがいいみたい(9600bpsだと遅延が起こる)
shimogamo 0:2a15bd367891 64 controllerManager.update();
shimogamo 0:2a15bd367891 65 servoManager.update();
shimogamo 12:8e39bb45c61c 66 wdt = !wdt;
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 0:2a15bd367891 73 airspeed.update();
shimogamo 14:11e71bf840b2 74 cadence.update();
shimogamo 14:11e71bf840b2 75 ultsonic.update();
shimogamo 15:e73408fc6008 76 atmpress.update();
shimogamo 16:7e36177b4435 77 selector.update();
shimogamo 9:d1fc0805ec7d 78 Thread::wait(500);
shimogamo 0:2a15bd367891 79 }
shimogamo 0:2a15bd367891 80 }
shimogamo 14:11e71bf840b2 81
shimogamo 0:2a15bd367891 82
shimogamo 0:2a15bd367891 83 void displayTask(void const *pvParameters){
shimogamo 0:2a15bd367891 84 while(1){
shimogamo 0:2a15bd367891 85 display.update();
shimogamo 13:a8e10a69df45 86 Thread::wait(50);
shimogamo 0:2a15bd367891 87 }
shimogamo 0:2a15bd367891 88 }
shimogamo 0:2a15bd367891 89
shimogamo 0:2a15bd367891 90 void xbeeTask(void const *pvParameters){
shimogamo 0:2a15bd367891 91 while(1){
shimogamo 0:2a15bd367891 92 xbee.update();
shimogamo 13:a8e10a69df45 93 Thread::wait(50);
shimogamo 0:2a15bd367891 94 }
shimogamo 0:2a15bd367891 95 }
shimogamo 0:2a15bd367891 96
shimogamo 0:2a15bd367891 97
shimogamo 0:2a15bd367891 98 int main(void){
shimogamo 0:2a15bd367891 99 printf("start\n");
shimogamo 5:9a1ec02229dd 100
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 }