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.
Diff: Global.cpp
- Revision:
- 35:63ccdae58da4
- Parent:
- 34:770a6bbb4d63
- Child:
- 36:ad6b2b81bb89
diff -r 770a6bbb4d63 -r 63ccdae58da4 Global.cpp --- a/Global.cpp Wed Mar 01 14:34:27 2017 +0000 +++ b/Global.cpp Sat Mar 18 08:34:17 2017 +0000 @@ -1,11 +1,18 @@ #include "mbed.h" #include "Global.h" #include "rtos.h" - +#include "FlashManager.h" +extern RawSerial pc3(USBTX, USBRX); //クラスじゃなくてnamespaceのほうが綺麗にかけるかもね +void Global::setpc(RawSerial _pc){ + _pc.printf("setpc\n"); +} Queue<char, 20> Global::initqueue; +//----------------FlashMemory(pin指定はここで)-------------------------------------------- +SPI Global::spi(PA_7, PA_6, PA_5);// mosi, miso, sclk +FlashManager Global::memory(spi, PB_9);//spi, cs //----------------普段は変動しない変数------------------------------------------------------ //サーボのパラメータ(角度(度数法)で設定)max,minはニュートラルを基準にしている double Global::maxpitch = 5.0; @@ -22,10 +29,10 @@ double Global::minyawdegree = 0; double Global::neutralyawdegree = 0.5; //ジョイスティックの遊び([-1,1]でニュートラルを0とした時の値) -double Global::maxpitchplayratio = 0; -double Global::minpitchplayratio = 0; -double Global::maxyawplayratio = 0; -double Global::minyawplayratio = 0; +double Global::maxpitchplayratio = 0.1; +double Global::minpitchplayratio = -0.1; +double Global::maxyawplayratio = 0.1; +double Global::minyawplayratio = -0.1; //トリムの変化率(角度(度数法)で設定) double Global::trimpitchrate = 0.5; @@ -65,79 +72,73 @@ //----------------どこからでも使えるled,スイッチ,タイマーの一括管理----------------------------- Timer Global::timer; DigitalOut Global::led(LED2); -//LocalFileSystem Global::local("local"); //ここでINIT.csvファイルが読み込まれる void Global::initialize(){ timer.start(); + memory.reset(); //fileread(); } //INITファイルの読み込み -/*void Global::fileread(){ - float a, b, c, d, e, f; - - FILE* fp = fopen("/local/init.csv", "r"); - if(fp == NULL) { - filewrite(); - return; - } - //1行目 - fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f); - setneutralpitch(a); - setmaxpitch(b); - setminpitch(c); - setneutralyaw(d); - setmaxyaw(e); - setminyaw(f); - //2行目 - fscanf(fp, "%f,%f,%f,%f,%f,%f",&a, &b, &c, &d, &e, &f); - setneutralpitchdegree(a); - setmaxpitchdegree(b); - setminpitchdegree(c); - setneutralyawdegree(d); - setmaxyawdegree(e); - setminyawdegree(f); - //3行目 - fscanf(fp, "%f,%f,%f,%f,%f",&a, &b, &c, &d, &e); - setmaxpitchplayratio(a); - setminpitchplayratio(b); - setmaxyawplayratio(c); - setminyawplayratio(d); - settrimpitchrate(e); - fclose(fp); +void Global::fileread(){ + /***********Memoryに値が保存されていない場合filewrite()**********/ + + /************************************************************/ + + vector<double> param(17); + param = memory.readdouble(0x0,17); + + setneutralpitch(param[0]); + setmaxpitch(param[1]); + setminpitch(param[2]); + setneutralyaw(param[3]); + setmaxyaw(param[4]); + setminyaw(param[5]); + + setneutralpitchdegree(param[6]); + setmaxpitchdegree(param[7]); + setminpitchdegree(param[8]); + setneutralyawdegree(param[9]); + setmaxyawdegree(param[10]); + setminyawdegree(param[11]); + + setmaxpitchplayratio(param[12]); + setminpitchplayratio(param[13]); + setmaxyawplayratio(param[14]); + setminyawplayratio(param[15]); + settrimpitchrate(param[16]); } //INITファイルの書き込み void Global::filewrite(){ - FILE* fp = fopen("/local/init.csv", "w"); - if(fp == NULL) { - error("Could not open file for write\n"); - } - fprintf(fp, "%f,%f,%f,%f,%f,%f\n", - getneutralpitch(), - getmaxpitch(), - getminpitch(), - getneutralyaw(), - getmaxyaw(), - getminyaw()); - fprintf(fp, "%f,%f,%f,%f,%f,%f\n", - getneutralpitchdegree(), - getmaxpitchdegree(), - getminpitchdegree(), - getneutralyawdegree(), - getmaxyawdegree(), - getminyawdegree()); - fprintf(fp, "%f,%f,%f,%f,%f\n", - getmaxpitchplayratio(), - getminpitchplayratio(), - getmaxyawplayratio(), - getminyawplayratio(), - gettrimpitchrate()); - - fclose(fp); -}*/ - + // pc.printf("push"); + vector<double> param; + + param.push_back(getneutralpitch()); + param.push_back(getmaxpitch()); + param.push_back(getminpitch()); + param.push_back(getneutralyaw()); + param.push_back(getmaxyaw()); + param.push_back(getminyaw()); + + param.push_back(getneutralpitchdegree()); + param.push_back(getmaxpitchdegree()); + param.push_back(getminpitchdegree()); + param.push_back(getneutralyawdegree()); + param.push_back(getmaxyawdegree()); + param.push_back(getminyawdegree()); + + param.push_back(getmaxpitchplayratio()); + param.push_back(getminpitchplayratio()); + param.push_back(getmaxyawplayratio()); + param.push_back(getminyawplayratio()); + param.push_back(gettrimpitchrate()); + pc3.printf("%d\n",param.size()); + pc3.printf("write\n"); + memory.writedouble(0x0,param); + pc3.printf("written\n"); +} //init等で更新される変数 double Global::getmaxpitch(){return maxpitch;} @@ -183,7 +184,6 @@ void Global::settrimpitchrate(double _trimpitchrate){trimpitchrate=_trimpitchrate;} - //常に更新される変数 double Global::getpitch(){return pitch;} double Global::getpitchdegree(){return pitchdegree;} @@ -217,8 +217,6 @@ int Global::getservovolttime(){return servovolttime;} int Global::getmiconvolttime(){return miconvolttime;} - - void Global::setpitch(double _pitch){ pitch = _pitch; pitchtime = timer.read_ms();