Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Global.cpp@9:d1fc0805ec7d, 2015-10-14 (annotated)
- Committer:
- shimogamo
- Date:
- Wed Oct 14 13:44:32 2015 +0000
- Revision:
- 9:d1fc0805ec7d
- Parent:
- 8:ca92cb674004
- Child:
- 10:0a4bf8c82493
Init??????
Who changed what in which revision?
User | Revision | Line number | New 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 | //トリムはGlobalで足したほうがいいかも |
shimogamo | 3:e3c41153e5fe | 7 | |
shimogamo | 3:e3c41153e5fe | 8 | |
shimogamo | 9:d1fc0805ec7d | 9 | Queue<char, 20> Global::queue; |
shimogamo | 3:e3c41153e5fe | 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 | 0:2a15bd367891 | 36 | double Global::trimpitch; |
shimogamo | 0:2a15bd367891 | 37 | double Global::inttrimpitch; |
shimogamo | 8:ca92cb674004 | 38 | double Global::yaw; |
shimogamo | 8:ca92cb674004 | 39 | double Global::yawdegree;//controllerの生データ |
shimogamo | 8:ca92cb674004 | 40 | double Global::trimyaw; |
shimogamo | 0:2a15bd367891 | 41 | double Global::inttrimyaw; |
shimogamo | 1:3f857674a290 | 42 | double Global::airspeed; |
shimogamo | 1:3f857674a290 | 43 | double Global::cadence; |
shimogamo | 1:3f857674a290 | 44 | double Global::altitude; |
shimogamo | 0:2a15bd367891 | 45 | |
shimogamo | 4:650af94bf062 | 46 | //----------------どこからでも使えるled,スイッチ,タイマーの一括管理----------------------------- |
shimogamo | 0:2a15bd367891 | 47 | Timer Global::timer; |
shimogamo | 0:2a15bd367891 | 48 | DigitalIn Global::initializeswitch(p23,PullUp);//否定で押しているとき |
shimogamo | 0:2a15bd367891 | 49 | DigitalOut Global::led1(LED1); |
shimogamo | 0:2a15bd367891 | 50 | DigitalOut Global::led2(LED2); |
shimogamo | 0:2a15bd367891 | 51 | DigitalOut Global::led3(LED3); |
shimogamo | 0:2a15bd367891 | 52 | DigitalOut Global::led4(LED4); |
shimogamo | 6:0d9fa7152934 | 53 | LocalFileSystem Global::local("local"); |
shimogamo | 6:0d9fa7152934 | 54 | |
shimogamo | 0:2a15bd367891 | 55 | |
shimogamo | 5:9a1ec02229dd | 56 | void Global::initialize(){ |
shimogamo | 6:0d9fa7152934 | 57 | timer.start(); |
shimogamo | 6:0d9fa7152934 | 58 | fileread(); |
shimogamo | 6:0d9fa7152934 | 59 | } |
shimogamo | 6:0d9fa7152934 | 60 | |
shimogamo | 6:0d9fa7152934 | 61 | void Global::fileread(){ |
shimogamo | 6:0d9fa7152934 | 62 | float a, b, c, d, e, f; |
shimogamo | 6:0d9fa7152934 | 63 | |
shimogamo | 6:0d9fa7152934 | 64 | FILE* fp = fopen("/local/init.csv", "r"); |
shimogamo | 6:0d9fa7152934 | 65 | if(fp == NULL) { |
shimogamo | 6:0d9fa7152934 | 66 | filewrite(); |
shimogamo | 6:0d9fa7152934 | 67 | return; |
shimogamo | 6:0d9fa7152934 | 68 | } |
shimogamo | 6:0d9fa7152934 | 69 | //1行目 |
shimogamo | 7:6f7bd18ce796 | 70 | fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f); |
shimogamo | 6:0d9fa7152934 | 71 | setneutralpitch(a); |
shimogamo | 6:0d9fa7152934 | 72 | setmaxpitch(b); |
shimogamo | 6:0d9fa7152934 | 73 | setminpitch(c); |
shimogamo | 6:0d9fa7152934 | 74 | setneutralyaw(d); |
shimogamo | 6:0d9fa7152934 | 75 | setmaxyaw(e); |
shimogamo | 6:0d9fa7152934 | 76 | setminyaw(f); |
shimogamo | 8:ca92cb674004 | 77 | //2行目 |
shimogamo | 8:ca92cb674004 | 78 | fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f); |
shimogamo | 8:ca92cb674004 | 79 | setneutralpitchdegree(a); |
shimogamo | 8:ca92cb674004 | 80 | setmaxpitchdegree(b); |
shimogamo | 8:ca92cb674004 | 81 | setminpitchdegree(c); |
shimogamo | 8:ca92cb674004 | 82 | setneutralyawdegree(d); |
shimogamo | 8:ca92cb674004 | 83 | setmaxyawdegree(e); |
shimogamo | 8:ca92cb674004 | 84 | setminyawdegree(f); |
shimogamo | 8:ca92cb674004 | 85 | //3行目 |
shimogamo | 9:d1fc0805ec7d | 86 | fscanf(fp, "%f,%f,%f,%f,%f",&a, &b, &c, &d, &e); |
shimogamo | 8:ca92cb674004 | 87 | setmaxpitchplayratio(a); |
shimogamo | 8:ca92cb674004 | 88 | setminpitchplayratio(b); |
shimogamo | 8:ca92cb674004 | 89 | setmaxyawplayratio(c); |
shimogamo | 8:ca92cb674004 | 90 | setminyawplayratio(d); |
shimogamo | 9:d1fc0805ec7d | 91 | settrimpitchrate(e); |
shimogamo | 6:0d9fa7152934 | 92 | fclose(fp); |
shimogamo | 6:0d9fa7152934 | 93 | } |
shimogamo | 6:0d9fa7152934 | 94 | |
shimogamo | 6:0d9fa7152934 | 95 | void Global::filewrite(){ |
shimogamo | 6:0d9fa7152934 | 96 | FILE* fp = fopen("/local/init.csv", "w"); |
shimogamo | 6:0d9fa7152934 | 97 | if(fp == NULL) { |
shimogamo | 6:0d9fa7152934 | 98 | error("Could not open file for write\n"); |
shimogamo | 6:0d9fa7152934 | 99 | } |
shimogamo | 6:0d9fa7152934 | 100 | fprintf(fp, "%f,%f,%f,%f,%f,%f\n", |
shimogamo | 6:0d9fa7152934 | 101 | getneutralpitch(), |
shimogamo | 6:0d9fa7152934 | 102 | getmaxpitch(), |
shimogamo | 6:0d9fa7152934 | 103 | getminpitch(), |
shimogamo | 6:0d9fa7152934 | 104 | getneutralyaw(), |
shimogamo | 6:0d9fa7152934 | 105 | getmaxyaw(), |
shimogamo | 6:0d9fa7152934 | 106 | getminyaw()); |
shimogamo | 8:ca92cb674004 | 107 | fprintf(fp, "%f,%f,%f,%f,%f,%f\n", |
shimogamo | 8:ca92cb674004 | 108 | getneutralpitchdegree(), |
shimogamo | 8:ca92cb674004 | 109 | getmaxpitchdegree(), |
shimogamo | 8:ca92cb674004 | 110 | getminpitchdegree(), |
shimogamo | 8:ca92cb674004 | 111 | getneutralyawdegree(), |
shimogamo | 8:ca92cb674004 | 112 | getmaxyawdegree(), |
shimogamo | 8:ca92cb674004 | 113 | getminyawdegree()); |
shimogamo | 9:d1fc0805ec7d | 114 | fprintf(fp, "%f,%f,%f,%f,%f\n", |
shimogamo | 8:ca92cb674004 | 115 | getmaxpitchplayratio(), |
shimogamo | 8:ca92cb674004 | 116 | getminpitchplayratio(), |
shimogamo | 8:ca92cb674004 | 117 | getmaxyawplayratio(), |
shimogamo | 9:d1fc0805ec7d | 118 | getminyawplayratio(), |
shimogamo | 9:d1fc0805ec7d | 119 | gettrimpitchrate()); |
shimogamo | 8:ca92cb674004 | 120 | |
shimogamo | 6:0d9fa7152934 | 121 | fclose(fp); |
shimogamo | 5:9a1ec02229dd | 122 | } |
shimogamo | 5:9a1ec02229dd | 123 | |
shimogamo | 1:3f857674a290 | 124 | |
shimogamo | 4:650af94bf062 | 125 | //定数チックな変数 |
shimogamo | 4:650af94bf062 | 126 | double Global::getmaxpitch(){return maxpitch;} |
shimogamo | 4:650af94bf062 | 127 | double Global::getminpitch(){return minpitch;} |
shimogamo | 4:650af94bf062 | 128 | double Global::getneutralpitch(){return neutralpitch;} |
shimogamo | 4:650af94bf062 | 129 | double Global::getmaxyaw(){return maxyaw;} |
shimogamo | 4:650af94bf062 | 130 | double Global::getminyaw(){return minyaw;} |
shimogamo | 4:650af94bf062 | 131 | double Global::getneutralyaw(){return neutralyaw;} |
shimogamo | 4:650af94bf062 | 132 | |
shimogamo | 4:650af94bf062 | 133 | void Global::setmaxpitch(double _maxpitch){maxpitch = _maxpitch;} |
shimogamo | 4:650af94bf062 | 134 | void Global::setminpitch(double _minpitch){minpitch = _minpitch;} |
shimogamo | 4:650af94bf062 | 135 | void Global::setneutralpitch(double _neutralpitch){neutralpitch = _neutralpitch;} |
shimogamo | 4:650af94bf062 | 136 | void Global::setmaxyaw(double _maxyaw){maxyaw = _maxyaw;} |
shimogamo | 4:650af94bf062 | 137 | void Global::setminyaw(double _minyaw){minyaw = _minyaw;} |
shimogamo | 4:650af94bf062 | 138 | void Global::setneutralyaw(double _neutralyaw){neutralyaw = _neutralyaw;} |
shimogamo | 4:650af94bf062 | 139 | |
shimogamo | 4:650af94bf062 | 140 | double Global::getmaxpitchdegree(){return maxpitchdegree;} |
shimogamo | 4:650af94bf062 | 141 | double Global::getneutralpitchdegree(){return neutralpitchdegree;} |
shimogamo | 4:650af94bf062 | 142 | double Global::getminpitchdegree(){return minpitchdegree;} |
shimogamo | 4:650af94bf062 | 143 | double Global::getmaxyawdegree(){return maxyawdegree;} |
shimogamo | 4:650af94bf062 | 144 | double Global::getneutralyawdegree(){return neutralyawdegree;} |
shimogamo | 4:650af94bf062 | 145 | double Global::getminyawdegree(){return minyawdegree;} |
shimogamo | 4:650af94bf062 | 146 | |
shimogamo | 0:2a15bd367891 | 147 | void Global::setmaxpitchdegree(double _maxpitchdegree){maxpitchdegree=_maxpitchdegree;} |
shimogamo | 0:2a15bd367891 | 148 | void Global::setneutralpitchdegree(double _neutralpitchdegree){neutralpitchdegree=_neutralpitchdegree;} |
shimogamo | 0:2a15bd367891 | 149 | void Global::setminpitchdegree(double _minpitchdegree){minpitchdegree=_minpitchdegree;} |
shimogamo | 0:2a15bd367891 | 150 | void Global::setmaxyawdegree(double _maxyawdegree){maxyawdegree=_maxyawdegree;} |
shimogamo | 0:2a15bd367891 | 151 | void Global::setneutralyawdegree(double _neutralyawdegree){neutralyawdegree=_neutralyawdegree;} |
shimogamo | 0:2a15bd367891 | 152 | void Global::setminyawdegree(double _minyawdegree){minyawdegree=_minyawdegree;} |
shimogamo | 4:650af94bf062 | 153 | |
shimogamo | 4:650af94bf062 | 154 | |
shimogamo | 8:ca92cb674004 | 155 | double Global::getmaxpitchplayratio(){return maxpitchplayratio;} |
shimogamo | 8:ca92cb674004 | 156 | double Global::getminpitchplayratio(){return minpitchplayratio;} |
shimogamo | 8:ca92cb674004 | 157 | double Global::getmaxyawplayratio(){return maxyawplayratio;} |
shimogamo | 8:ca92cb674004 | 158 | double Global::getminyawplayratio(){return minyawplayratio;} |
shimogamo | 8:ca92cb674004 | 159 | |
shimogamo | 8:ca92cb674004 | 160 | void Global::setmaxpitchplayratio(double _maxpitchplayratio){maxpitchplayratio=_maxpitchplayratio;} |
shimogamo | 8:ca92cb674004 | 161 | void Global::setminpitchplayratio(double _minpitchplayratio){minpitchplayratio=_minpitchplayratio;} |
shimogamo | 8:ca92cb674004 | 162 | void Global::setmaxyawplayratio(double _maxyawplayratio){maxyawplayratio=_maxyawplayratio;} |
shimogamo | 8:ca92cb674004 | 163 | void Global::setminyawplayratio(double _minyawplayratio){minyawplayratio=_minyawplayratio;} |
shimogamo | 8:ca92cb674004 | 164 | |
shimogamo | 9:d1fc0805ec7d | 165 | double Global::gettrimpitchrate(){return trimpitchrate;} |
shimogamo | 1:3f857674a290 | 166 | |
shimogamo | 9:d1fc0805ec7d | 167 | void Global::settrimpitchrate(double _trimpitchrate){trimpitchrate=_trimpitchrate;} |
shimogamo | 1:3f857674a290 | 168 | |
shimogamo | 1:3f857674a290 | 169 | |
shimogamo | 0:2a15bd367891 | 170 | //変数 |
shimogamo | 1:3f857674a290 | 171 | double Global::getpitch(){return pitch;} |
shimogamo | 8:ca92cb674004 | 172 | double Global::getpitchdegree(){return pitchdegree;} |
shimogamo | 1:3f857674a290 | 173 | double Global::gettrimpitch(){return trimpitch;} |
shimogamo | 1:3f857674a290 | 174 | double Global::getinttrimpitch(){return inttrimpitch;} |
shimogamo | 1:3f857674a290 | 175 | double Global::getyaw(){return yaw;} |
shimogamo | 8:ca92cb674004 | 176 | double Global::getyawdegree(){return yawdegree;} |
shimogamo | 1:3f857674a290 | 177 | double Global::gettrimyaw(){return trimyaw;} |
shimogamo | 1:3f857674a290 | 178 | double Global::getinttrimyaw(){return inttrimyaw;} |
shimogamo | 1:3f857674a290 | 179 | double Global::getairspeed(){return airspeed;} |
shimogamo | 1:3f857674a290 | 180 | double Global::getcadence(){return cadence;} |
shimogamo | 1:3f857674a290 | 181 | double Global::getaltitude(){return altitude;} |
shimogamo | 0:2a15bd367891 | 182 | |
shimogamo | 1:3f857674a290 | 183 | void Global::setpitch(double _pitch){pitch = _pitch;} |
shimogamo | 8:ca92cb674004 | 184 | void Global::setpitchdegree(double _pitchdegree){pitchdegree = _pitchdegree;} |
shimogamo | 1:3f857674a290 | 185 | void Global::settrimpitch(double _trimpitch){trimpitch = _trimpitch;} |
shimogamo | 1:3f857674a290 | 186 | void Global::setinttrimpitch(double _inttrimpitch){inttrimpitch = _inttrimpitch;} |
shimogamo | 1:3f857674a290 | 187 | void Global::setyaw(double _yaw){yaw = _yaw;} |
shimogamo | 8:ca92cb674004 | 188 | void Global::setyawdegree(double _yawdegree){yawdegree = _yawdegree;} |
shimogamo | 1:3f857674a290 | 189 | void Global::settrimyaw(double _trimyaw){trimyaw = _trimyaw;} |
shimogamo | 1:3f857674a290 | 190 | void Global::setinttrimyaw(double _inttrimyaw){inttrimyaw = _inttrimyaw;} |
shimogamo | 1:3f857674a290 | 191 | void Global::setairspeed(double _airspeed){airspeed = _airspeed;} |
shimogamo | 1:3f857674a290 | 192 | void Global::setcadence(double _cadence){cadence = _cadence;} |
shimogamo | 1:3f857674a290 | 193 | void Global::setaltitude(double _altitude){altitude = _altitude;} |
shimogamo | 4:650af94bf062 | 194 |