kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Sat Mar 25 07:09:30 2017 +0000
Revision:
41:013df90be273
Parent:
40:fa6c39f853f1
Parent:
38:18ac0f8628bf
marge

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 36:ad6b2b81bb89 5 extern RawSerial pc;
shimogamo 3:e3c41153e5fe 6
shimogamo 26:a53c3208ac35 7 //クラスじゃなくてnamespaceのほうが綺麗にかけるかもね
shimogamo 26:a53c3208ac35 8
shimogamo 12:8e39bb45c61c 9 Queue<char, 20> Global::initqueue;
shimogamo 35:63ccdae58da4 10 //----------------FlashMemory(pin指定はここで)--------------------------------------------
shimogamo 35:63ccdae58da4 11 SPI Global::spi(PA_7, PA_6, PA_5);// mosi, miso, sclk
shimogamo 35:63ccdae58da4 12 FlashManager Global::memory(spi, PB_9);//spi, cs
shimogamo 36:ad6b2b81bb89 13 //FlashManager Global::memory(PA_7, PA_6, PA_5, PB_9);
shimogamo 25:589742cd3137 14 //----------------普段は変動しない変数------------------------------------------------------
shimogamo 9:d1fc0805ec7d 15 //サーボのパラメータ(角度(度数法)で設定)max,minはニュートラルを基準にしている
shimogamo 4:650af94bf062 16 double Global::maxpitch = 5.0;
shimogamo 4:650af94bf062 17 double Global::minpitch = -5.0;
shimogamo 4:650af94bf062 18 double Global::neutralpitch = 0;
shimogamo 4:650af94bf062 19 double Global::maxyaw = 30.0;
shimogamo 4:650af94bf062 20 double Global::minyaw = -30.0;
shimogamo 4:650af94bf062 21 double Global::neutralyaw = 0;
shimogamo 8:ca92cb674004 22 //ジョイスティックのパラメータ(mbedのAnalogIn値[0,1])/max, min, neu全て[0,1]の絶対的な値をとる
shimogamo 4:650af94bf062 23 double Global::maxpitchdegree = 1.0;
shimogamo 4:650af94bf062 24 double Global::minpitchdegree = 0;
shimogamo 4:650af94bf062 25 double Global::neutralpitchdegree = 0.5;
shimogamo 4:650af94bf062 26 double Global::maxyawdegree = 1.0;
shimogamo 4:650af94bf062 27 double Global::minyawdegree = 0;
shimogamo 4:650af94bf062 28 double Global::neutralyawdegree = 0.5;
shimogamo 9:d1fc0805ec7d 29 //ジョイスティックの遊び([-1,1]でニュートラルを0とした時の値)
shimogamo 35:63ccdae58da4 30 double Global::maxpitchplayratio = 0.1;
shimogamo 35:63ccdae58da4 31 double Global::minpitchplayratio = -0.1;
shimogamo 35:63ccdae58da4 32 double Global::maxyawplayratio = 0.1;
shimogamo 35:63ccdae58da4 33 double Global::minyawplayratio = -0.1;
shimogamo 9:d1fc0805ec7d 34 //トリムの変化率(角度(度数法)で設定)
shimogamo 9:d1fc0805ec7d 35 double Global::trimpitchrate = 0.5;
shimogamo 3:e3c41153e5fe 36
shimogamo 3:e3c41153e5fe 37 //----------------周期的に変動する変数------------------------------------------------------
shimogamo 8:ca92cb674004 38 double Global::pitch;
shimogamo 8:ca92cb674004 39 double Global::pitchdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 40 int Global::inttrimpitch;
shimogamo 8:ca92cb674004 41 double Global::yaw;
shimogamo 8:ca92cb674004 42 double Global::yawdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 43 int Global::inttrimyaw;
shimogamo 1:3f857674a290 44 double Global::airspeed;
naoya1687 33:d939479e7b13 45 float Global::cadence;
naoya1687 33:d939479e7b13 46 float Global::ultsonic;
shimogamo 10:0a4bf8c82493 47 double Global::atmpress;
naoya1687 32:13aba70baa4b 48 //int Global::selector;
naoya1687 33:d939479e7b13 49 float Global::cadencevolt;
naoya1687 33:d939479e7b13 50 float Global::ultsonicvolt;
shimogamo 19:c6ad6b453b39 51 double Global::servovolt;
shimogamo 19:c6ad6b453b39 52 double Global::miconvolt;
shimogamo 0:2a15bd367891 53
shimogamo 13:a8e10a69df45 54 int Global::pitchtime;
shimogamo 13:a8e10a69df45 55 int Global::pitchdegreetime;
shimogamo 13:a8e10a69df45 56 int Global::inttrimpitchtime;
shimogamo 13:a8e10a69df45 57 int Global::yawtime;
shimogamo 13:a8e10a69df45 58 int Global::yawdegreetime;
shimogamo 13:a8e10a69df45 59 int Global::inttrimyawtime;
shimogamo 13:a8e10a69df45 60 int Global::airspeedtime;
shimogamo 13:a8e10a69df45 61 int Global::cadencetime;
shimogamo 13:a8e10a69df45 62 int Global::ultsonictime;
shimogamo 13:a8e10a69df45 63 int Global::atmpresstime;
naoya1687 32:13aba70baa4b 64 //int Global::selectortime;
naoya1687 31:cef6ee7af014 65 int Global::cadencevolttime;
naoya1687 31:cef6ee7af014 66 int Global::ultsonicvolttime;
shimogamo 19:c6ad6b453b39 67 int Global::servovolttime;
shimogamo 19:c6ad6b453b39 68 int Global::miconvolttime;
shimogamo 12:8e39bb45c61c 69
shimogamo 4:650af94bf062 70 //----------------どこからでも使えるled,スイッチ,タイマーの一括管理-----------------------------
shimogamo 0:2a15bd367891 71 Timer Global::timer;
naoya1687 38:18ac0f8628bf 72 //DigitalOut Global::led(LED2);
shimogamo 6:0d9fa7152934 73
shimogamo 26:a53c3208ac35 74 //ここでINIT.csvファイルが読み込まれる
shimogamo 5:9a1ec02229dd 75 void Global::initialize(){
shimogamo 6:0d9fa7152934 76 timer.start();
shimogamo 35:63ccdae58da4 77 memory.reset();
naoya1687 38:18ac0f8628bf 78 fileread();
shimogamo 6:0d9fa7152934 79 }
shimogamo 6:0d9fa7152934 80
shimogamo 26:a53c3208ac35 81 //INITファイルの読み込み
shimogamo 35:63ccdae58da4 82 void Global::fileread(){
shimogamo 35:63ccdae58da4 83 /***********Memoryに値が保存されていない場合filewrite()**********/
shimogamo 35:63ccdae58da4 84
shimogamo 35:63ccdae58da4 85 /************************************************************/
shimogamo 35:63ccdae58da4 86
naoya1687 38:18ac0f8628bf 87 vector<double> param = memory.readdouble(0x0,17);
shimogamo 35:63ccdae58da4 88
shimogamo 35:63ccdae58da4 89 setneutralpitch(param[0]);
shimogamo 35:63ccdae58da4 90 setmaxpitch(param[1]);
shimogamo 35:63ccdae58da4 91 setminpitch(param[2]);
shimogamo 35:63ccdae58da4 92 setneutralyaw(param[3]);
shimogamo 35:63ccdae58da4 93 setmaxyaw(param[4]);
shimogamo 35:63ccdae58da4 94 setminyaw(param[5]);
shimogamo 35:63ccdae58da4 95
shimogamo 35:63ccdae58da4 96 setneutralpitchdegree(param[6]);
shimogamo 35:63ccdae58da4 97 setmaxpitchdegree(param[7]);
shimogamo 35:63ccdae58da4 98 setminpitchdegree(param[8]);
shimogamo 35:63ccdae58da4 99 setneutralyawdegree(param[9]);
shimogamo 35:63ccdae58da4 100 setmaxyawdegree(param[10]);
shimogamo 35:63ccdae58da4 101 setminyawdegree(param[11]);
shimogamo 35:63ccdae58da4 102
shimogamo 35:63ccdae58da4 103 setmaxpitchplayratio(param[12]);
shimogamo 35:63ccdae58da4 104 setminpitchplayratio(param[13]);
shimogamo 35:63ccdae58da4 105 setmaxyawplayratio(param[14]);
shimogamo 35:63ccdae58da4 106 setminyawplayratio(param[15]);
shimogamo 35:63ccdae58da4 107 settrimpitchrate(param[16]);
shimogamo 40:fa6c39f853f1 108
shimogamo 40:fa6c39f853f1 109 pc.printf("read\n");
shimogamo 6:0d9fa7152934 110 }
shimogamo 6:0d9fa7152934 111
shimogamo 26:a53c3208ac35 112 //INITファイルの書き込み
shimogamo 6:0d9fa7152934 113 void Global::filewrite(){
shimogamo 35:63ccdae58da4 114 vector<double> param;
naoya1687 38:18ac0f8628bf 115
shimogamo 35:63ccdae58da4 116 param.push_back(getneutralpitch());
shimogamo 35:63ccdae58da4 117 param.push_back(getmaxpitch());
shimogamo 35:63ccdae58da4 118 param.push_back(getminpitch());
shimogamo 35:63ccdae58da4 119 param.push_back(getneutralyaw());
shimogamo 35:63ccdae58da4 120 param.push_back(getmaxyaw());
shimogamo 35:63ccdae58da4 121 param.push_back(getminyaw());
shimogamo 35:63ccdae58da4 122
shimogamo 35:63ccdae58da4 123 param.push_back(getneutralpitchdegree());
shimogamo 35:63ccdae58da4 124 param.push_back(getmaxpitchdegree());
shimogamo 35:63ccdae58da4 125 param.push_back(getminpitchdegree());
shimogamo 35:63ccdae58da4 126 param.push_back(getneutralyawdegree());
shimogamo 35:63ccdae58da4 127 param.push_back(getmaxyawdegree());
shimogamo 35:63ccdae58da4 128 param.push_back(getminyawdegree());
shimogamo 35:63ccdae58da4 129
shimogamo 35:63ccdae58da4 130 param.push_back(getmaxpitchplayratio());
shimogamo 35:63ccdae58da4 131 param.push_back(getminpitchplayratio());
shimogamo 35:63ccdae58da4 132 param.push_back(getmaxyawplayratio());
shimogamo 35:63ccdae58da4 133 param.push_back(getminyawplayratio());
shimogamo 35:63ccdae58da4 134 param.push_back(gettrimpitchrate());
naoya1687 38:18ac0f8628bf 135 /*
shimogamo 36:ad6b2b81bb89 136 for(int i=0;i<17;i++){
shimogamo 36:ad6b2b81bb89 137 param.push_back(i*0.1);
naoya1687 38:18ac0f8628bf 138 }*/
shimogamo 35:63ccdae58da4 139 memory.writedouble(0x0,param);
shimogamo 36:ad6b2b81bb89 140 pc.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 }