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.
Init.cpp@9:d1fc0805ec7d, 2015-10-14 (annotated)
- Committer:
- shimogamo
- Date:
- Wed Oct 14 13:44:32 2015 +0000
- Revision:
- 9:d1fc0805ec7d
- Child:
- 10:0a4bf8c82493
Init??????
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| shimogamo | 9:d1fc0805ec7d | 1 | #include "mbed.h" |
| shimogamo | 9:d1fc0805ec7d | 2 | #include "Global.h" |
| shimogamo | 9:d1fc0805ec7d | 3 | #include "Init.h" |
| shimogamo | 9:d1fc0805ec7d | 4 | #include <string> |
| shimogamo | 9:d1fc0805ec7d | 5 | #include <iostream> |
| shimogamo | 9:d1fc0805ec7d | 6 | |
| shimogamo | 9:d1fc0805ec7d | 7 | std::string Init::strbuf; |
| shimogamo | 9:d1fc0805ec7d | 8 | |
| shimogamo | 9:d1fc0805ec7d | 9 | void Init::getSerial(){ |
| shimogamo | 9:d1fc0805ec7d | 10 | osEvent evt = Global::queue.get(); |
| shimogamo | 9:d1fc0805ec7d | 11 | if(evt.status == osEventMessage){ |
| shimogamo | 9:d1fc0805ec7d | 12 | char temp = evt.value.v; |
| shimogamo | 9:d1fc0805ec7d | 13 | strbuf.push_back(temp); |
| shimogamo | 9:d1fc0805ec7d | 14 | if(temp == '\n'){ |
| shimogamo | 9:d1fc0805ec7d | 15 | std::string::size_type spaceIndex = strbuf.find(" "); |
| shimogamo | 9:d1fc0805ec7d | 16 | |
| shimogamo | 9:d1fc0805ec7d | 17 | if (spaceIndex != std::string::npos) {//数値データがあるコマンド(" "がある場合) |
| shimogamo | 9:d1fc0805ec7d | 18 | char *gomi; |
| shimogamo | 9:d1fc0805ec7d | 19 | std::string command = strbuf.substr(0, spaceIndex); |
| shimogamo | 9:d1fc0805ec7d | 20 | double num = strtod(strbuf.substr(spaceIndex+1, strbuf.size()-2).c_str(), &gomi);//strbuf.size()-1には'\n'が入っている |
| shimogamo | 9:d1fc0805ec7d | 21 | printf("coms=%s, num=%f\n", command.c_str(), num); |
| shimogamo | 9:d1fc0805ec7d | 22 | setting(command, num); |
| shimogamo | 9:d1fc0805ec7d | 23 | |
| shimogamo | 9:d1fc0805ec7d | 24 | }else{//数値データがないコマンド(" "がない場合) |
| shimogamo | 9:d1fc0805ec7d | 25 | std::string command = strbuf.substr(0,strbuf.size()-2); |
| shimogamo | 9:d1fc0805ec7d | 26 | setting(command); |
| shimogamo | 9:d1fc0805ec7d | 27 | } |
| shimogamo | 9:d1fc0805ec7d | 28 | //ここで,ニュートラル情報をLocalFileに保存 |
| shimogamo | 9:d1fc0805ec7d | 29 | Global::filewrite(); |
| shimogamo | 9:d1fc0805ec7d | 30 | strbuf.clear(); |
| shimogamo | 9:d1fc0805ec7d | 31 | } |
| shimogamo | 9:d1fc0805ec7d | 32 | if(strbuf.size() > 30)strbuf.clear(); |
| shimogamo | 9:d1fc0805ec7d | 33 | } |
| shimogamo | 9:d1fc0805ec7d | 34 | } |
| shimogamo | 9:d1fc0805ec7d | 35 | |
| shimogamo | 9:d1fc0805ec7d | 36 | |
| shimogamo | 9:d1fc0805ec7d | 37 | void Init::setting(std::string command, double num){ |
| shimogamo | 9:d1fc0805ec7d | 38 | if(command == "eleneu"){ |
| shimogamo | 9:d1fc0805ec7d | 39 | Global::setneutralpitch(num); |
| shimogamo | 9:d1fc0805ec7d | 40 | }else if(command == "elemax"){ |
| shimogamo | 9:d1fc0805ec7d | 41 | Global::setmaxpitch(num); |
| shimogamo | 9:d1fc0805ec7d | 42 | }else if(command == "elemin"){ |
| shimogamo | 9:d1fc0805ec7d | 43 | Global::setminpitch(num); |
| shimogamo | 9:d1fc0805ec7d | 44 | }else if(command == "rudneu"){ |
| shimogamo | 9:d1fc0805ec7d | 45 | Global::setneutralyaw(num); |
| shimogamo | 9:d1fc0805ec7d | 46 | }else if(command == "rudmax"){ |
| shimogamo | 9:d1fc0805ec7d | 47 | Global::setmaxyaw(num); |
| shimogamo | 9:d1fc0805ec7d | 48 | }else if(command == "rudmin"){ |
| shimogamo | 9:d1fc0805ec7d | 49 | Global::setminyaw(num); |
| shimogamo | 9:d1fc0805ec7d | 50 | |
| shimogamo | 9:d1fc0805ec7d | 51 | }else if(command == "eleneudeg"){ |
| shimogamo | 9:d1fc0805ec7d | 52 | Global::setneutralpitchdegree(num); |
| shimogamo | 9:d1fc0805ec7d | 53 | }else if(command == "elemaxdeg"){ |
| shimogamo | 9:d1fc0805ec7d | 54 | Global::setmaxpitchdegree(num); |
| shimogamo | 9:d1fc0805ec7d | 55 | }else if(command == "elemindeg"){ |
| shimogamo | 9:d1fc0805ec7d | 56 | Global::setminpitchdegree(num); |
| shimogamo | 9:d1fc0805ec7d | 57 | }else if(command == "rudneudeg"){ |
| shimogamo | 9:d1fc0805ec7d | 58 | Global::setneutralyawdegree(num); |
| shimogamo | 9:d1fc0805ec7d | 59 | }else if(command == "rudmaxdeg"){ |
| shimogamo | 9:d1fc0805ec7d | 60 | Global::setmaxyawdegree(num); |
| shimogamo | 9:d1fc0805ec7d | 61 | }else if(command == "rudmindeg"){ |
| shimogamo | 9:d1fc0805ec7d | 62 | Global::setminyawdegree(num); |
| shimogamo | 9:d1fc0805ec7d | 63 | |
| shimogamo | 9:d1fc0805ec7d | 64 | }else if(command == "elemaxplay"){ |
| shimogamo | 9:d1fc0805ec7d | 65 | Global::setmaxpitchplayratio(num); |
| shimogamo | 9:d1fc0805ec7d | 66 | }else if(command == "eleminplay"){ |
| shimogamo | 9:d1fc0805ec7d | 67 | Global::setminpitchplayratio(num); |
| shimogamo | 9:d1fc0805ec7d | 68 | }else if(command == "rudmaxplay"){ |
| shimogamo | 9:d1fc0805ec7d | 69 | Global::setmaxyawplayratio(num); |
| shimogamo | 9:d1fc0805ec7d | 70 | }else if(command == "rudminplay"){ |
| shimogamo | 9:d1fc0805ec7d | 71 | Global::setminyawplayratio(num); |
| shimogamo | 9:d1fc0805ec7d | 72 | }else if(command == "eletrim"){ |
| shimogamo | 9:d1fc0805ec7d | 73 | Global::settrimpitchrate(num); |
| shimogamo | 9:d1fc0805ec7d | 74 | |
| shimogamo | 9:d1fc0805ec7d | 75 | }else{ |
| shimogamo | 9:d1fc0805ec7d | 76 | printf("Invalid Input\n"); |
| shimogamo | 9:d1fc0805ec7d | 77 | } |
| shimogamo | 9:d1fc0805ec7d | 78 | } |
| shimogamo | 9:d1fc0805ec7d | 79 | |
| shimogamo | 9:d1fc0805ec7d | 80 | void Init::setting(std::string command){ |
| shimogamo | 9:d1fc0805ec7d | 81 | if(command == "eleneu"){ |
| shimogamo | 9:d1fc0805ec7d | 82 | Global::setneutralpitch(Global::getpitch()); |
| shimogamo | 9:d1fc0805ec7d | 83 | }else if(command == "elemax"){ |
| shimogamo | 9:d1fc0805ec7d | 84 | Global::setmaxpitch(Global::getpitch()); |
| shimogamo | 9:d1fc0805ec7d | 85 | }else if(command == "elemin"){ |
| shimogamo | 9:d1fc0805ec7d | 86 | Global::setminpitch(Global::getpitch()); |
| shimogamo | 9:d1fc0805ec7d | 87 | }else if(command == "rudneu"){ |
| shimogamo | 9:d1fc0805ec7d | 88 | Global::setneutralyaw(Global::getyaw()); |
| shimogamo | 9:d1fc0805ec7d | 89 | }else if(command == "rudmax"){ |
| shimogamo | 9:d1fc0805ec7d | 90 | Global::setmaxyaw(Global::getyaw()); |
| shimogamo | 9:d1fc0805ec7d | 91 | }else if(command == "rudmin"){ |
| shimogamo | 9:d1fc0805ec7d | 92 | Global::setminyaw(Global::getyaw()); |
| shimogamo | 9:d1fc0805ec7d | 93 | |
| shimogamo | 9:d1fc0805ec7d | 94 | }else if(command == "eleneudeg"){ |
| shimogamo | 9:d1fc0805ec7d | 95 | Global::setneutralpitchdegree(Global::getpitchdegree()); |
| shimogamo | 9:d1fc0805ec7d | 96 | }else if(command == "elemaxdeg"){ |
| shimogamo | 9:d1fc0805ec7d | 97 | Global::setmaxpitchdegree(Global::getpitchdegree()); |
| shimogamo | 9:d1fc0805ec7d | 98 | }else if(command == "elemindeg"){ |
| shimogamo | 9:d1fc0805ec7d | 99 | Global::setminpitchdegree(Global::getpitchdegree()); |
| shimogamo | 9:d1fc0805ec7d | 100 | }else if(command == "rudneudeg"){ |
| shimogamo | 9:d1fc0805ec7d | 101 | Global::setneutralyawdegree(Global::getyawdegree()); |
| shimogamo | 9:d1fc0805ec7d | 102 | }else if(command == "rudmaxdeg"){ |
| shimogamo | 9:d1fc0805ec7d | 103 | Global::setmaxyawdegree(Global::getyawdegree()); |
| shimogamo | 9:d1fc0805ec7d | 104 | }else if(command == "rudmindeg"){ |
| shimogamo | 9:d1fc0805ec7d | 105 | Global::setminyawdegree(Global::getyawdegree()); |
| shimogamo | 9:d1fc0805ec7d | 106 | |
| shimogamo | 9:d1fc0805ec7d | 107 | }else if(command == "show"){ |
| shimogamo | 9:d1fc0805ec7d | 108 | showParam(); |
| shimogamo | 9:d1fc0805ec7d | 109 | |
| shimogamo | 9:d1fc0805ec7d | 110 | }else{ |
| shimogamo | 9:d1fc0805ec7d | 111 | printf("Invalid Input\n"); |
| shimogamo | 9:d1fc0805ec7d | 112 | } |
| shimogamo | 9:d1fc0805ec7d | 113 | } |
| shimogamo | 9:d1fc0805ec7d | 114 | |
| shimogamo | 9:d1fc0805ec7d | 115 | void Init::showParam(){ |
| shimogamo | 9:d1fc0805ec7d | 116 | printf("------Servo Parameter------\n"); |
| shimogamo | 9:d1fc0805ec7d | 117 | printf("elevatorNeutral = %f\n", Global::getneutralpitch()); |
| shimogamo | 9:d1fc0805ec7d | 118 | printf("elevatorMax = %f\n", Global::getmaxpitch()); |
| shimogamo | 9:d1fc0805ec7d | 119 | printf("elevatorMin = %f\n", Global::getminpitch()); |
| shimogamo | 9:d1fc0805ec7d | 120 | printf("rudderNeutral = %f\n", Global::getneutralyaw()); |
| shimogamo | 9:d1fc0805ec7d | 121 | printf("rudderMax = %f\n", Global::getmaxyaw()); |
| shimogamo | 9:d1fc0805ec7d | 122 | printf("rudderMin = %f\n", Global::getminyaw()); |
| shimogamo | 9:d1fc0805ec7d | 123 | printf("----Controller Parameter----\n"); |
| shimogamo | 9:d1fc0805ec7d | 124 | printf("elevatorNeutral = %f\n", Global::getneutralpitchdegree()); |
| shimogamo | 9:d1fc0805ec7d | 125 | printf("elevatorMax = %f\n", Global::getmaxpitchdegree()); |
| shimogamo | 9:d1fc0805ec7d | 126 | printf("elevatorMin = %f\n", Global::getminpitchdegree()); |
| shimogamo | 9:d1fc0805ec7d | 127 | printf("rudderNeutral = %f\n", Global::getneutralyawdegree()); |
| shimogamo | 9:d1fc0805ec7d | 128 | printf("rudderMax = %f\n", Global::getmaxyawdegree()); |
| shimogamo | 9:d1fc0805ec7d | 129 | printf("rudderMin = %f\n", Global::getminyawdegree()); |
| shimogamo | 9:d1fc0805ec7d | 130 | printf("------Controller Play------\n"); |
| shimogamo | 9:d1fc0805ec7d | 131 | printf("elevatorMaxPlay = %f\n", Global::getmaxpitchplayratio()); |
| shimogamo | 9:d1fc0805ec7d | 132 | printf("elevatorMinPlay = %f\n", Global::getminpitchplayratio()); |
| shimogamo | 9:d1fc0805ec7d | 133 | printf("rudderMaxPlay = %f\n", Global::getmaxyawplayratio()); |
| shimogamo | 9:d1fc0805ec7d | 134 | printf("rudderMinPlay = %f\n", Global::getminyawplayratio()); |
| shimogamo | 9:d1fc0805ec7d | 135 | printf("-------Trim Parameter-------\n"); |
| shimogamo | 9:d1fc0805ec7d | 136 | printf("elevatorTrimRate = %f\n", Global::gettrimpitchrate()); |
| shimogamo | 9:d1fc0805ec7d | 137 | } |