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@5:9a1ec02229dd, 2015-10-09 (annotated)
- Committer:
- shimogamo
- Date:
- Fri Oct 09 14:29:32 2015 +0000
- Revision:
- 5:9a1ec02229dd
- Parent:
- 2:e0f1e8662b8c
- Child:
- 6:0d9fa7152934
main.cpp??initialize??????????????string????
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 | 5:9a1ec02229dd | 13 | |
shimogamo | 5:9a1ec02229dd | 14 | #define BUFMAX 20 |
shimogamo | 5:9a1ec02229dd | 15 | |
shimogamo | 5:9a1ec02229dd | 16 | RawSerial pc(USBTX, USBRX); |
shimogamo | 5:9a1ec02229dd | 17 | Queue<char, BUFMAX> queue; |
shimogamo | 0:2a15bd367891 | 18 | |
shimogamo | 0:2a15bd367891 | 19 | |
shimogamo | 0:2a15bd367891 | 20 | Display display(p9, p10); |
shimogamo | 0:2a15bd367891 | 21 | XBee xbee(p13, p14); |
shimogamo | 0:2a15bd367891 | 22 | Trim trim(p16, p17, p15); |
shimogamo | 0:2a15bd367891 | 23 | ControllerManager controllerManager(p18,p19,p20); |
shimogamo | 0:2a15bd367891 | 24 | ServoManager servoManager(p21, p22); |
shimogamo | 0:2a15bd367891 | 25 | Airspeed airspeed(p26, NC, NC); |
shimogamo | 0:2a15bd367891 | 26 | Cadence cadence(p29, p30, NC); |
shimogamo | 0:2a15bd367891 | 27 | |
shimogamo | 0:2a15bd367891 | 28 | |
shimogamo | 5:9a1ec02229dd | 29 | void pc_rx(){ |
shimogamo | 5:9a1ec02229dd | 30 | while(pc.readable()==1){ |
shimogamo | 5:9a1ec02229dd | 31 | char buf = pc.getc(); |
shimogamo | 5:9a1ec02229dd | 32 | queue.put((char*)buf); |
shimogamo | 0:2a15bd367891 | 33 | } |
shimogamo | 0:2a15bd367891 | 34 | } |
shimogamo | 0:2a15bd367891 | 35 | |
shimogamo | 5:9a1ec02229dd | 36 | |
shimogamo | 5:9a1ec02229dd | 37 | void initializeTask(void const *pvParametersd){ |
shimogamo | 5:9a1ec02229dd | 38 | std::string strbuf; |
shimogamo | 5:9a1ec02229dd | 39 | while(1){ |
shimogamo | 5:9a1ec02229dd | 40 | osEvent evt = queue.get(); |
shimogamo | 5:9a1ec02229dd | 41 | if(evt.status == osEventMessage){ |
shimogamo | 5:9a1ec02229dd | 42 | char temp = evt.value.v; |
shimogamo | 5:9a1ec02229dd | 43 | strbuf.push_back(temp); |
shimogamo | 5:9a1ec02229dd | 44 | if(temp == '\n'){ |
shimogamo | 5:9a1ec02229dd | 45 | Global::led1 = 1; |
shimogamo | 5:9a1ec02229dd | 46 | |
shimogamo | 5:9a1ec02229dd | 47 | std::string::size_type spaceIndex = strbuf.find(" "); |
shimogamo | 5:9a1ec02229dd | 48 | if (spaceIndex != std::string::npos) { |
shimogamo | 5:9a1ec02229dd | 49 | char *gomi; |
shimogamo | 5:9a1ec02229dd | 50 | std::string command = strbuf.substr(0, spaceIndex); |
shimogamo | 5:9a1ec02229dd | 51 | double num = strtod(strbuf.substr(spaceIndex+1, strbuf.size()-1).c_str(), &gomi); |
shimogamo | 5:9a1ec02229dd | 52 | |
shimogamo | 5:9a1ec02229dd | 53 | pc.printf("coms=%s, num=%f\n", command.c_str(), num); |
shimogamo | 5:9a1ec02229dd | 54 | |
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 | 5:9a1ec02229dd | 68 | } |
shimogamo | 5:9a1ec02229dd | 69 | |
shimogamo | 5:9a1ec02229dd | 70 | strbuf.clear(); |
shimogamo | 5:9a1ec02229dd | 71 | //ここで,ニュートラル情報をLocalFileに保存 |
shimogamo | 5:9a1ec02229dd | 72 | } |
shimogamo | 5:9a1ec02229dd | 73 | } |
shimogamo | 5:9a1ec02229dd | 74 | Thread::wait(10); |
shimogamo | 5:9a1ec02229dd | 75 | if(strbuf.size() >= BUFMAX){ |
shimogamo | 5:9a1ec02229dd | 76 | pc.printf("\nInput Error ... "); |
shimogamo | 5:9a1ec02229dd | 77 | strbuf.clear(); |
shimogamo | 5:9a1ec02229dd | 78 | pc.printf("Buffer clear\n"); |
shimogamo | 5:9a1ec02229dd | 79 | } |
shimogamo | 5:9a1ec02229dd | 80 | } |
shimogamo | 5:9a1ec02229dd | 81 | } |
shimogamo | 5:9a1ec02229dd | 82 | } |
shimogamo | 5:9a1ec02229dd | 83 | |
shimogamo | 5:9a1ec02229dd | 84 | |
shimogamo | 0:2a15bd367891 | 85 | void controlTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 86 | while(1){ |
shimogamo | 2:e0f1e8662b8c | 87 | trim.update(); |
shimogamo | 0:2a15bd367891 | 88 | controllerManager.update(); |
shimogamo | 0:2a15bd367891 | 89 | servoManager.update(); |
shimogamo | 0:2a15bd367891 | 90 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 91 | } |
shimogamo | 0:2a15bd367891 | 92 | } |
shimogamo | 0:2a15bd367891 | 93 | |
shimogamo | 0:2a15bd367891 | 94 | void airspeedTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 95 | while(1){ |
shimogamo | 0:2a15bd367891 | 96 | airspeed.update(); |
shimogamo | 0:2a15bd367891 | 97 | Thread::wait(200); |
shimogamo | 0:2a15bd367891 | 98 | } |
shimogamo | 0:2a15bd367891 | 99 | } |
shimogamo | 0:2a15bd367891 | 100 | |
shimogamo | 0:2a15bd367891 | 101 | void cadenceTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 102 | while(1){ |
shimogamo | 0:2a15bd367891 | 103 | cadence.update(); |
shimogamo | 0:2a15bd367891 | 104 | Thread::wait(200); |
shimogamo | 0:2a15bd367891 | 105 | } |
shimogamo | 0:2a15bd367891 | 106 | } |
shimogamo | 0:2a15bd367891 | 107 | |
shimogamo | 0:2a15bd367891 | 108 | void displayTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 109 | while(1){ |
shimogamo | 0:2a15bd367891 | 110 | display.update(); |
shimogamo | 0:2a15bd367891 | 111 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 112 | } |
shimogamo | 0:2a15bd367891 | 113 | } |
shimogamo | 0:2a15bd367891 | 114 | |
shimogamo | 0:2a15bd367891 | 115 | void xbeeTask(void const *pvParameters){ |
shimogamo | 0:2a15bd367891 | 116 | while(1){ |
shimogamo | 0:2a15bd367891 | 117 | xbee.update(); |
shimogamo | 0:2a15bd367891 | 118 | Thread::wait(50); |
shimogamo | 0:2a15bd367891 | 119 | } |
shimogamo | 0:2a15bd367891 | 120 | } |
shimogamo | 0:2a15bd367891 | 121 | |
shimogamo | 0:2a15bd367891 | 122 | |
shimogamo | 0:2a15bd367891 | 123 | int main(void){ |
shimogamo | 0:2a15bd367891 | 124 | printf("start\n"); |
shimogamo | 5:9a1ec02229dd | 125 | |
shimogamo | 5:9a1ec02229dd | 126 | pc.attach(pc_rx,Serial::RxIrq); |
shimogamo | 5:9a1ec02229dd | 127 | |
shimogamo | 0:2a15bd367891 | 128 | Global::timer.start(); |
shimogamo | 5:9a1ec02229dd | 129 | Thread InitializeTask(initializeTask); |
shimogamo | 0:2a15bd367891 | 130 | Thread ControlTask(controlTask); |
shimogamo | 0:2a15bd367891 | 131 | Thread AirspeedTask(airspeedTask); |
shimogamo | 0:2a15bd367891 | 132 | Thread CadenceTask(cadenceTask); |
shimogamo | 0:2a15bd367891 | 133 | Thread DisplayTask(displayTask); |
shimogamo | 0:2a15bd367891 | 134 | Thread XbeeTask(xbeeTask); |
shimogamo | 0:2a15bd367891 | 135 | printf("Task end\n"); |
shimogamo | 0:2a15bd367891 | 136 | |
shimogamo | 0:2a15bd367891 | 137 | Thread::wait(osWaitForever); |
shimogamo | 0:2a15bd367891 | 138 | } |