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