kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Sat Mar 18 08:34:17 2017 +0000
Revision:
35:63ccdae58da4
Parent:
34:770a6bbb4d63
Child:
36:ad6b2b81bb89
FlashMemory.h??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimogamo 0:2a15bd367891 1 #include "mbed.h"
shimogamo 0:2a15bd367891 2 #include "Global.h"
shimogamo 9:d1fc0805ec7d 3 #include "rtos.h"
shimogamo 35:63ccdae58da4 4 #include "FlashManager.h"
shimogamo 35:63ccdae58da4 5 extern RawSerial pc3(USBTX, USBRX);
shimogamo 3:e3c41153e5fe 6
shimogamo 26:a53c3208ac35 7 //クラスじゃなくてnamespaceのほうが綺麗にかけるかもね
shimogamo 35:63ccdae58da4 8 void Global::setpc(RawSerial _pc){
shimogamo 35:63ccdae58da4 9 _pc.printf("setpc\n");
shimogamo 35:63ccdae58da4 10 }
shimogamo 26:a53c3208ac35 11
shimogamo 12:8e39bb45c61c 12 Queue<char, 20> Global::initqueue;
shimogamo 35:63ccdae58da4 13 //----------------FlashMemory(pin指定はここで)--------------------------------------------
shimogamo 35:63ccdae58da4 14 SPI Global::spi(PA_7, PA_6, PA_5);// mosi, miso, sclk
shimogamo 35:63ccdae58da4 15 FlashManager Global::memory(spi, PB_9);//spi, cs
shimogamo 25:589742cd3137 16 //----------------普段は変動しない変数------------------------------------------------------
shimogamo 9:d1fc0805ec7d 17 //サーボのパラメータ(角度(度数法)で設定)max,minはニュートラルを基準にしている
shimogamo 4:650af94bf062 18 double Global::maxpitch = 5.0;
shimogamo 4:650af94bf062 19 double Global::minpitch = -5.0;
shimogamo 4:650af94bf062 20 double Global::neutralpitch = 0;
shimogamo 4:650af94bf062 21 double Global::maxyaw = 30.0;
shimogamo 4:650af94bf062 22 double Global::minyaw = -30.0;
shimogamo 4:650af94bf062 23 double Global::neutralyaw = 0;
shimogamo 8:ca92cb674004 24 //ジョイスティックのパラメータ(mbedのAnalogIn値[0,1])/max, min, neu全て[0,1]の絶対的な値をとる
shimogamo 4:650af94bf062 25 double Global::maxpitchdegree = 1.0;
shimogamo 4:650af94bf062 26 double Global::minpitchdegree = 0;
shimogamo 4:650af94bf062 27 double Global::neutralpitchdegree = 0.5;
shimogamo 4:650af94bf062 28 double Global::maxyawdegree = 1.0;
shimogamo 4:650af94bf062 29 double Global::minyawdegree = 0;
shimogamo 4:650af94bf062 30 double Global::neutralyawdegree = 0.5;
shimogamo 9:d1fc0805ec7d 31 //ジョイスティックの遊び([-1,1]でニュートラルを0とした時の値)
shimogamo 35:63ccdae58da4 32 double Global::maxpitchplayratio = 0.1;
shimogamo 35:63ccdae58da4 33 double Global::minpitchplayratio = -0.1;
shimogamo 35:63ccdae58da4 34 double Global::maxyawplayratio = 0.1;
shimogamo 35:63ccdae58da4 35 double Global::minyawplayratio = -0.1;
shimogamo 9:d1fc0805ec7d 36 //トリムの変化率(角度(度数法)で設定)
shimogamo 9:d1fc0805ec7d 37 double Global::trimpitchrate = 0.5;
shimogamo 3:e3c41153e5fe 38
shimogamo 3:e3c41153e5fe 39 //----------------周期的に変動する変数------------------------------------------------------
shimogamo 8:ca92cb674004 40 double Global::pitch;
shimogamo 8:ca92cb674004 41 double Global::pitchdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 42 int Global::inttrimpitch;
shimogamo 8:ca92cb674004 43 double Global::yaw;
shimogamo 8:ca92cb674004 44 double Global::yawdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 45 int Global::inttrimyaw;
shimogamo 1:3f857674a290 46 double Global::airspeed;
naoya1687 33:d939479e7b13 47 float Global::cadence;
naoya1687 33:d939479e7b13 48 float Global::ultsonic;
shimogamo 10:0a4bf8c82493 49 double Global::atmpress;
naoya1687 32:13aba70baa4b 50 //int Global::selector;
naoya1687 33:d939479e7b13 51 float Global::cadencevolt;
naoya1687 33:d939479e7b13 52 float Global::ultsonicvolt;
shimogamo 19:c6ad6b453b39 53 double Global::servovolt;
shimogamo 19:c6ad6b453b39 54 double Global::miconvolt;
shimogamo 0:2a15bd367891 55
shimogamo 13:a8e10a69df45 56 int Global::pitchtime;
shimogamo 13:a8e10a69df45 57 int Global::pitchdegreetime;
shimogamo 13:a8e10a69df45 58 int Global::inttrimpitchtime;
shimogamo 13:a8e10a69df45 59 int Global::yawtime;
shimogamo 13:a8e10a69df45 60 int Global::yawdegreetime;
shimogamo 13:a8e10a69df45 61 int Global::inttrimyawtime;
shimogamo 13:a8e10a69df45 62 int Global::airspeedtime;
shimogamo 13:a8e10a69df45 63 int Global::cadencetime;
shimogamo 13:a8e10a69df45 64 int Global::ultsonictime;
shimogamo 13:a8e10a69df45 65 int Global::atmpresstime;
naoya1687 32:13aba70baa4b 66 //int Global::selectortime;
naoya1687 31:cef6ee7af014 67 int Global::cadencevolttime;
naoya1687 31:cef6ee7af014 68 int Global::ultsonicvolttime;
shimogamo 19:c6ad6b453b39 69 int Global::servovolttime;
shimogamo 19:c6ad6b453b39 70 int Global::miconvolttime;
shimogamo 12:8e39bb45c61c 71
shimogamo 4:650af94bf062 72 //----------------どこからでも使えるled,スイッチ,タイマーの一括管理-----------------------------
shimogamo 0:2a15bd367891 73 Timer Global::timer;
naoya1687 34:770a6bbb4d63 74 DigitalOut Global::led(LED2);
shimogamo 6:0d9fa7152934 75
shimogamo 26:a53c3208ac35 76 //ここでINIT.csvファイルが読み込まれる
shimogamo 5:9a1ec02229dd 77 void Global::initialize(){
shimogamo 6:0d9fa7152934 78 timer.start();
shimogamo 35:63ccdae58da4 79 memory.reset();
naoya1687 34:770a6bbb4d63 80 //fileread();
shimogamo 6:0d9fa7152934 81 }
shimogamo 6:0d9fa7152934 82
shimogamo 26:a53c3208ac35 83 //INITファイルの読み込み
shimogamo 35:63ccdae58da4 84 void Global::fileread(){
shimogamo 35:63ccdae58da4 85 /***********Memoryに値が保存されていない場合filewrite()**********/
shimogamo 35:63ccdae58da4 86
shimogamo 35:63ccdae58da4 87 /************************************************************/
shimogamo 35:63ccdae58da4 88
shimogamo 35:63ccdae58da4 89 vector<double> param(17);
shimogamo 35:63ccdae58da4 90 param = memory.readdouble(0x0,17);
shimogamo 35:63ccdae58da4 91
shimogamo 35:63ccdae58da4 92 setneutralpitch(param[0]);
shimogamo 35:63ccdae58da4 93 setmaxpitch(param[1]);
shimogamo 35:63ccdae58da4 94 setminpitch(param[2]);
shimogamo 35:63ccdae58da4 95 setneutralyaw(param[3]);
shimogamo 35:63ccdae58da4 96 setmaxyaw(param[4]);
shimogamo 35:63ccdae58da4 97 setminyaw(param[5]);
shimogamo 35:63ccdae58da4 98
shimogamo 35:63ccdae58da4 99 setneutralpitchdegree(param[6]);
shimogamo 35:63ccdae58da4 100 setmaxpitchdegree(param[7]);
shimogamo 35:63ccdae58da4 101 setminpitchdegree(param[8]);
shimogamo 35:63ccdae58da4 102 setneutralyawdegree(param[9]);
shimogamo 35:63ccdae58da4 103 setmaxyawdegree(param[10]);
shimogamo 35:63ccdae58da4 104 setminyawdegree(param[11]);
shimogamo 35:63ccdae58da4 105
shimogamo 35:63ccdae58da4 106 setmaxpitchplayratio(param[12]);
shimogamo 35:63ccdae58da4 107 setminpitchplayratio(param[13]);
shimogamo 35:63ccdae58da4 108 setmaxyawplayratio(param[14]);
shimogamo 35:63ccdae58da4 109 setminyawplayratio(param[15]);
shimogamo 35:63ccdae58da4 110 settrimpitchrate(param[16]);
shimogamo 6:0d9fa7152934 111 }
shimogamo 6:0d9fa7152934 112
shimogamo 26:a53c3208ac35 113 //INITファイルの書き込み
shimogamo 6:0d9fa7152934 114 void Global::filewrite(){
shimogamo 35:63ccdae58da4 115 // pc.printf("push");
shimogamo 35:63ccdae58da4 116 vector<double> param;
shimogamo 35:63ccdae58da4 117
shimogamo 35:63ccdae58da4 118 param.push_back(getneutralpitch());
shimogamo 35:63ccdae58da4 119 param.push_back(getmaxpitch());
shimogamo 35:63ccdae58da4 120 param.push_back(getminpitch());
shimogamo 35:63ccdae58da4 121 param.push_back(getneutralyaw());
shimogamo 35:63ccdae58da4 122 param.push_back(getmaxyaw());
shimogamo 35:63ccdae58da4 123 param.push_back(getminyaw());
shimogamo 35:63ccdae58da4 124
shimogamo 35:63ccdae58da4 125 param.push_back(getneutralpitchdegree());
shimogamo 35:63ccdae58da4 126 param.push_back(getmaxpitchdegree());
shimogamo 35:63ccdae58da4 127 param.push_back(getminpitchdegree());
shimogamo 35:63ccdae58da4 128 param.push_back(getneutralyawdegree());
shimogamo 35:63ccdae58da4 129 param.push_back(getmaxyawdegree());
shimogamo 35:63ccdae58da4 130 param.push_back(getminyawdegree());
shimogamo 35:63ccdae58da4 131
shimogamo 35:63ccdae58da4 132 param.push_back(getmaxpitchplayratio());
shimogamo 35:63ccdae58da4 133 param.push_back(getminpitchplayratio());
shimogamo 35:63ccdae58da4 134 param.push_back(getmaxyawplayratio());
shimogamo 35:63ccdae58da4 135 param.push_back(getminyawplayratio());
shimogamo 35:63ccdae58da4 136 param.push_back(gettrimpitchrate());
shimogamo 35:63ccdae58da4 137 pc3.printf("%d\n",param.size());
shimogamo 35:63ccdae58da4 138 pc3.printf("write\n");
shimogamo 35:63ccdae58da4 139 memory.writedouble(0x0,param);
shimogamo 35:63ccdae58da4 140 pc3.printf("written\n");
shimogamo 35:63ccdae58da4 141 }
shimogamo 1:3f857674a290 142
shimogamo 25:589742cd3137 143 //init等で更新される変数
shimogamo 4:650af94bf062 144 double Global::getmaxpitch(){return maxpitch;}
shimogamo 4:650af94bf062 145 double Global::getminpitch(){return minpitch;}
shimogamo 4:650af94bf062 146 double Global::getneutralpitch(){return neutralpitch;}
shimogamo 4:650af94bf062 147 double Global::getmaxyaw(){return maxyaw;}
shimogamo 4:650af94bf062 148 double Global::getminyaw(){return minyaw;}
shimogamo 4:650af94bf062 149 double Global::getneutralyaw(){return neutralyaw;}
shimogamo 4:650af94bf062 150
shimogamo 4:650af94bf062 151 void Global::setmaxpitch(double _maxpitch){maxpitch = _maxpitch;}
shimogamo 4:650af94bf062 152 void Global::setminpitch(double _minpitch){minpitch = _minpitch;}
shimogamo 4:650af94bf062 153 void Global::setneutralpitch(double _neutralpitch){neutralpitch = _neutralpitch;}
shimogamo 4:650af94bf062 154 void Global::setmaxyaw(double _maxyaw){maxyaw = _maxyaw;}
shimogamo 4:650af94bf062 155 void Global::setminyaw(double _minyaw){minyaw = _minyaw;}
shimogamo 4:650af94bf062 156 void Global::setneutralyaw(double _neutralyaw){neutralyaw = _neutralyaw;}
shimogamo 4:650af94bf062 157
shimogamo 4:650af94bf062 158 double Global::getmaxpitchdegree(){return maxpitchdegree;}
shimogamo 4:650af94bf062 159 double Global::getneutralpitchdegree(){return neutralpitchdegree;}
shimogamo 4:650af94bf062 160 double Global::getminpitchdegree(){return minpitchdegree;}
shimogamo 4:650af94bf062 161 double Global::getmaxyawdegree(){return maxyawdegree;}
shimogamo 4:650af94bf062 162 double Global::getneutralyawdegree(){return neutralyawdegree;}
shimogamo 4:650af94bf062 163 double Global::getminyawdegree(){return minyawdegree;}
shimogamo 4:650af94bf062 164
shimogamo 0:2a15bd367891 165 void Global::setmaxpitchdegree(double _maxpitchdegree){maxpitchdegree=_maxpitchdegree;}
shimogamo 0:2a15bd367891 166 void Global::setneutralpitchdegree(double _neutralpitchdegree){neutralpitchdegree=_neutralpitchdegree;}
shimogamo 0:2a15bd367891 167 void Global::setminpitchdegree(double _minpitchdegree){minpitchdegree=_minpitchdegree;}
shimogamo 0:2a15bd367891 168 void Global::setmaxyawdegree(double _maxyawdegree){maxyawdegree=_maxyawdegree;}
shimogamo 0:2a15bd367891 169 void Global::setneutralyawdegree(double _neutralyawdegree){neutralyawdegree=_neutralyawdegree;}
shimogamo 0:2a15bd367891 170 void Global::setminyawdegree(double _minyawdegree){minyawdegree=_minyawdegree;}
shimogamo 4:650af94bf062 171
shimogamo 4:650af94bf062 172
shimogamo 8:ca92cb674004 173 double Global::getmaxpitchplayratio(){return maxpitchplayratio;}
shimogamo 8:ca92cb674004 174 double Global::getminpitchplayratio(){return minpitchplayratio;}
shimogamo 8:ca92cb674004 175 double Global::getmaxyawplayratio(){return maxyawplayratio;}
shimogamo 8:ca92cb674004 176 double Global::getminyawplayratio(){return minyawplayratio;}
shimogamo 8:ca92cb674004 177
shimogamo 8:ca92cb674004 178 void Global::setmaxpitchplayratio(double _maxpitchplayratio){maxpitchplayratio=_maxpitchplayratio;}
shimogamo 8:ca92cb674004 179 void Global::setminpitchplayratio(double _minpitchplayratio){minpitchplayratio=_minpitchplayratio;}
shimogamo 8:ca92cb674004 180 void Global::setmaxyawplayratio(double _maxyawplayratio){maxyawplayratio=_maxyawplayratio;}
shimogamo 8:ca92cb674004 181 void Global::setminyawplayratio(double _minyawplayratio){minyawplayratio=_minyawplayratio;}
shimogamo 8:ca92cb674004 182
shimogamo 9:d1fc0805ec7d 183 double Global::gettrimpitchrate(){return trimpitchrate;}
shimogamo 1:3f857674a290 184
shimogamo 9:d1fc0805ec7d 185 void Global::settrimpitchrate(double _trimpitchrate){trimpitchrate=_trimpitchrate;}
shimogamo 1:3f857674a290 186
shimogamo 25:589742cd3137 187 //常に更新される変数
shimogamo 1:3f857674a290 188 double Global::getpitch(){return pitch;}
shimogamo 8:ca92cb674004 189 double Global::getpitchdegree(){return pitchdegree;}
shimogamo 10:0a4bf8c82493 190 int Global::getinttrimpitch(){return inttrimpitch;}
shimogamo 1:3f857674a290 191 double Global::getyaw(){return yaw;}
shimogamo 8:ca92cb674004 192 double Global::getyawdegree(){return yawdegree;}
shimogamo 10:0a4bf8c82493 193 int Global::getinttrimyaw(){return inttrimyaw;}
shimogamo 1:3f857674a290 194 double Global::getairspeed(){return airspeed;}
naoya1687 33:d939479e7b13 195 float Global::getcadence(){return cadence;}
naoya1687 33:d939479e7b13 196 float Global::getultsonic(){return ultsonic;}
shimogamo 10:0a4bf8c82493 197 double Global::getatmpress(){return atmpress;}
naoya1687 32:13aba70baa4b 198 //int Global::getselector(){return selector;}
naoya1687 33:d939479e7b13 199 float Global::getcadencevolt(){return cadencevolt;}
naoya1687 33:d939479e7b13 200 float Global::getultsonicvolt(){return ultsonicvolt;}
shimogamo 19:c6ad6b453b39 201 double Global::getservovolt(){return servovolt;}
shimogamo 19:c6ad6b453b39 202 double Global::getmiconvolt(){return miconvolt;}
shimogamo 10:0a4bf8c82493 203
shimogamo 13:a8e10a69df45 204 int Global::getpitchtime(){return pitchtime;}
shimogamo 13:a8e10a69df45 205 int Global::getpitchdegreetime(){return pitchdegreetime;}
shimogamo 13:a8e10a69df45 206 int Global::getinttrimpitchtime(){return inttrimpitchtime;}
shimogamo 13:a8e10a69df45 207 int Global::getyawtime(){return yawtime;}
shimogamo 13:a8e10a69df45 208 int Global::getyawdegreetime(){return yawdegreetime;}
shimogamo 13:a8e10a69df45 209 int Global::getinttrimyawtime(){return inttrimyawtime;}
shimogamo 13:a8e10a69df45 210 int Global::getairspeedtime(){return airspeedtime;}
shimogamo 13:a8e10a69df45 211 int Global::getcadencetime(){return cadencetime;}
shimogamo 13:a8e10a69df45 212 int Global::getultsonictime(){return ultsonictime;}
shimogamo 13:a8e10a69df45 213 int Global::getatmpresstime(){return atmpresstime;}
naoya1687 32:13aba70baa4b 214 //int Global::getselectortime(){return selectortime;}
naoya1687 31:cef6ee7af014 215 int Global::getcadencevolttime(){return cadencevolttime;}
naoya1687 31:cef6ee7af014 216 int Global::getultsonicvolttime(){return ultsonicvolttime;}
shimogamo 19:c6ad6b453b39 217 int Global::getservovolttime(){return servovolttime;}
shimogamo 19:c6ad6b453b39 218 int Global::getmiconvolttime(){return miconvolttime;}
shimogamo 13:a8e10a69df45 219
shimogamo 12:8e39bb45c61c 220 void Global::setpitch(double _pitch){
shimogamo 12:8e39bb45c61c 221 pitch = _pitch;
shimogamo 13:a8e10a69df45 222 pitchtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 223 }
shimogamo 12:8e39bb45c61c 224 void Global::setpitchdegree(double _pitchdegree){
shimogamo 12:8e39bb45c61c 225 pitchdegree = _pitchdegree;
shimogamo 13:a8e10a69df45 226 pitchdegreetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 227 }
shimogamo 12:8e39bb45c61c 228 void Global::setinttrimpitch(int _inttrimpitch){
shimogamo 12:8e39bb45c61c 229 inttrimpitch = _inttrimpitch;
shimogamo 13:a8e10a69df45 230 inttrimpitchtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 231 }
shimogamo 12:8e39bb45c61c 232 void Global::setyaw(double _yaw){
shimogamo 12:8e39bb45c61c 233 yaw = _yaw;
shimogamo 13:a8e10a69df45 234 yawtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 235 }
shimogamo 12:8e39bb45c61c 236 void Global::setyawdegree(double _yawdegree){
shimogamo 12:8e39bb45c61c 237 yawdegree = _yawdegree;
shimogamo 13:a8e10a69df45 238 yawdegreetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 239 }
shimogamo 12:8e39bb45c61c 240 void Global::setinttrimyaw(int _inttrimyaw){
shimogamo 12:8e39bb45c61c 241 inttrimyaw = _inttrimyaw;
shimogamo 13:a8e10a69df45 242 inttrimyawtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 243 }
shimogamo 12:8e39bb45c61c 244 void Global::setairspeed(double _airspeed){
shimogamo 12:8e39bb45c61c 245 airspeed = _airspeed;
shimogamo 13:a8e10a69df45 246 airspeedtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 247 }
naoya1687 33:d939479e7b13 248 void Global::setcadence(float _cadence){
shimogamo 12:8e39bb45c61c 249 cadence = _cadence;
shimogamo 13:a8e10a69df45 250 cadencetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 251 }
naoya1687 33:d939479e7b13 252 void Global::setultsonic(float _ultsonic){
shimogamo 12:8e39bb45c61c 253 ultsonic = _ultsonic;
shimogamo 13:a8e10a69df45 254 ultsonictime = timer.read_ms();
shimogamo 12:8e39bb45c61c 255 }
shimogamo 12:8e39bb45c61c 256 void Global::setatmpress(double _atmpress){
shimogamo 12:8e39bb45c61c 257 atmpress = _atmpress;
shimogamo 13:a8e10a69df45 258 atmpresstime = timer.read_ms();
shimogamo 12:8e39bb45c61c 259 }
naoya1687 32:13aba70baa4b 260 /*void Global::setselector(int _selector){
shimogamo 16:7e36177b4435 261 selector = _selector;
shimogamo 16:7e36177b4435 262 selectortime = timer.read_ms();
naoya1687 32:13aba70baa4b 263 }*/
naoya1687 33:d939479e7b13 264 void Global::setcadencevolt(float _cadencevolt){
naoya1687 31:cef6ee7af014 265 cadencevolt = _cadencevolt;
naoya1687 31:cef6ee7af014 266 cadencevolttime = timer.read_ms();
naoya1687 31:cef6ee7af014 267 }
naoya1687 33:d939479e7b13 268 void Global::setultsonicvolt(float _ultsonicvolt){
naoya1687 31:cef6ee7af014 269 ultsonicvolt = _ultsonicvolt;
naoya1687 31:cef6ee7af014 270 ultsonicvolttime = timer.read_ms();
naoya1687 31:cef6ee7af014 271 }
shimogamo 19:c6ad6b453b39 272 void Global::setservovolt(double _servovolt){
shimogamo 19:c6ad6b453b39 273 servovolt = _servovolt;
shimogamo 19:c6ad6b453b39 274 servovolttime = timer.read_ms();
shimogamo 19:c6ad6b453b39 275 }
shimogamo 19:c6ad6b453b39 276 void Global::setmiconvolt(double _miconvolt){
shimogamo 19:c6ad6b453b39 277 miconvolt = _miconvolt;
shimogamo 19:c6ad6b453b39 278 miconvolttime = timer.read_ms();
shimogamo 19:c6ad6b453b39 279 }