kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Tue Oct 13 13:10:21 2015 +0000
Revision:
8:ca92cb674004
Parent:
7:6f7bd18ce796
Child:
9:d1fc0805ec7d
play????????

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 3:e3c41153e5fe 3
shimogamo 3:e3c41153e5fe 4 //トリムはGlobalで足したほうがいいかも
shimogamo 3:e3c41153e5fe 5
shimogamo 3:e3c41153e5fe 6
shimogamo 3:e3c41153e5fe 7 //----------------普段は変動しない変数(定数)------------------------------------------------------
shimogamo 8:ca92cb674004 8 //サーボのパラメータ(角度(deg)で設定)max,minはニュートラルを基準にしている
shimogamo 4:650af94bf062 9 double Global::maxpitch = 5.0;
shimogamo 4:650af94bf062 10 double Global::minpitch = -5.0;
shimogamo 4:650af94bf062 11 double Global::neutralpitch = 0;
shimogamo 4:650af94bf062 12 double Global::maxyaw = 30.0;
shimogamo 4:650af94bf062 13 double Global::minyaw = -30.0;
shimogamo 4:650af94bf062 14 double Global::neutralyaw = 0;
shimogamo 8:ca92cb674004 15 //ジョイスティックのパラメータ(mbedのAnalogIn値[0,1])/max, min, neu全て[0,1]の絶対的な値をとる
shimogamo 4:650af94bf062 16 double Global::maxpitchdegree = 1.0;
shimogamo 4:650af94bf062 17 double Global::minpitchdegree = 0;
shimogamo 4:650af94bf062 18 double Global::neutralpitchdegree = 0.5;
shimogamo 4:650af94bf062 19 double Global::maxyawdegree = 1.0;
shimogamo 4:650af94bf062 20 double Global::minyawdegree = 0;
shimogamo 4:650af94bf062 21 double Global::neutralyawdegree = 0.5;
shimogamo 8:ca92cb674004 22 //ジョイスティックの遊び
shimogamo 8:ca92cb674004 23 double Global::maxpitchplayratio = 0;
shimogamo 8:ca92cb674004 24 double Global::minpitchplayratio = 0;
shimogamo 8:ca92cb674004 25 double Global::maxyawplayratio = 0;
shimogamo 8:ca92cb674004 26 double Global::minyawplayratio = 0;
shimogamo 8:ca92cb674004 27
shimogamo 3:e3c41153e5fe 28
shimogamo 3:e3c41153e5fe 29 //----------------周期的に変動する変数------------------------------------------------------
shimogamo 8:ca92cb674004 30 double Global::pitch;
shimogamo 8:ca92cb674004 31 double Global::pitchdegree;//controllerの生データ
shimogamo 0:2a15bd367891 32 double Global::trimpitch;
shimogamo 0:2a15bd367891 33 double Global::inttrimpitch;
shimogamo 8:ca92cb674004 34 double Global::yaw;
shimogamo 8:ca92cb674004 35 double Global::yawdegree;//controllerの生データ
shimogamo 8:ca92cb674004 36 double Global::trimyaw;
shimogamo 0:2a15bd367891 37 double Global::inttrimyaw;
shimogamo 1:3f857674a290 38 double Global::airspeed;
shimogamo 1:3f857674a290 39 double Global::cadence;
shimogamo 1:3f857674a290 40 double Global::altitude;
shimogamo 0:2a15bd367891 41
shimogamo 4:650af94bf062 42 //----------------どこからでも使えるled,スイッチ,タイマーの一括管理-----------------------------
shimogamo 0:2a15bd367891 43 Timer Global::timer;
shimogamo 0:2a15bd367891 44 DigitalIn Global::initializeswitch(p23,PullUp);//否定で押しているとき
shimogamo 0:2a15bd367891 45 DigitalOut Global::led1(LED1);
shimogamo 0:2a15bd367891 46 DigitalOut Global::led2(LED2);
shimogamo 0:2a15bd367891 47 DigitalOut Global::led3(LED3);
shimogamo 0:2a15bd367891 48 DigitalOut Global::led4(LED4);
shimogamo 6:0d9fa7152934 49 LocalFileSystem Global::local("local");
shimogamo 6:0d9fa7152934 50
shimogamo 0:2a15bd367891 51
shimogamo 5:9a1ec02229dd 52 void Global::initialize(){
shimogamo 6:0d9fa7152934 53 timer.start();
shimogamo 6:0d9fa7152934 54 fileread();
shimogamo 6:0d9fa7152934 55 }
shimogamo 6:0d9fa7152934 56
shimogamo 6:0d9fa7152934 57 void Global::fileread(){
shimogamo 6:0d9fa7152934 58 float a, b, c, d, e, f;
shimogamo 6:0d9fa7152934 59
shimogamo 6:0d9fa7152934 60 FILE* fp = fopen("/local/init.csv", "r");
shimogamo 6:0d9fa7152934 61 if(fp == NULL) {
shimogamo 6:0d9fa7152934 62 filewrite();
shimogamo 6:0d9fa7152934 63 return;
shimogamo 6:0d9fa7152934 64 }
shimogamo 6:0d9fa7152934 65 //1行目
shimogamo 7:6f7bd18ce796 66 fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f);
shimogamo 6:0d9fa7152934 67 setneutralpitch(a);
shimogamo 6:0d9fa7152934 68 setmaxpitch(b);
shimogamo 6:0d9fa7152934 69 setminpitch(c);
shimogamo 6:0d9fa7152934 70 setneutralyaw(d);
shimogamo 6:0d9fa7152934 71 setmaxyaw(e);
shimogamo 6:0d9fa7152934 72 setminyaw(f);
shimogamo 8:ca92cb674004 73 //2行目
shimogamo 8:ca92cb674004 74 fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f);
shimogamo 8:ca92cb674004 75 setneutralpitchdegree(a);
shimogamo 8:ca92cb674004 76 setmaxpitchdegree(b);
shimogamo 8:ca92cb674004 77 setminpitchdegree(c);
shimogamo 8:ca92cb674004 78 setneutralyawdegree(d);
shimogamo 8:ca92cb674004 79 setmaxyawdegree(e);
shimogamo 8:ca92cb674004 80 setminyawdegree(f);
shimogamo 8:ca92cb674004 81 //3行目
shimogamo 8:ca92cb674004 82 fscanf(fp, "%f,%f,%f,%f",&a, &b, &c, &d);
shimogamo 8:ca92cb674004 83 setmaxpitchplayratio(a);
shimogamo 8:ca92cb674004 84 setminpitchplayratio(b);
shimogamo 8:ca92cb674004 85 setmaxyawplayratio(c);
shimogamo 8:ca92cb674004 86 setminyawplayratio(d);
shimogamo 8:ca92cb674004 87
shimogamo 6:0d9fa7152934 88 fclose(fp);
shimogamo 6:0d9fa7152934 89 }
shimogamo 6:0d9fa7152934 90
shimogamo 6:0d9fa7152934 91 void Global::filewrite(){
shimogamo 6:0d9fa7152934 92 FILE* fp = fopen("/local/init.csv", "w");
shimogamo 6:0d9fa7152934 93 if(fp == NULL) {
shimogamo 6:0d9fa7152934 94 error("Could not open file for write\n");
shimogamo 6:0d9fa7152934 95 }
shimogamo 6:0d9fa7152934 96 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",
shimogamo 6:0d9fa7152934 97 getneutralpitch(),
shimogamo 6:0d9fa7152934 98 getmaxpitch(),
shimogamo 6:0d9fa7152934 99 getminpitch(),
shimogamo 6:0d9fa7152934 100 getneutralyaw(),
shimogamo 6:0d9fa7152934 101 getmaxyaw(),
shimogamo 6:0d9fa7152934 102 getminyaw());
shimogamo 8:ca92cb674004 103 fprintf(fp, "%f,%f,%f,%f,%f,%f\n",
shimogamo 8:ca92cb674004 104 getneutralpitchdegree(),
shimogamo 8:ca92cb674004 105 getmaxpitchdegree(),
shimogamo 8:ca92cb674004 106 getminpitchdegree(),
shimogamo 8:ca92cb674004 107 getneutralyawdegree(),
shimogamo 8:ca92cb674004 108 getmaxyawdegree(),
shimogamo 8:ca92cb674004 109 getminyawdegree());
shimogamo 8:ca92cb674004 110 fprintf(fp, "%f,%f,%f,%f\n",
shimogamo 8:ca92cb674004 111 getmaxpitchplayratio(),
shimogamo 8:ca92cb674004 112 getminpitchplayratio(),
shimogamo 8:ca92cb674004 113 getmaxyawplayratio(),
shimogamo 8:ca92cb674004 114 getminyawplayratio());
shimogamo 8:ca92cb674004 115
shimogamo 6:0d9fa7152934 116 fclose(fp);
shimogamo 5:9a1ec02229dd 117 }
shimogamo 5:9a1ec02229dd 118
shimogamo 1:3f857674a290 119
shimogamo 4:650af94bf062 120 //定数チックな変数
shimogamo 4:650af94bf062 121 double Global::getmaxpitch(){return maxpitch;}
shimogamo 4:650af94bf062 122 double Global::getminpitch(){return minpitch;}
shimogamo 4:650af94bf062 123 double Global::getneutralpitch(){return neutralpitch;}
shimogamo 4:650af94bf062 124 double Global::getmaxyaw(){return maxyaw;}
shimogamo 4:650af94bf062 125 double Global::getminyaw(){return minyaw;}
shimogamo 4:650af94bf062 126 double Global::getneutralyaw(){return neutralyaw;}
shimogamo 4:650af94bf062 127
shimogamo 4:650af94bf062 128 void Global::setmaxpitch(double _maxpitch){maxpitch = _maxpitch;}
shimogamo 4:650af94bf062 129 void Global::setminpitch(double _minpitch){minpitch = _minpitch;}
shimogamo 4:650af94bf062 130 void Global::setneutralpitch(double _neutralpitch){neutralpitch = _neutralpitch;}
shimogamo 4:650af94bf062 131 void Global::setmaxyaw(double _maxyaw){maxyaw = _maxyaw;}
shimogamo 4:650af94bf062 132 void Global::setminyaw(double _minyaw){minyaw = _minyaw;}
shimogamo 4:650af94bf062 133 void Global::setneutralyaw(double _neutralyaw){neutralyaw = _neutralyaw;}
shimogamo 4:650af94bf062 134
shimogamo 4:650af94bf062 135 double Global::getmaxpitchdegree(){return maxpitchdegree;}
shimogamo 4:650af94bf062 136 double Global::getneutralpitchdegree(){return neutralpitchdegree;}
shimogamo 4:650af94bf062 137 double Global::getminpitchdegree(){return minpitchdegree;}
shimogamo 4:650af94bf062 138 double Global::getmaxyawdegree(){return maxyawdegree;}
shimogamo 4:650af94bf062 139 double Global::getneutralyawdegree(){return neutralyawdegree;}
shimogamo 4:650af94bf062 140 double Global::getminyawdegree(){return minyawdegree;}
shimogamo 4:650af94bf062 141
shimogamo 0:2a15bd367891 142 void Global::setmaxpitchdegree(double _maxpitchdegree){maxpitchdegree=_maxpitchdegree;}
shimogamo 0:2a15bd367891 143 void Global::setneutralpitchdegree(double _neutralpitchdegree){neutralpitchdegree=_neutralpitchdegree;}
shimogamo 0:2a15bd367891 144 void Global::setminpitchdegree(double _minpitchdegree){minpitchdegree=_minpitchdegree;}
shimogamo 0:2a15bd367891 145 void Global::setmaxyawdegree(double _maxyawdegree){maxyawdegree=_maxyawdegree;}
shimogamo 0:2a15bd367891 146 void Global::setneutralyawdegree(double _neutralyawdegree){neutralyawdegree=_neutralyawdegree;}
shimogamo 0:2a15bd367891 147 void Global::setminyawdegree(double _minyawdegree){minyawdegree=_minyawdegree;}
shimogamo 4:650af94bf062 148
shimogamo 4:650af94bf062 149
shimogamo 8:ca92cb674004 150 double Global::getmaxpitchplayratio(){return maxpitchplayratio;}
shimogamo 8:ca92cb674004 151 double Global::getminpitchplayratio(){return minpitchplayratio;}
shimogamo 8:ca92cb674004 152 double Global::getmaxyawplayratio(){return maxyawplayratio;}
shimogamo 8:ca92cb674004 153 double Global::getminyawplayratio(){return minyawplayratio;}
shimogamo 8:ca92cb674004 154
shimogamo 8:ca92cb674004 155 void Global::setmaxpitchplayratio(double _maxpitchplayratio){maxpitchplayratio=_maxpitchplayratio;}
shimogamo 8:ca92cb674004 156 void Global::setminpitchplayratio(double _minpitchplayratio){minpitchplayratio=_minpitchplayratio;}
shimogamo 8:ca92cb674004 157 void Global::setmaxyawplayratio(double _maxyawplayratio){maxyawplayratio=_maxyawplayratio;}
shimogamo 8:ca92cb674004 158 void Global::setminyawplayratio(double _minyawplayratio){minyawplayratio=_minyawplayratio;}
shimogamo 8:ca92cb674004 159
shimogamo 1:3f857674a290 160
shimogamo 1:3f857674a290 161
shimogamo 1:3f857674a290 162
shimogamo 0:2a15bd367891 163 //変数
shimogamo 1:3f857674a290 164 double Global::getpitch(){return pitch;}
shimogamo 8:ca92cb674004 165 double Global::getpitchdegree(){return pitchdegree;}
shimogamo 1:3f857674a290 166 double Global::gettrimpitch(){return trimpitch;}
shimogamo 1:3f857674a290 167 double Global::getinttrimpitch(){return inttrimpitch;}
shimogamo 1:3f857674a290 168 double Global::getyaw(){return yaw;}
shimogamo 8:ca92cb674004 169 double Global::getyawdegree(){return yawdegree;}
shimogamo 1:3f857674a290 170 double Global::gettrimyaw(){return trimyaw;}
shimogamo 1:3f857674a290 171 double Global::getinttrimyaw(){return inttrimyaw;}
shimogamo 1:3f857674a290 172 double Global::getairspeed(){return airspeed;}
shimogamo 1:3f857674a290 173 double Global::getcadence(){return cadence;}
shimogamo 1:3f857674a290 174 double Global::getaltitude(){return altitude;}
shimogamo 0:2a15bd367891 175
shimogamo 1:3f857674a290 176 void Global::setpitch(double _pitch){pitch = _pitch;}
shimogamo 8:ca92cb674004 177 void Global::setpitchdegree(double _pitchdegree){pitchdegree = _pitchdegree;}
shimogamo 1:3f857674a290 178 void Global::settrimpitch(double _trimpitch){trimpitch = _trimpitch;}
shimogamo 1:3f857674a290 179 void Global::setinttrimpitch(double _inttrimpitch){inttrimpitch = _inttrimpitch;}
shimogamo 1:3f857674a290 180 void Global::setyaw(double _yaw){yaw = _yaw;}
shimogamo 8:ca92cb674004 181 void Global::setyawdegree(double _yawdegree){yawdegree = _yawdegree;}
shimogamo 1:3f857674a290 182 void Global::settrimyaw(double _trimyaw){trimyaw = _trimyaw;}
shimogamo 1:3f857674a290 183 void Global::setinttrimyaw(double _inttrimyaw){inttrimyaw = _inttrimyaw;}
shimogamo 1:3f857674a290 184 void Global::setairspeed(double _airspeed){airspeed = _airspeed;}
shimogamo 1:3f857674a290 185 void Global::setcadence(double _cadence){cadence = _cadence;}
shimogamo 1:3f857674a290 186 void Global::setaltitude(double _altitude){altitude = _altitude;}
shimogamo 4:650af94bf062 187