kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Sat Nov 28 15:08:59 2015 +0000
Revision:
11:af917eb0e624
Parent:
10:0a4bf8c82493
Child:
12:8e39bb45c61c
????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimogamo 10:0a4bf8c82493 1 //@todo timerの精度の確認
shimogamo 10:0a4bf8c82493 2
shimogamo 10:0a4bf8c82493 3 //@todo Initのコマンドモード化
shimogamo 10:0a4bf8c82493 4
shimogamo 10:0a4bf8c82493 5 //@todo ソフトウェアシリアルの確認等
shimogamo 8:ca92cb674004 6
shimogamo 8:ca92cb674004 7 //@todo androidとの通信
shimogamo 8:ca92cb674004 8 //@todo xbeeとの通信
shimogamo 8:ca92cb674004 9
shimogamo 8:ca92cb674004 10 //@todo 高度計の追加
shimogamo 8:ca92cb674004 11
shimogamo 0:2a15bd367891 12 #include "mbed.h"
shimogamo 0:2a15bd367891 13 #include "rtos.h"
shimogamo 0:2a15bd367891 14 #include "Global.h"
shimogamo 9:d1fc0805ec7d 15 #include "Init.h"
shimogamo 0:2a15bd367891 16 #include "ServoManager.h"
shimogamo 0:2a15bd367891 17 #include "ControllerManager.h"
shimogamo 0:2a15bd367891 18 #include "Trim.h"
shimogamo 0:2a15bd367891 19 #include "Cadence.h"
shimogamo 0:2a15bd367891 20 #include "Airspeed.h"
shimogamo 0:2a15bd367891 21 #include "Altitude.h"
shimogamo 0:2a15bd367891 22 #include "Display.h"
shimogamo 0:2a15bd367891 23 #include "XBee.h"
shimogamo 5:9a1ec02229dd 24
shimogamo 5:9a1ec02229dd 25
shimogamo 5:9a1ec02229dd 26 RawSerial pc(USBTX, USBRX);
shimogamo 0:2a15bd367891 27
shimogamo 11:af917eb0e624 28 Cadence cadence(p11, p12, NC);
shimogamo 11:af917eb0e624 29 Display display(p13, p14);
shimogamo 11:af917eb0e624 30 ControllerManager controllerManager(p8,p15,p16);
shimogamo 11:af917eb0e624 31 Trim trim(p17, p18);
shimogamo 0:2a15bd367891 32 ServoManager servoManager(p21, p22);
shimogamo 11:af917eb0e624 33 DigitalOut resetSw(p26);
shimogamo 11:af917eb0e624 34 XBee xbee(p28, p27);
shimogamo 11:af917eb0e624 35 Airspeed airspeed(p29, NC, NC);//p19,p20をinterruptに使ってはいけない
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 9:d1fc0805ec7d 42 Global::queue.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 2:e0f1e8662b8c 57 trim.update();
shimogamo 0:2a15bd367891 58 controllerManager.update();
shimogamo 0:2a15bd367891 59 servoManager.update();
shimogamo 11:af917eb0e624 60 resetSw = !resetSw;
shimogamo 0:2a15bd367891 61 Thread::wait(50);
shimogamo 0:2a15bd367891 62 }
shimogamo 0:2a15bd367891 63 }
shimogamo 0:2a15bd367891 64
shimogamo 0:2a15bd367891 65 void airspeedTask(void const *pvParameters){
shimogamo 0:2a15bd367891 66 while(1){
shimogamo 0:2a15bd367891 67 airspeed.update();
shimogamo 9:d1fc0805ec7d 68 Thread::wait(500);
shimogamo 0:2a15bd367891 69 }
shimogamo 0:2a15bd367891 70 }
shimogamo 0:2a15bd367891 71
shimogamo 0:2a15bd367891 72 void cadenceTask(void const *pvParameters){
shimogamo 0:2a15bd367891 73 while(1){
shimogamo 0:2a15bd367891 74 cadence.update();
shimogamo 9:d1fc0805ec7d 75 Thread::wait(500);
shimogamo 0:2a15bd367891 76 }
shimogamo 0:2a15bd367891 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 10:0a4bf8c82493 82 Thread::wait(100);
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 9:d1fc0805ec7d 89 Thread::wait(500);
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 0:2a15bd367891 102 Thread AirspeedTask(airspeedTask);
shimogamo 0:2a15bd367891 103 Thread CadenceTask(cadenceTask);
shimogamo 0:2a15bd367891 104 Thread DisplayTask(displayTask);
shimogamo 0:2a15bd367891 105 Thread XbeeTask(xbeeTask);
shimogamo 0:2a15bd367891 106 printf("Task end\n");
shimogamo 0:2a15bd367891 107
shimogamo 0:2a15bd367891 108 Thread::wait(osWaitForever);
shimogamo 0:2a15bd367891 109 }