Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@6:0d9fa7152934, 2015-10-10 (annotated)
- Committer:
- shimogamo
- Date:
- Sat Oct 10 20:16:31 2015 +0000
- Revision:
- 6:0d9fa7152934
- Parent:
- 5:9a1ec02229dd
- Child:
- 7:6f7bd18ce796
??????????????csv????????????????????????????????????????????
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:9a1ec02229dd | 49 | if (spaceIndex != std::string::npos) { |
shimogamo | 5:9a1ec02229dd | 50 | char *gomi; |
shimogamo | 5:9a1ec02229dd | 51 | std::string command = strbuf.substr(0, spaceIndex); |
shimogamo | 5:9a1ec02229dd | 52 | double num = strtod(strbuf.substr(spaceIndex+1, strbuf.size()-1).c_str(), &gomi); |
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 | |
shimogamo | 5:9a1ec02229dd | 57 | if(command == "eleneu"){ |
shimogamo | 5:9a1ec02229dd | 58 | Global::setneutralpitch(num); |
shimogamo | 5:9a1ec02229dd | 59 | }else if(command == "elemax"){ |
shimogamo | 5:9a1ec02229dd | 60 | Global::setmaxpitch(num); |
shimogamo | 5:9a1ec02229dd | 61 | }else if(command == "elemin"){ |
shimogamo | 5:9a1ec02229dd | 62 | Global::setminpitch(num); |
shimogamo | 5:9a1ec02229dd | 63 | }else if(command == "rudneu"){ |
shimogamo | 5:9a1ec02229dd | 64 | Global::setneutralyaw(num); |
shimogamo | 5:9a1ec02229dd | 65 | }else if(command == "rudmax"){ |
shimogamo | 5:9a1ec02229dd | 66 | Global::setmaxyaw(num); |
shimogamo | 5:9a1ec02229dd | 67 | }else if(command == "rudmin"){ |
shimogamo | 5:9a1ec02229dd | 68 | Global::setminyaw(num); |
shimogamo | 5:9a1ec02229dd | 69 | } |
shimogamo | 5:9a1ec02229dd | 70 | |
shimogamo | 5:9a1ec02229dd | 71 | strbuf.clear(); |
shimogamo | 6:0d9fa7152934 | 72 | //ここで,ニュートラル情報をLocalFileに保存 |
shimogamo | 6:0d9fa7152934 | 73 | Global::filewrite(); |
shimogamo | 5:9a1ec02229dd | 74 | } |
shimogamo | 5:9a1ec02229dd | 75 | } |
shimogamo | 5:9a1ec02229dd | 76 | Thread::wait(10); |
shimogamo | 5:9a1ec02229dd | 77 | if(strbuf.size() >= BUFMAX){ |
shimogamo | 5:9a1ec02229dd | 78 | pc.printf("\nInput Error ... "); |
shimogamo | 5:9a1ec02229dd | 79 | strbuf.clear(); |
shimogamo | 5:9a1ec02229dd | 80 | pc.printf("Buffer clear\n"); |
shimogamo | 5:9a1ec02229dd | 81 | } |
shimogamo | 5:9a1ec02229dd | 82 | } |
shimogamo | 5:9a1ec02229dd | 83 | } |
shimogamo | 5:9a1ec02229dd | 84 | } |
shimogamo | 5:9a1ec02229dd | 85 | |
shimogamo | 5:9a1ec02229dd | 86 | |
shimogamo | 0:2a15bd367891 | 87 | void controlTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 88 | while(1){ |
shimogamo | 2:e0f1e8662b8c | 89 | trim.update(); |
shimogamo | 0:2a15bd367891 | 90 | controllerManager.update(); |
shimogamo | 0:2a15bd367891 | 91 | servoManager.update(); |
shimogamo | 0:2a15bd367891 | 92 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 93 | } |
shimogamo | 0:2a15bd367891 | 94 | } |
shimogamo | 0:2a15bd367891 | 95 | |
shimogamo | 0:2a15bd367891 | 96 | void airspeedTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 97 | while(1){ |
shimogamo | 0:2a15bd367891 | 98 | airspeed.update(); |
shimogamo | 0:2a15bd367891 | 99 | Thread::wait(200); |
shimogamo | 0:2a15bd367891 | 100 | } |
shimogamo | 0:2a15bd367891 | 101 | } |
shimogamo | 0:2a15bd367891 | 102 | |
shimogamo | 0:2a15bd367891 | 103 | void cadenceTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 104 | while(1){ |
shimogamo | 0:2a15bd367891 | 105 | cadence.update(); |
shimogamo | 0:2a15bd367891 | 106 | Thread::wait(200); |
shimogamo | 0:2a15bd367891 | 107 | } |
shimogamo | 0:2a15bd367891 | 108 | } |
shimogamo | 0:2a15bd367891 | 109 | |
shimogamo | 0:2a15bd367891 | 110 | void displayTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 111 | while(1){ |
shimogamo | 0:2a15bd367891 | 112 | display.update(); |
shimogamo | 0:2a15bd367891 | 113 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 114 | } |
shimogamo | 0:2a15bd367891 | 115 | } |
shimogamo | 0:2a15bd367891 | 116 | |
shimogamo | 0:2a15bd367891 | 117 | void xbeeTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 118 | while(1){ |
shimogamo | 0:2a15bd367891 | 119 | xbee.update(); |
shimogamo | 0:2a15bd367891 | 120 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 121 | } |
shimogamo | 0:2a15bd367891 | 122 | } |
shimogamo | 0:2a15bd367891 | 123 | |
shimogamo | 0:2a15bd367891 | 124 | |
shimogamo | 0:2a15bd367891 | 125 | int main(void){ |
shimogamo | 0:2a15bd367891 | 126 | printf("start\n"); |
shimogamo | 5:9a1ec02229dd | 127 | |
shimogamo | 5:9a1ec02229dd | 128 | pc.attach(pc_rx,Serial::RxIrq); |
shimogamo | 5:9a1ec02229dd | 129 | |
shimogamo | 6:0d9fa7152934 | 130 | Global::initialize(); |
shimogamo | 5:9a1ec02229dd | 131 | Thread InitializeTask(initializeTask); |
shimogamo | 0:2a15bd367891 | 132 | Thread ControlTask(controlTask); |
shimogamo | 0:2a15bd367891 | 133 | Thread AirspeedTask(airspeedTask); |
shimogamo | 0:2a15bd367891 | 134 | Thread CadenceTask(cadenceTask); |
shimogamo | 0:2a15bd367891 | 135 | Thread DisplayTask(displayTask); |
shimogamo | 0:2a15bd367891 | 136 | Thread XbeeTask(xbeeTask); |
shimogamo | 0:2a15bd367891 | 137 | printf("Task end\n"); |
shimogamo | 0:2a15bd367891 | 138 | |
shimogamo | 0:2a15bd367891 | 139 | Thread::wait(osWaitForever); |
shimogamo | 0:2a15bd367891 | 140 | } |