kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Mon Mar 28 09:01:00 2016 +0000
Revision:
17:887cfe1d309f
Parent:
16:7e36177b4435
Child:
19:c6ad6b453b39
??????1??????????????????????

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 3:e3c41153e5fe 6
shimogamo 12:8e39bb45c61c 7 Queue<char, 20> Global::initqueue;
shimogamo 3:e3c41153e5fe 8 //----------------普段は変動しない変数(定数)------------------------------------------------------
shimogamo 9:d1fc0805ec7d 9 //サーボのパラメータ(角度(度数法)で設定)max,minはニュートラルを基準にしている
shimogamo 4:650af94bf062 10 double Global::maxpitch = 5.0;
shimogamo 4:650af94bf062 11 double Global::minpitch = -5.0;
shimogamo 4:650af94bf062 12 double Global::neutralpitch = 0;
shimogamo 4:650af94bf062 13 double Global::maxyaw = 30.0;
shimogamo 4:650af94bf062 14 double Global::minyaw = -30.0;
shimogamo 4:650af94bf062 15 double Global::neutralyaw = 0;
shimogamo 8:ca92cb674004 16 //ジョイスティックのパラメータ(mbedのAnalogIn値[0,1])/max, min, neu全て[0,1]の絶対的な値をとる
shimogamo 4:650af94bf062 17 double Global::maxpitchdegree = 1.0;
shimogamo 4:650af94bf062 18 double Global::minpitchdegree = 0;
shimogamo 4:650af94bf062 19 double Global::neutralpitchdegree = 0.5;
shimogamo 4:650af94bf062 20 double Global::maxyawdegree = 1.0;
shimogamo 4:650af94bf062 21 double Global::minyawdegree = 0;
shimogamo 4:650af94bf062 22 double Global::neutralyawdegree = 0.5;
shimogamo 9:d1fc0805ec7d 23 //ジョイスティックの遊び([-1,1]でニュートラルを0とした時の値)
shimogamo 8:ca92cb674004 24 double Global::maxpitchplayratio = 0;
shimogamo 8:ca92cb674004 25 double Global::minpitchplayratio = 0;
shimogamo 8:ca92cb674004 26 double Global::maxyawplayratio = 0;
shimogamo 8:ca92cb674004 27 double Global::minyawplayratio = 0;
shimogamo 9:d1fc0805ec7d 28 //トリムの変化率(角度(度数法)で設定)
shimogamo 9:d1fc0805ec7d 29 double Global::trimpitchrate = 0.5;
shimogamo 3:e3c41153e5fe 30
shimogamo 3:e3c41153e5fe 31 //----------------周期的に変動する変数------------------------------------------------------
shimogamo 8:ca92cb674004 32 double Global::pitch;
shimogamo 8:ca92cb674004 33 double Global::pitchdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 34 int Global::inttrimpitch;
shimogamo 8:ca92cb674004 35 double Global::yaw;
shimogamo 8:ca92cb674004 36 double Global::yawdegree;//controllerの生データ
shimogamo 10:0a4bf8c82493 37 int Global::inttrimyaw;
shimogamo 1:3f857674a290 38 double Global::airspeed;
shimogamo 1:3f857674a290 39 double Global::cadence;
shimogamo 10:0a4bf8c82493 40 double Global::ultsonic;
shimogamo 10:0a4bf8c82493 41 double Global::atmpress;
shimogamo 16:7e36177b4435 42 int Global::selector;
shimogamo 0:2a15bd367891 43
shimogamo 13:a8e10a69df45 44 int Global::pitchtime;
shimogamo 13:a8e10a69df45 45 int Global::pitchdegreetime;
shimogamo 13:a8e10a69df45 46 int Global::inttrimpitchtime;
shimogamo 13:a8e10a69df45 47 int Global::yawtime;
shimogamo 13:a8e10a69df45 48 int Global::yawdegreetime;
shimogamo 13:a8e10a69df45 49 int Global::inttrimyawtime;
shimogamo 13:a8e10a69df45 50 int Global::airspeedtime;
shimogamo 13:a8e10a69df45 51 int Global::cadencetime;
shimogamo 13:a8e10a69df45 52 int Global::ultsonictime;
shimogamo 13:a8e10a69df45 53 int Global::atmpresstime;
shimogamo 16:7e36177b4435 54 int Global::selectortime;
shimogamo 12:8e39bb45c61c 55
shimogamo 4:650af94bf062 56 //----------------どこからでも使えるled,スイッチ,タイマーの一括管理-----------------------------
shimogamo 0:2a15bd367891 57 Timer Global::timer;
shimogamo 16:7e36177b4435 58 DigitalOut Global::led[] = {LED1,LED2,LED3,LED4};
shimogamo 6:0d9fa7152934 59 LocalFileSystem Global::local("local");
shimogamo 6:0d9fa7152934 60
shimogamo 0:2a15bd367891 61
shimogamo 5:9a1ec02229dd 62 void Global::initialize(){
shimogamo 6:0d9fa7152934 63 timer.start();
shimogamo 6:0d9fa7152934 64 fileread();
shimogamo 6:0d9fa7152934 65 }
shimogamo 6:0d9fa7152934 66
shimogamo 6:0d9fa7152934 67 void Global::fileread(){
shimogamo 6:0d9fa7152934 68 float a, b, c, d, e, f;
shimogamo 6:0d9fa7152934 69
shimogamo 6:0d9fa7152934 70 FILE* fp = fopen("/local/init.csv", "r");
shimogamo 6:0d9fa7152934 71 if(fp == NULL) {
shimogamo 6:0d9fa7152934 72 filewrite();
shimogamo 6:0d9fa7152934 73 return;
shimogamo 6:0d9fa7152934 74 }
shimogamo 6:0d9fa7152934 75 //1行目
shimogamo 7:6f7bd18ce796 76 fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f);
shimogamo 6:0d9fa7152934 77 setneutralpitch(a);
shimogamo 6:0d9fa7152934 78 setmaxpitch(b);
shimogamo 6:0d9fa7152934 79 setminpitch(c);
shimogamo 6:0d9fa7152934 80 setneutralyaw(d);
shimogamo 6:0d9fa7152934 81 setmaxyaw(e);
shimogamo 6:0d9fa7152934 82 setminyaw(f);
shimogamo 8:ca92cb674004 83 //2行目
shimogamo 8:ca92cb674004 84 fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f);
shimogamo 8:ca92cb674004 85 setneutralpitchdegree(a);
shimogamo 8:ca92cb674004 86 setmaxpitchdegree(b);
shimogamo 8:ca92cb674004 87 setminpitchdegree(c);
shimogamo 8:ca92cb674004 88 setneutralyawdegree(d);
shimogamo 8:ca92cb674004 89 setmaxyawdegree(e);
shimogamo 8:ca92cb674004 90 setminyawdegree(f);
shimogamo 8:ca92cb674004 91 //3行目
shimogamo 9:d1fc0805ec7d 92 fscanf(fp, "%f,%f,%f,%f,%f",&a, &b, &c, &d, &e);
shimogamo 8:ca92cb674004 93 setmaxpitchplayratio(a);
shimogamo 8:ca92cb674004 94 setminpitchplayratio(b);
shimogamo 8:ca92cb674004 95 setmaxyawplayratio(c);
shimogamo 8:ca92cb674004 96 setminyawplayratio(d);
shimogamo 9:d1fc0805ec7d 97 settrimpitchrate(e);
shimogamo 6:0d9fa7152934 98 fclose(fp);
shimogamo 6:0d9fa7152934 99 }
shimogamo 6:0d9fa7152934 100
shimogamo 6:0d9fa7152934 101 void Global::filewrite(){
shimogamo 6:0d9fa7152934 102 FILE* fp = fopen("/local/init.csv", "w");
shimogamo 6:0d9fa7152934 103 if(fp == NULL) {
shimogamo 6:0d9fa7152934 104 error("Could not open file for write\n");
shimogamo 6:0d9fa7152934 105 }
shimogamo 6:0d9fa7152934 106 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",
shimogamo 6:0d9fa7152934 107 getneutralpitch(),
shimogamo 6:0d9fa7152934 108 getmaxpitch(),
shimogamo 6:0d9fa7152934 109 getminpitch(),
shimogamo 6:0d9fa7152934 110 getneutralyaw(),
shimogamo 6:0d9fa7152934 111 getmaxyaw(),
shimogamo 6:0d9fa7152934 112 getminyaw());
shimogamo 8:ca92cb674004 113 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",
shimogamo 8:ca92cb674004 114 getneutralpitchdegree(),
shimogamo 8:ca92cb674004 115 getmaxpitchdegree(),
shimogamo 8:ca92cb674004 116 getminpitchdegree(),
shimogamo 8:ca92cb674004 117 getneutralyawdegree(),
shimogamo 8:ca92cb674004 118 getmaxyawdegree(),
shimogamo 8:ca92cb674004 119 getminyawdegree());
shimogamo 9:d1fc0805ec7d 120 fprintf(fp, "%f,%f,%f,%f,%f\n",
shimogamo 8:ca92cb674004 121 getmaxpitchplayratio(),
shimogamo 8:ca92cb674004 122 getminpitchplayratio(),
shimogamo 8:ca92cb674004 123 getmaxyawplayratio(),
shimogamo 9:d1fc0805ec7d 124 getminyawplayratio(),
shimogamo 9:d1fc0805ec7d 125 gettrimpitchrate());
shimogamo 8:ca92cb674004 126
shimogamo 6:0d9fa7152934 127 fclose(fp);
shimogamo 5:9a1ec02229dd 128 }
shimogamo 5:9a1ec02229dd 129
shimogamo 1:3f857674a290 130
shimogamo 4:650af94bf062 131 //定数チックな変数
shimogamo 4:650af94bf062 132 double Global::getmaxpitch(){return maxpitch;}
shimogamo 4:650af94bf062 133 double Global::getminpitch(){return minpitch;}
shimogamo 4:650af94bf062 134 double Global::getneutralpitch(){return neutralpitch;}
shimogamo 4:650af94bf062 135 double Global::getmaxyaw(){return maxyaw;}
shimogamo 4:650af94bf062 136 double Global::getminyaw(){return minyaw;}
shimogamo 4:650af94bf062 137 double Global::getneutralyaw(){return neutralyaw;}
shimogamo 4:650af94bf062 138
shimogamo 4:650af94bf062 139 void Global::setmaxpitch(double _maxpitch){maxpitch = _maxpitch;}
shimogamo 4:650af94bf062 140 void Global::setminpitch(double _minpitch){minpitch = _minpitch;}
shimogamo 4:650af94bf062 141 void Global::setneutralpitch(double _neutralpitch){neutralpitch = _neutralpitch;}
shimogamo 4:650af94bf062 142 void Global::setmaxyaw(double _maxyaw){maxyaw = _maxyaw;}
shimogamo 4:650af94bf062 143 void Global::setminyaw(double _minyaw){minyaw = _minyaw;}
shimogamo 4:650af94bf062 144 void Global::setneutralyaw(double _neutralyaw){neutralyaw = _neutralyaw;}
shimogamo 4:650af94bf062 145
shimogamo 4:650af94bf062 146 double Global::getmaxpitchdegree(){return maxpitchdegree;}
shimogamo 4:650af94bf062 147 double Global::getneutralpitchdegree(){return neutralpitchdegree;}
shimogamo 4:650af94bf062 148 double Global::getminpitchdegree(){return minpitchdegree;}
shimogamo 4:650af94bf062 149 double Global::getmaxyawdegree(){return maxyawdegree;}
shimogamo 4:650af94bf062 150 double Global::getneutralyawdegree(){return neutralyawdegree;}
shimogamo 4:650af94bf062 151 double Global::getminyawdegree(){return minyawdegree;}
shimogamo 4:650af94bf062 152
shimogamo 0:2a15bd367891 153 void Global::setmaxpitchdegree(double _maxpitchdegree){maxpitchdegree=_maxpitchdegree;}
shimogamo 0:2a15bd367891 154 void Global::setneutralpitchdegree(double _neutralpitchdegree){neutralpitchdegree=_neutralpitchdegree;}
shimogamo 0:2a15bd367891 155 void Global::setminpitchdegree(double _minpitchdegree){minpitchdegree=_minpitchdegree;}
shimogamo 0:2a15bd367891 156 void Global::setmaxyawdegree(double _maxyawdegree){maxyawdegree=_maxyawdegree;}
shimogamo 0:2a15bd367891 157 void Global::setneutralyawdegree(double _neutralyawdegree){neutralyawdegree=_neutralyawdegree;}
shimogamo 0:2a15bd367891 158 void Global::setminyawdegree(double _minyawdegree){minyawdegree=_minyawdegree;}
shimogamo 4:650af94bf062 159
shimogamo 4:650af94bf062 160
shimogamo 8:ca92cb674004 161 double Global::getmaxpitchplayratio(){return maxpitchplayratio;}
shimogamo 8:ca92cb674004 162 double Global::getminpitchplayratio(){return minpitchplayratio;}
shimogamo 8:ca92cb674004 163 double Global::getmaxyawplayratio(){return maxyawplayratio;}
shimogamo 8:ca92cb674004 164 double Global::getminyawplayratio(){return minyawplayratio;}
shimogamo 8:ca92cb674004 165
shimogamo 8:ca92cb674004 166 void Global::setmaxpitchplayratio(double _maxpitchplayratio){maxpitchplayratio=_maxpitchplayratio;}
shimogamo 8:ca92cb674004 167 void Global::setminpitchplayratio(double _minpitchplayratio){minpitchplayratio=_minpitchplayratio;}
shimogamo 8:ca92cb674004 168 void Global::setmaxyawplayratio(double _maxyawplayratio){maxyawplayratio=_maxyawplayratio;}
shimogamo 8:ca92cb674004 169 void Global::setminyawplayratio(double _minyawplayratio){minyawplayratio=_minyawplayratio;}
shimogamo 8:ca92cb674004 170
shimogamo 9:d1fc0805ec7d 171 double Global::gettrimpitchrate(){return trimpitchrate;}
shimogamo 1:3f857674a290 172
shimogamo 9:d1fc0805ec7d 173 void Global::settrimpitchrate(double _trimpitchrate){trimpitchrate=_trimpitchrate;}
shimogamo 1:3f857674a290 174
shimogamo 1:3f857674a290 175
shimogamo 0:2a15bd367891 176 //変数
shimogamo 1:3f857674a290 177 double Global::getpitch(){return pitch;}
shimogamo 8:ca92cb674004 178 double Global::getpitchdegree(){return pitchdegree;}
shimogamo 10:0a4bf8c82493 179 int Global::getinttrimpitch(){return inttrimpitch;}
shimogamo 1:3f857674a290 180 double Global::getyaw(){return yaw;}
shimogamo 8:ca92cb674004 181 double Global::getyawdegree(){return yawdegree;}
shimogamo 10:0a4bf8c82493 182 int Global::getinttrimyaw(){return inttrimyaw;}
shimogamo 1:3f857674a290 183 double Global::getairspeed(){return airspeed;}
shimogamo 1:3f857674a290 184 double Global::getcadence(){return cadence;}
shimogamo 10:0a4bf8c82493 185 double Global::getultsonic(){return ultsonic;}
shimogamo 10:0a4bf8c82493 186 double Global::getatmpress(){return atmpress;}
shimogamo 16:7e36177b4435 187 int Global::getselector(){return selector;}
shimogamo 10:0a4bf8c82493 188
shimogamo 13:a8e10a69df45 189 int Global::getpitchtime(){return pitchtime;}
shimogamo 13:a8e10a69df45 190 int Global::getpitchdegreetime(){return pitchdegreetime;}
shimogamo 13:a8e10a69df45 191 int Global::getinttrimpitchtime(){return inttrimpitchtime;}
shimogamo 13:a8e10a69df45 192 int Global::getyawtime(){return yawtime;}
shimogamo 13:a8e10a69df45 193 int Global::getyawdegreetime(){return yawdegreetime;}
shimogamo 13:a8e10a69df45 194 int Global::getinttrimyawtime(){return inttrimyawtime;}
shimogamo 13:a8e10a69df45 195 int Global::getairspeedtime(){return airspeedtime;}
shimogamo 13:a8e10a69df45 196 int Global::getcadencetime(){return cadencetime;}
shimogamo 13:a8e10a69df45 197 int Global::getultsonictime(){return ultsonictime;}
shimogamo 13:a8e10a69df45 198 int Global::getatmpresstime(){return atmpresstime;}
shimogamo 16:7e36177b4435 199 int Global::getselectortime(){return selectortime;}
shimogamo 13:a8e10a69df45 200
shimogamo 13:a8e10a69df45 201
shimogamo 0:2a15bd367891 202
shimogamo 12:8e39bb45c61c 203 void Global::setpitch(double _pitch){
shimogamo 12:8e39bb45c61c 204 pitch = _pitch;
shimogamo 13:a8e10a69df45 205 pitchtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 206 }
shimogamo 12:8e39bb45c61c 207 void Global::setpitchdegree(double _pitchdegree){
shimogamo 12:8e39bb45c61c 208 pitchdegree = _pitchdegree;
shimogamo 13:a8e10a69df45 209 pitchdegreetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 210 }
shimogamo 12:8e39bb45c61c 211 void Global::setinttrimpitch(int _inttrimpitch){
shimogamo 12:8e39bb45c61c 212 inttrimpitch = _inttrimpitch;
shimogamo 13:a8e10a69df45 213 inttrimpitchtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 214 }
shimogamo 12:8e39bb45c61c 215 void Global::setyaw(double _yaw){
shimogamo 12:8e39bb45c61c 216 yaw = _yaw;
shimogamo 13:a8e10a69df45 217 yawtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 218 }
shimogamo 12:8e39bb45c61c 219 void Global::setyawdegree(double _yawdegree){
shimogamo 12:8e39bb45c61c 220 yawdegree = _yawdegree;
shimogamo 13:a8e10a69df45 221 yawdegreetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 222 }
shimogamo 12:8e39bb45c61c 223 void Global::setinttrimyaw(int _inttrimyaw){
shimogamo 12:8e39bb45c61c 224 inttrimyaw = _inttrimyaw;
shimogamo 13:a8e10a69df45 225 inttrimyawtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 226 }
shimogamo 12:8e39bb45c61c 227 void Global::setairspeed(double _airspeed){
shimogamo 12:8e39bb45c61c 228 airspeed = _airspeed;
shimogamo 13:a8e10a69df45 229 airspeedtime = timer.read_ms();
shimogamo 12:8e39bb45c61c 230 }
shimogamo 12:8e39bb45c61c 231 void Global::setcadence(double _cadence){
shimogamo 12:8e39bb45c61c 232 cadence = _cadence;
shimogamo 13:a8e10a69df45 233 cadencetime = timer.read_ms();
shimogamo 12:8e39bb45c61c 234 }
shimogamo 12:8e39bb45c61c 235 void Global::setultsonic(double _ultsonic){
shimogamo 12:8e39bb45c61c 236 ultsonic = _ultsonic;
shimogamo 13:a8e10a69df45 237 ultsonictime = timer.read_ms();
shimogamo 12:8e39bb45c61c 238 }
shimogamo 12:8e39bb45c61c 239 void Global::setatmpress(double _atmpress){
shimogamo 12:8e39bb45c61c 240 atmpress = _atmpress;
shimogamo 13:a8e10a69df45 241 atmpresstime = timer.read_ms();
shimogamo 12:8e39bb45c61c 242 }
shimogamo 16:7e36177b4435 243 void Global::setselector(int _selector){
shimogamo 16:7e36177b4435 244 selector = _selector;
shimogamo 16:7e36177b4435 245 selectortime = timer.read_ms();
shimogamo 16:7e36177b4435 246 }