kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Sat Nov 28 18:47:26 2015 +0000
Revision:
12:8e39bb45c61c
Parent:
11:af917eb0e624
Child:
13:a8e10a69df45
Trim?ControllerManager?????

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 8:ca92cb674004 5 //@todo androidとの通信
shimogamo 8:ca92cb674004 6 //@todo xbeeとの通信
shimogamo 8:ca92cb674004 7
shimogamo 8:ca92cb674004 8 //@todo 高度計の追加
shimogamo 8:ca92cb674004 9
shimogamo 12:8e39bb45c61c 10 //@todo Cadence, Airspeed内でNC,Encorderクラスから継承
shimogamo 12:8e39bb45c61c 11
shimogamo 12:8e39bb45c61c 12 //@todo 使っているライブラリの関数の説明追加
shimogamo 12:8e39bb45c61c 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 0:2a15bd367891 23 #include "Display.h"
shimogamo 0:2a15bd367891 24 #include "XBee.h"
shimogamo 5:9a1ec02229dd 25
shimogamo 5:9a1ec02229dd 26
shimogamo 5:9a1ec02229dd 27 RawSerial pc(USBTX, USBRX);
shimogamo 0:2a15bd367891 28
shimogamo 11:af917eb0e624 29 Cadence cadence(p11, p12, NC);
shimogamo 12:8e39bb45c61c 30 Display display(p13, p14);//tx, rx
shimogamo 12:8e39bb45c61c 31 ControllerManager controllerManager(p15,p16,p17,p18);//ele, rud, eletrimup, eletrimdown
shimogamo 12:8e39bb45c61c 32 ServoManager servoManager(p21, p22);//ele, rud
shimogamo 12:8e39bb45c61c 33 DigitalOut wdt(p26);
shimogamo 12:8e39bb45c61c 34 XBee xbee(p28, p27);//tx, rx
shimogamo 12:8e39bb45c61c 35 Airspeed airspeed(p29, NC, NC);//p19,p20をInterruptInに使ってはいけない
shimogamo 0:2a15bd367891 36
shimogamo 0:2a15bd367891 37
shimogamo 5:9a1ec02229dd 38 void pc_rx(){
shimogamo 5:9a1ec02229dd 39 while(pc.readable()==1){
shimogamo 10:0a4bf8c82493 40 //コマンドモードのon,offはここに入れる
shimogamo 9:d1fc0805ec7d 41 char buf = (char)pc.getc();
shimogamo 12:8e39bb45c61c 42 Global::initqueue.put((char*)buf);
shimogamo 0:2a15bd367891 43 }
shimogamo 0:2a15bd367891 44 }
shimogamo 0:2a15bd367891 45
shimogamo 5:9a1ec02229dd 46
shimogamo 9:d1fc0805ec7d 47
shimogamo 9:d1fc0805ec7d 48 void initializeTask(void const *pvParameters){
shimogamo 5:9a1ec02229dd 49 while(1){
shimogamo 9:d1fc0805ec7d 50 Init::getSerial();
shimogamo 5:9a1ec02229dd 51 }
shimogamo 5:9a1ec02229dd 52 }
shimogamo 5:9a1ec02229dd 53
shimogamo 0:2a15bd367891 54 void controlTask(void const *pvParameters){
shimogamo 0:2a15bd367891 55 while(1){
shimogamo 10:0a4bf8c82493 56 //この中でprintfはしないほうがいいみたい(9600bpsだと遅延が起こります)
shimogamo 0:2a15bd367891 57 controllerManager.update();
shimogamo 0:2a15bd367891 58 servoManager.update();
shimogamo 12:8e39bb45c61c 59 wdt = !wdt;
shimogamo 0:2a15bd367891 60 Thread::wait(50);
shimogamo 0:2a15bd367891 61 }
shimogamo 0:2a15bd367891 62 }
shimogamo 0:2a15bd367891 63
shimogamo 0:2a15bd367891 64 void airspeedTask(void const *pvParameters){
shimogamo 0:2a15bd367891 65 while(1){
shimogamo 0:2a15bd367891 66 airspeed.update();
shimogamo 9:d1fc0805ec7d 67 Thread::wait(500);
shimogamo 0:2a15bd367891 68 }
shimogamo 0:2a15bd367891 69 }
shimogamo 0:2a15bd367891 70
shimogamo 0:2a15bd367891 71 void cadenceTask(void const *pvParameters){
shimogamo 0:2a15bd367891 72 while(1){
shimogamo 0:2a15bd367891 73 cadence.update();
shimogamo 9:d1fc0805ec7d 74 Thread::wait(500);
shimogamo 0:2a15bd367891 75 }
shimogamo 0:2a15bd367891 76 }
shimogamo 0:2a15bd367891 77
shimogamo 0:2a15bd367891 78 void displayTask(void const *pvParameters){
shimogamo 0:2a15bd367891 79 while(1){
shimogamo 0:2a15bd367891 80 display.update();
shimogamo 10:0a4bf8c82493 81 Thread::wait(100);
shimogamo 0:2a15bd367891 82 }
shimogamo 0:2a15bd367891 83 }
shimogamo 0:2a15bd367891 84
shimogamo 0:2a15bd367891 85 void xbeeTask(void const *pvParameters){
shimogamo 0:2a15bd367891 86 while(1){
shimogamo 0:2a15bd367891 87 xbee.update();
shimogamo 9:d1fc0805ec7d 88 Thread::wait(500);
shimogamo 0:2a15bd367891 89 }
shimogamo 0:2a15bd367891 90 }
shimogamo 0:2a15bd367891 91
shimogamo 0:2a15bd367891 92
shimogamo 0:2a15bd367891 93 int main(void){
shimogamo 0:2a15bd367891 94 printf("start\n");
shimogamo 5:9a1ec02229dd 95
shimogamo 5:9a1ec02229dd 96 pc.attach(pc_rx,Serial::RxIrq);
shimogamo 5:9a1ec02229dd 97
shimogamo 6:0d9fa7152934 98 Global::initialize();
shimogamo 5:9a1ec02229dd 99 Thread InitializeTask(initializeTask);
shimogamo 9:d1fc0805ec7d 100 Thread ControlTask(controlTask, NULL, osPriorityRealtime);
shimogamo 0:2a15bd367891 101 Thread AirspeedTask(airspeedTask);
shimogamo 0:2a15bd367891 102 Thread CadenceTask(cadenceTask);
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 }