kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Sat Oct 10 22:53:05 2015 +0000
Revision:
7:6f7bd18ce796
Parent:
6:0d9fa7152934
Child:
8:ca92cb674004
controllerManager???

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimogamo 0:2a15bd367891 1 #include "mbed.h"
shimogamo 0:2a15bd367891 2 #include "rtos.h"
shimogamo 0:2a15bd367891 3 #include "Global.h"
shimogamo 0:2a15bd367891 4 #include "ServoManager.h"
shimogamo 0:2a15bd367891 5 #include "ControllerManager.h"
shimogamo 0:2a15bd367891 6 #include "Trim.h"
shimogamo 0:2a15bd367891 7 #include "Cadence.h"
shimogamo 0:2a15bd367891 8 #include "Airspeed.h"
shimogamo 0:2a15bd367891 9 #include "Altitude.h"
shimogamo 0:2a15bd367891 10 #include "Display.h"
shimogamo 0:2a15bd367891 11 #include "XBee.h"
shimogamo 5:9a1ec02229dd 12 #include <string>
shimogamo 6:0d9fa7152934 13 #include <iostream>
shimogamo 5:9a1ec02229dd 14
shimogamo 5:9a1ec02229dd 15 #define BUFMAX 20
shimogamo 5:9a1ec02229dd 16
shimogamo 5:9a1ec02229dd 17 RawSerial pc(USBTX, USBRX);
shimogamo 5:9a1ec02229dd 18 Queue<char, BUFMAX> queue;
shimogamo 0:2a15bd367891 19
shimogamo 0:2a15bd367891 20
shimogamo 0:2a15bd367891 21 Display display(p9, p10);
shimogamo 0:2a15bd367891 22 XBee xbee(p13, p14);
shimogamo 0:2a15bd367891 23 Trim trim(p16, p17, p15);
shimogamo 0:2a15bd367891 24 ControllerManager controllerManager(p18,p19,p20);
shimogamo 0:2a15bd367891 25 ServoManager servoManager(p21, p22);
shimogamo 0:2a15bd367891 26 Airspeed airspeed(p26, NC, NC);
shimogamo 0:2a15bd367891 27 Cadence cadence(p29, p30, NC);
shimogamo 0:2a15bd367891 28
shimogamo 0:2a15bd367891 29
shimogamo 5:9a1ec02229dd 30 void pc_rx(){
shimogamo 5:9a1ec02229dd 31 while(pc.readable()==1){
shimogamo 5:9a1ec02229dd 32 char buf = pc.getc();
shimogamo 5:9a1ec02229dd 33 queue.put((char*)buf);
shimogamo 0:2a15bd367891 34 }
shimogamo 0:2a15bd367891 35 }
shimogamo 0:2a15bd367891 36
shimogamo 5:9a1ec02229dd 37
shimogamo 5:9a1ec02229dd 38 void initializeTask(void const *pvParametersd){
shimogamo 5:9a1ec02229dd 39 std::string strbuf;
shimogamo 6:0d9fa7152934 40
shimogamo 5:9a1ec02229dd 41 while(1){
shimogamo 5:9a1ec02229dd 42 osEvent evt = queue.get();
shimogamo 5:9a1ec02229dd 43 if(evt.status == osEventMessage){
shimogamo 5:9a1ec02229dd 44 char temp = evt.value.v;
shimogamo 5:9a1ec02229dd 45 strbuf.push_back(temp);
shimogamo 6:0d9fa7152934 46 if(temp == '\n'){
shimogamo 6:0d9fa7152934 47 std::string::size_type spaceIndex = strbuf.find(" ");
shimogamo 5:9a1ec02229dd 48
shimogamo 7:6f7bd18ce796 49 if (spaceIndex != std::string::npos) {//数値データがあるコマンド(" "がある場合)
shimogamo 5:9a1ec02229dd 50 char *gomi;
shimogamo 5:9a1ec02229dd 51 std::string command = strbuf.substr(0, spaceIndex);
shimogamo 7:6f7bd18ce796 52 double num = strtod(strbuf.substr(spaceIndex+1, strbuf.size()-2).c_str(), &gomi);//strbuf.size()-1には'\n'が入っている
shimogamo 5:9a1ec02229dd 53
shimogamo 5:9a1ec02229dd 54 pc.printf("coms=%s, num=%f\n", command.c_str(), num);
shimogamo 5:9a1ec02229dd 55
shimogamo 5:9a1ec02229dd 56 if(command == "eleneu"){
shimogamo 5:9a1ec02229dd 57 Global::setneutralpitch(num);
shimogamo 5:9a1ec02229dd 58 }else if(command == "elemax"){
shimogamo 5:9a1ec02229dd 59 Global::setmaxpitch(num);
shimogamo 5:9a1ec02229dd 60 }else if(command == "elemin"){
shimogamo 5:9a1ec02229dd 61 Global::setminpitch(num);
shimogamo 5:9a1ec02229dd 62 }else if(command == "rudneu"){
shimogamo 5:9a1ec02229dd 63 Global::setneutralyaw(num);
shimogamo 5:9a1ec02229dd 64 }else if(command == "rudmax"){
shimogamo 5:9a1ec02229dd 65 Global::setmaxyaw(num);
shimogamo 5:9a1ec02229dd 66 }else if(command == "rudmin"){
shimogamo 5:9a1ec02229dd 67 Global::setminyaw(num);
shimogamo 7:6f7bd18ce796 68
shimogamo 7:6f7bd18ce796 69 }else if(command == "eleneudeg"){
shimogamo 7:6f7bd18ce796 70 Global::setneutralpitchdegree(num);
shimogamo 7:6f7bd18ce796 71 }else if(command == "elemaxdeg"){
shimogamo 7:6f7bd18ce796 72 Global::setmaxpitchdegree(num);
shimogamo 7:6f7bd18ce796 73 }else if(command == "elemindeg"){
shimogamo 7:6f7bd18ce796 74 Global::setminpitchdegree(num);
shimogamo 7:6f7bd18ce796 75 }else if(command == "rudneudeg"){
shimogamo 7:6f7bd18ce796 76 Global::setneutralyawdegree(num);
shimogamo 7:6f7bd18ce796 77 }else if(command == "rudmaxdeg"){
shimogamo 7:6f7bd18ce796 78 Global::setmaxyawdegree(num);
shimogamo 7:6f7bd18ce796 79 }else if(command == "rudmindeg"){
shimogamo 7:6f7bd18ce796 80 Global::setminyawdegree(num);
shimogamo 7:6f7bd18ce796 81
shimogamo 7:6f7bd18ce796 82 }else{
shimogamo 7:6f7bd18ce796 83 pc.printf("Invalid Input\n");
shimogamo 5:9a1ec02229dd 84 }
shimogamo 5:9a1ec02229dd 85
shimogamo 6:0d9fa7152934 86 //ここで,ニュートラル情報をLocalFileに保存
shimogamo 6:0d9fa7152934 87 Global::filewrite();
shimogamo 7:6f7bd18ce796 88 }else{//数値データがないコマンド(" "がない場合)
shimogamo 7:6f7bd18ce796 89 std::string command = strbuf.substr(0,strbuf.size()-2);
shimogamo 7:6f7bd18ce796 90 if(command == "show"){
shimogamo 7:6f7bd18ce796 91 pc.printf("elevatorNeutral = %f\n", Global::getneutralpitch());
shimogamo 7:6f7bd18ce796 92 pc.printf("elevatorMax = %f\n", Global::getmaxpitch());
shimogamo 7:6f7bd18ce796 93 pc.printf("elevatorMin = %f\n", Global::getminpitch());
shimogamo 7:6f7bd18ce796 94 pc.printf("rudderNeutral = %f\n", Global::getneutralyaw());
shimogamo 7:6f7bd18ce796 95 pc.printf("rudderMax = %f\n", Global::getmaxyaw());
shimogamo 7:6f7bd18ce796 96 pc.printf("rudderMin = %f\n", Global::getminyaw());
shimogamo 7:6f7bd18ce796 97 }else if(command == "reset"){
shimogamo 7:6f7bd18ce796 98
shimogamo 7:6f7bd18ce796 99 }else{
shimogamo 7:6f7bd18ce796 100 pc.printf("Invalid Input\n");
shimogamo 7:6f7bd18ce796 101 }
shimogamo 5:9a1ec02229dd 102 }
shimogamo 7:6f7bd18ce796 103 strbuf.clear();
shimogamo 5:9a1ec02229dd 104 }
shimogamo 5:9a1ec02229dd 105 Thread::wait(10);
shimogamo 5:9a1ec02229dd 106 if(strbuf.size() >= BUFMAX){
shimogamo 5:9a1ec02229dd 107 pc.printf("\nInput Error ... ");
shimogamo 5:9a1ec02229dd 108 strbuf.clear();
shimogamo 5:9a1ec02229dd 109 pc.printf("Buffer clear\n");
shimogamo 5:9a1ec02229dd 110 }
shimogamo 5:9a1ec02229dd 111 }
shimogamo 5:9a1ec02229dd 112 }
shimogamo 5:9a1ec02229dd 113 }
shimogamo 5:9a1ec02229dd 114
shimogamo 5:9a1ec02229dd 115
shimogamo 0:2a15bd367891 116 void controlTask(void const *pvParameters){
shimogamo 0:2a15bd367891 117 while(1){
shimogamo 2:e0f1e8662b8c 118 trim.update();
shimogamo 0:2a15bd367891 119 controllerManager.update();
shimogamo 0:2a15bd367891 120 servoManager.update();
shimogamo 0:2a15bd367891 121 Thread::wait(50);
shimogamo 0:2a15bd367891 122 }
shimogamo 0:2a15bd367891 123 }
shimogamo 0:2a15bd367891 124
shimogamo 0:2a15bd367891 125 void airspeedTask(void const *pvParameters){
shimogamo 0:2a15bd367891 126 while(1){
shimogamo 0:2a15bd367891 127 airspeed.update();
shimogamo 0:2a15bd367891 128 Thread::wait(200);
shimogamo 0:2a15bd367891 129 }
shimogamo 0:2a15bd367891 130 }
shimogamo 0:2a15bd367891 131
shimogamo 0:2a15bd367891 132 void cadenceTask(void const *pvParameters){
shimogamo 0:2a15bd367891 133 while(1){
shimogamo 0:2a15bd367891 134 cadence.update();
shimogamo 0:2a15bd367891 135 Thread::wait(200);
shimogamo 0:2a15bd367891 136 }
shimogamo 0:2a15bd367891 137 }
shimogamo 0:2a15bd367891 138
shimogamo 0:2a15bd367891 139 void displayTask(void const *pvParameters){
shimogamo 0:2a15bd367891 140 while(1){
shimogamo 0:2a15bd367891 141 display.update();
shimogamo 0:2a15bd367891 142 Thread::wait(50);
shimogamo 0:2a15bd367891 143 }
shimogamo 0:2a15bd367891 144 }
shimogamo 0:2a15bd367891 145
shimogamo 0:2a15bd367891 146 void xbeeTask(void const *pvParameters){
shimogamo 0:2a15bd367891 147 while(1){
shimogamo 0:2a15bd367891 148 xbee.update();
shimogamo 0:2a15bd367891 149 Thread::wait(50);
shimogamo 0:2a15bd367891 150 }
shimogamo 0:2a15bd367891 151 }
shimogamo 0:2a15bd367891 152
shimogamo 0:2a15bd367891 153
shimogamo 0:2a15bd367891 154 int main(void){
shimogamo 0:2a15bd367891 155 printf("start\n");
shimogamo 5:9a1ec02229dd 156
shimogamo 5:9a1ec02229dd 157 pc.attach(pc_rx,Serial::RxIrq);
shimogamo 5:9a1ec02229dd 158
shimogamo 6:0d9fa7152934 159 Global::initialize();
shimogamo 5:9a1ec02229dd 160 Thread InitializeTask(initializeTask);
shimogamo 0:2a15bd367891 161 Thread ControlTask(controlTask);
shimogamo 0:2a15bd367891 162 Thread AirspeedTask(airspeedTask);
shimogamo 0:2a15bd367891 163 Thread CadenceTask(cadenceTask);
shimogamo 0:2a15bd367891 164 Thread DisplayTask(displayTask);
shimogamo 0:2a15bd367891 165 Thread XbeeTask(xbeeTask);
shimogamo 0:2a15bd367891 166 printf("Task end\n");
shimogamo 0:2a15bd367891 167
shimogamo 0:2a15bd367891 168 Thread::wait(osWaitForever);
shimogamo 0:2a15bd367891 169 }