kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Thu Nov 26 08:14:41 2015 +0000
Revision:
10:0a4bf8c82493
Parent:
9:d1fc0805ec7d
Child:
11:af917eb0e624
previous pin assign

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 0:2a15bd367891 28
shimogamo 0:2a15bd367891 29 Display display(p9, p10);
shimogamo 0:2a15bd367891 30 XBee xbee(p13, p14);
shimogamo 8:ca92cb674004 31 Trim trim(p16, p17);
shimogamo 0:2a15bd367891 32 ControllerManager controllerManager(p18,p19,p20);
shimogamo 0:2a15bd367891 33 ServoManager servoManager(p21, p22);
shimogamo 0:2a15bd367891 34 Airspeed airspeed(p26, NC, NC);
shimogamo 0:2a15bd367891 35 Cadence cadence(p29, p30, NC);
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 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 }