shiyuu oguro
/
Daisen0
コントロールの前段階。姿勢制御の実験中。
Fork of rcj2015_CatPot_MotorTest by
Diff: main.cpp
- Revision:
- 2:89bdaf269693
- Parent:
- 1:e8b1e591f61e
- Child:
- 3:69ce73ed70a7
--- a/main.cpp Mon Mar 07 06:04:16 2016 +0000 +++ b/main.cpp Mon Mar 07 07:30:55 2016 +0000 @@ -1,3 +1,5 @@ +/* 実験中 */ + #include "mbed.h" #include "HMC6352.h" #include <math.h> @@ -5,8 +7,8 @@ #define PAI 3.1415926535897932384626 #define POWER 0 -#define LIMIT 0.7 -#define TRIALS 10 +#define LIMIT 1 +#define TRIALS 1 #define ZERO 0 BusOut m_led(LED1,LED2,LED3,LED4); @@ -56,20 +58,13 @@ } int main() { - int seeta=0,diff=0,min1=0,min2=1,max1=359,max2=358; + int seeta=0,diff=0,getFirst=0,min1=0,min2=1,max1=359,max2=358; int sampleC[TRIALS] = {0},getCompass[TRIALS] = {0}; + compass.setOpMode(HMC6352_CONTINUOUS, 1, 20);//最初のSetting - compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); - for(j=0;j<TRIALS;j++){ - sampleC[j] = ( compass.sample() / 10.0 ); - sampleC[j] = diffKun(sampleC[j],ZERO); - wait_ms(1); - diff += sampleC[j]; - //pc.printf("%d ",sampleC[j]); - } - diff /= TRIALS; - diff = diffKun(diff,ZERO); - + // + getFirst = ( compass.sample() / 10.0 ); + seeta = 0; motor.baud(115200); //ボーレート設定 motor.printf("1F0002F0003F0004F000\r\n"); //モータ停止 モーター番号(1~6) + ForR(前進後進) + パワー(0~100) @@ -86,14 +81,25 @@ // while(1){ - for(j=0;j<TRIALS;j++){ + // + /*for(j=0;j<TRIALS;j++){ getCompass[j] = ( compass.sample() / 10.0 ); - getCompass[j] = diffKun(); + //pc.printf("%d\n",getCompass[j]); + getCompass[j] = diffKun(getCompass[j],getFirst); + if((getCompass[j]>359)&&(j<0)) getCompass[j] = getCompass[j-1]; + diff += getCompass[j]; } + diff /= TRIALS; + diff = diffKun(diff,getFirst); + pc.printf("%d\n",diff);*/ + // + getCompass[0] = ( compass.sample() / 10.0 ); + diff = diffKun(getCompass[0],getFirst); + move(seeta,diff); - pc.printf("%f %f\n",getFirst,getCompass); - //pc.printf("%d %d %d\n",speed[0],speed[1],speed[2]); - wait(0.01); + pc.printf("%d %d %d",getFirst,getCompass[0],diff); + pc.printf(" %d %d %d\n",speed[0],speed[1],speed[2]); + //wait(0.01); } /*wait(1); speed[0] = 0;