kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
naoya1687
Date:
Mon Feb 13 06:08:05 2017 +0000
Revision:
31:cef6ee7af014
Parent:
26:a53c3208ac35
Child:
32:13aba70baa4b
?????? todo????

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 9:d1fc0805ec7d 4
shimogamo 3:e3c41153e5fe 5
shimogamo 26:a53c3208ac35 6 //クラスじゃなくてnamespaceのほうが綺麗にかけるかもね
shimogamo 26:a53c3208ac35 7
shimogamo 3:e3c41153e5fe 8
shimogamo 12:8e39bb45c61c 9 Queue<char, 20> Global::initqueue;
shimogamo 25:589742cd3137 10 //----------------普段は変動しない変数------------------------------------------------------
shimogamo 9:d1fc0805ec7d 11 //サーボのパラメータ(角度(度数法)で設定)max,minはニュートラルを基準にしている
shimogamo 4:650af94bf062 12 double Global::maxpitch = 5.0;
shimogamo 4:650af94bf062 13 double Global::minpitch = -5.0;
shimogamo 4:650af94bf062 14 double Global::neutralpitch = 0;
shimogamo 4:650af94bf062 15 double Global::maxyaw = 30.0;
shimogamo 4:650af94bf062 16 double Global::minyaw = -30.0;
shimogamo 4:650af94bf062 17 double Global::neutralyaw = 0;
shimogamo 8:ca92cb674004 18 //ジョイスティックのパラメータ(mbedのAnalogIn値[0,1])/max, min, neu全て[0,1]の絶対的な値をとる
shimogamo 4:650af94bf062 19 double Global::maxpitchdegree = 1.0;
shimogamo 4:650af94bf062 20 double Global::minpitchdegree = 0;
shimogamo 4:650af94bf062 21 double Global::neutralpitchdegree = 0.5;
shimogamo 4:650af94bf062 22 double Global::maxyawdegree = 1.0;
shimogamo 4:650af94bf062 23 double Global::minyawdegree = 0;
shimogamo 4:650af94bf062 24 double Global::neutralyawdegree = 0.5;
shimogamo 9:d1fc0805ec7d 25 //ジョイスティックの遊び([-1,1]でニュートラルを0とした時の値)
shimogamo 8:ca92cb674004 26 double Global::maxpitchplayratio = 0;
shimogamo 8:ca92cb674004 27 double Global::minpitchplayratio = 0;
shimogamo 8:ca92cb674004 28 double Global::maxyawplayratio = 0;
shimogamo 8:ca92cb674004 29 double Global::minyawplayratio = 0;
shimogamo 9:d1fc0805ec7d 30 //トリムの変化率(角度(度数法)で設定)
shimogamo 9:d1fc0805ec7d 31 double Global::trimpitchrate = 0.5;
shimogamo 3:e3c41153e5fe 32
shimogamo 3:e3c41153e5fe 33 //----------------周期的に変動する変数------------------------------------------------------
shimogamo 8:ca92cb674004 34 double Global::pitch;
shimogamo 8:ca92cb674004 35 double Global::pitchdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 36 int Global::inttrimpitch;
shimogamo 8:ca92cb674004 37 double Global::yaw;
shimogamo 8:ca92cb674004 38 double Global::yawdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 39 int Global::inttrimyaw;
shimogamo 1:3f857674a290 40 double Global::airspeed;
shimogamo 1:3f857674a290 41 double Global::cadence;
shimogamo 10:0a4bf8c82493 42 double Global::ultsonic;
shimogamo 10:0a4bf8c82493 43 double Global::atmpress;
shimogamo 16:7e36177b4435 44 int Global::selector;
naoya1687 31:cef6ee7af014 45 double Global::cadencevolt;
naoya1687 31:cef6ee7af014 46 double Global::ultsonicvolt;
shimogamo 19:c6ad6b453b39 47 double Global::servovolt;
shimogamo 19:c6ad6b453b39 48 double Global::miconvolt;
shimogamo 0:2a15bd367891 49
shimogamo 13:a8e10a69df45 50 int Global::pitchtime;
shimogamo 13:a8e10a69df45 51 int Global::pitchdegreetime;
shimogamo 13:a8e10a69df45 52 int Global::inttrimpitchtime;
shimogamo 13:a8e10a69df45 53 int Global::yawtime;
shimogamo 13:a8e10a69df45 54 int Global::yawdegreetime;
shimogamo 13:a8e10a69df45 55 int Global::inttrimyawtime;
shimogamo 13:a8e10a69df45 56 int Global::airspeedtime;
shimogamo 13:a8e10a69df45 57 int Global::cadencetime;
shimogamo 13:a8e10a69df45 58 int Global::ultsonictime;
shimogamo 13:a8e10a69df45 59 int Global::atmpresstime;
shimogamo 16:7e36177b4435 60 int Global::selectortime;
naoya1687 31:cef6ee7af014 61 int Global::cadencevolttime;
naoya1687 31:cef6ee7af014 62 int Global::ultsonicvolttime;
shimogamo 19:c6ad6b453b39 63 int Global::servovolttime;
shimogamo 19:c6ad6b453b39 64 int Global::miconvolttime;
shimogamo 12:8e39bb45c61c 65
shimogamo 4:650af94bf062 66 //----------------どこからでも使えるled,スイッチ,タイマーの一括管理-----------------------------
shimogamo 0:2a15bd367891 67 Timer Global::timer;
shimogamo 16:7e36177b4435 68 DigitalOut Global::led[] = {LED1,LED2,LED3,LED4};
shimogamo 6:0d9fa7152934 69 LocalFileSystem Global::local("local");
shimogamo 6:0d9fa7152934 70
shimogamo 26:a53c3208ac35 71 //ここでINIT.csvファイルが読み込まれる
shimogamo 5:9a1ec02229dd 72 void Global::initialize(){
shimogamo 6:0d9fa7152934 73 timer.start();
shimogamo 6:0d9fa7152934 74 fileread();
shimogamo 6:0d9fa7152934 75 }
shimogamo 6:0d9fa7152934 76
shimogamo 26:a53c3208ac35 77 //INITファイルの読み込み
shimogamo 6:0d9fa7152934 78 void Global::fileread(){
shimogamo 6:0d9fa7152934 79 float a, b, c, d, e, f;
shimogamo 6:0d9fa7152934 80
shimogamo 6:0d9fa7152934 81 FILE* fp = fopen("/local/init.csv", "r");
shimogamo 6:0d9fa7152934 82 if(fp == NULL) {
shimogamo 6:0d9fa7152934 83 filewrite();
shimogamo 6:0d9fa7152934 84 return;
shimogamo 6:0d9fa7152934 85 }
shimogamo 6:0d9fa7152934 86 //1行目
shimogamo 7:6f7bd18ce796 87 fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f);
shimogamo 6:0d9fa7152934 88 setneutralpitch(a);
shimogamo 6:0d9fa7152934 89 setmaxpitch(b);
shimogamo 6:0d9fa7152934 90 setminpitch(c);
shimogamo 6:0d9fa7152934 91 setneutralyaw(d);
shimogamo 6:0d9fa7152934 92 setmaxyaw(e);
shimogamo 6:0d9fa7152934 93 setminyaw(f);
shimogamo 8:ca92cb674004 94 //2行目
shimogamo 8:ca92cb674004 95 fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f);
shimogamo 8:ca92cb674004 96 setneutralpitchdegree(a);
shimogamo 8:ca92cb674004 97 setmaxpitchdegree(b);
shimogamo 8:ca92cb674004 98 setminpitchdegree(c);
shimogamo 8:ca92cb674004 99 setneutralyawdegree(d);
shimogamo 8:ca92cb674004 100 setmaxyawdegree(e);
shimogamo 8:ca92cb674004 101 setminyawdegree(f);
shimogamo 8:ca92cb674004 102 //3行目
shimogamo 9:d1fc0805ec7d 103 fscanf(fp, "%f,%f,%f,%f,%f",&a, &b, &c, &d, &e);
shimogamo 8:ca92cb674004 104 setmaxpitchplayratio(a);
shimogamo 8:ca92cb674004 105 setminpitchplayratio(b);
shimogamo 8:ca92cb674004 106 setmaxyawplayratio(c);
shimogamo 8:ca92cb674004 107 setminyawplayratio(d);
shimogamo 9:d1fc0805ec7d 108 settrimpitchrate(e);
shimogamo 6:0d9fa7152934 109 fclose(fp);
shimogamo 6:0d9fa7152934 110 }
shimogamo 6:0d9fa7152934 111
shimogamo 26:a53c3208ac35 112 //INITファイルの書き込み
shimogamo 6:0d9fa7152934 113 void Global::filewrite(){
shimogamo 6:0d9fa7152934 114 FILE* fp = fopen("/local/init.csv", "w");
shimogamo 6:0d9fa7152934 115 if(fp == NULL) {
shimogamo 6:0d9fa7152934 116 error("Could not open file for write\n");
shimogamo 6:0d9fa7152934 117 }
shimogamo 6:0d9fa7152934 118 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",
shimogamo 6:0d9fa7152934 119 getneutralpitch(),
shimogamo 6:0d9fa7152934 120 getmaxpitch(),
shimogamo 6:0d9fa7152934 121 getminpitch(),
shimogamo 6:0d9fa7152934 122 getneutralyaw(),
shimogamo 6:0d9fa7152934 123 getmaxyaw(),
shimogamo 6:0d9fa7152934 124 getminyaw());
shimogamo 8:ca92cb674004 125 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",
shimogamo 8:ca92cb674004 126 getneutralpitchdegree(),
shimogamo 8:ca92cb674004 127 getmaxpitchdegree(),
shimogamo 8:ca92cb674004 128 getminpitchdegree(),
shimogamo 8:ca92cb674004 129 getneutralyawdegree(),
shimogamo 8:ca92cb674004 130 getmaxyawdegree(),
shimogamo 8:ca92cb674004 131 getminyawdegree());
shimogamo 9:d1fc0805ec7d 132 fprintf(fp, "%f,%f,%f,%f,%f\n",
shimogamo 8:ca92cb674004 133 getmaxpitchplayratio(),
shimogamo 8:ca92cb674004 134 getminpitchplayratio(),
shimogamo 8:ca92cb674004 135 getmaxyawplayratio(),
shimogamo 9:d1fc0805ec7d 136 getminyawplayratio(),
shimogamo 9:d1fc0805ec7d 137 gettrimpitchrate());
shimogamo 8:ca92cb674004 138
shimogamo 6:0d9fa7152934 139 fclose(fp);
shimogamo 5:9a1ec02229dd 140 }
shimogamo 5:9a1ec02229dd 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 1:3f857674a290 187
shimogamo 25:589742cd3137 188 //常に更新される変数
shimogamo 1:3f857674a290 189 double Global::getpitch(){return pitch;}
shimogamo 8:ca92cb674004 190 double Global::getpitchdegree(){return pitchdegree;}
shimogamo 10:0a4bf8c82493 191 int Global::getinttrimpitch(){return inttrimpitch;}
shimogamo 1:3f857674a290 192 double Global::getyaw(){return yaw;}
shimogamo 8:ca92cb674004 193 double Global::getyawdegree(){return yawdegree;}
shimogamo 10:0a4bf8c82493 194 int Global::getinttrimyaw(){return inttrimyaw;}
shimogamo 1:3f857674a290 195 double Global::getairspeed(){return airspeed;}
shimogamo 1:3f857674a290 196 double Global::getcadence(){return cadence;}
shimogamo 10:0a4bf8c82493 197 double Global::getultsonic(){return ultsonic;}
shimogamo 10:0a4bf8c82493 198 double Global::getatmpress(){return atmpress;}
shimogamo 16:7e36177b4435 199 int Global::getselector(){return selector;}
naoya1687 31:cef6ee7af014 200 double Global::getcadencevolt(){return cadencevolt;}
naoya1687 31:cef6ee7af014 201 double Global::getultsonicvolt(){return ultsonicvolt;}
shimogamo 19:c6ad6b453b39 202 double Global::getservovolt(){return servovolt;}
shimogamo 19:c6ad6b453b39 203 double Global::getmiconvolt(){return miconvolt;}
shimogamo 10:0a4bf8c82493 204
shimogamo 13:a8e10a69df45 205 int Global::getpitchtime(){return pitchtime;}
shimogamo 13:a8e10a69df45 206 int Global::getpitchdegreetime(){return pitchdegreetime;}
shimogamo 13:a8e10a69df45 207 int Global::getinttrimpitchtime(){return inttrimpitchtime;}
shimogamo 13:a8e10a69df45 208 int Global::getyawtime(){return yawtime;}
shimogamo 13:a8e10a69df45 209 int Global::getyawdegreetime(){return yawdegreetime;}
shimogamo 13:a8e10a69df45 210 int Global::getinttrimyawtime(){return inttrimyawtime;}
shimogamo 13:a8e10a69df45 211 int Global::getairspeedtime(){return airspeedtime;}
shimogamo 13:a8e10a69df45 212 int Global::getcadencetime(){return cadencetime;}
shimogamo 13:a8e10a69df45 213 int Global::getultsonictime(){return ultsonictime;}
shimogamo 13:a8e10a69df45 214 int Global::getatmpresstime(){return atmpresstime;}
shimogamo 16:7e36177b4435 215 int Global::getselectortime(){return selectortime;}
naoya1687 31:cef6ee7af014 216 int Global::getcadencevolttime(){return cadencevolttime;}
naoya1687 31:cef6ee7af014 217 int Global::getultsonicvolttime(){return ultsonicvolttime;}
shimogamo 19:c6ad6b453b39 218 int Global::getservovolttime(){return servovolttime;}
shimogamo 19:c6ad6b453b39 219 int Global::getmiconvolttime(){return miconvolttime;}
shimogamo 13:a8e10a69df45 220
shimogamo 13:a8e10a69df45 221
shimogamo 0:2a15bd367891 222
shimogamo 12:8e39bb45c61c 223 void Global::setpitch(double _pitch){
shimogamo 12:8e39bb45c61c 224 pitch = _pitch;
shimogamo 13:a8e10a69df45 225 pitchtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 226 }
shimogamo 12:8e39bb45c61c 227 void Global::setpitchdegree(double _pitchdegree){
shimogamo 12:8e39bb45c61c 228 pitchdegree = _pitchdegree;
shimogamo 13:a8e10a69df45 229 pitchdegreetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 230 }
shimogamo 12:8e39bb45c61c 231 void Global::setinttrimpitch(int _inttrimpitch){
shimogamo 12:8e39bb45c61c 232 inttrimpitch = _inttrimpitch;
shimogamo 13:a8e10a69df45 233 inttrimpitchtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 234 }
shimogamo 12:8e39bb45c61c 235 void Global::setyaw(double _yaw){
shimogamo 12:8e39bb45c61c 236 yaw = _yaw;
shimogamo 13:a8e10a69df45 237 yawtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 238 }
shimogamo 12:8e39bb45c61c 239 void Global::setyawdegree(double _yawdegree){
shimogamo 12:8e39bb45c61c 240 yawdegree = _yawdegree;
shimogamo 13:a8e10a69df45 241 yawdegreetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 242 }
shimogamo 12:8e39bb45c61c 243 void Global::setinttrimyaw(int _inttrimyaw){
shimogamo 12:8e39bb45c61c 244 inttrimyaw = _inttrimyaw;
shimogamo 13:a8e10a69df45 245 inttrimyawtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 246 }
shimogamo 12:8e39bb45c61c 247 void Global::setairspeed(double _airspeed){
shimogamo 12:8e39bb45c61c 248 airspeed = _airspeed;
shimogamo 13:a8e10a69df45 249 airspeedtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 250 }
shimogamo 12:8e39bb45c61c 251 void Global::setcadence(double _cadence){
shimogamo 12:8e39bb45c61c 252 cadence = _cadence;
shimogamo 13:a8e10a69df45 253 cadencetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 254 }
shimogamo 12:8e39bb45c61c 255 void Global::setultsonic(double _ultsonic){
shimogamo 12:8e39bb45c61c 256 ultsonic = _ultsonic;
shimogamo 13:a8e10a69df45 257 ultsonictime = timer.read_ms();
shimogamo 12:8e39bb45c61c 258 }
shimogamo 12:8e39bb45c61c 259 void Global::setatmpress(double _atmpress){
shimogamo 12:8e39bb45c61c 260 atmpress = _atmpress;
shimogamo 13:a8e10a69df45 261 atmpresstime = timer.read_ms();
shimogamo 12:8e39bb45c61c 262 }
shimogamo 16:7e36177b4435 263 void Global::setselector(int _selector){
shimogamo 16:7e36177b4435 264 selector = _selector;
shimogamo 16:7e36177b4435 265 selectortime = timer.read_ms();
shimogamo 16:7e36177b4435 266 }
naoya1687 31:cef6ee7af014 267 void Global::setcadencevolt(double _cadencevolt){
naoya1687 31:cef6ee7af014 268 cadencevolt = _cadencevolt;
naoya1687 31:cef6ee7af014 269 cadencevolttime = timer.read_ms();
naoya1687 31:cef6ee7af014 270 }
naoya1687 31:cef6ee7af014 271 void Global::setultsonicvolt(double _ultsonicvolt){
naoya1687 31:cef6ee7af014 272 ultsonicvolt = _ultsonicvolt;
naoya1687 31:cef6ee7af014 273 ultsonicvolttime = timer.read_ms();
naoya1687 31:cef6ee7af014 274 }
shimogamo 19:c6ad6b453b39 275 void Global::setservovolt(double _servovolt){
shimogamo 19:c6ad6b453b39 276 servovolt = _servovolt;
shimogamo 19:c6ad6b453b39 277 servovolttime = timer.read_ms();
shimogamo 19:c6ad6b453b39 278 }
shimogamo 19:c6ad6b453b39 279 void Global::setmiconvolt(double _miconvolt){
shimogamo 19:c6ad6b453b39 280 miconvolt = _miconvolt;
shimogamo 19:c6ad6b453b39 281 miconvolttime = timer.read_ms();
shimogamo 19:c6ad6b453b39 282 }