コントロールの前段階。姿勢制御の実験中。

Dependencies:   HMC6352 mbed

Fork of rcj2015_CatPot_MotorTest by Fumiya Fujisawa

Files at this revision

API Documentation at this revision

Comitter:
shiyuu
Date:
Mon Mar 07 09:08:05 2016 +0000
Parent:
2:89bdaf269693
Commit message:
?????????????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 89bdaf269693 -r 69ce73ed70a7 main.cpp
--- a/main.cpp	Mon Mar 07 07:30:55 2016 +0000
+++ b/main.cpp	Mon Mar 07 09:08:05 2016 +0000
@@ -1,4 +1,4 @@
-/* 実験中 */
+/* 取り敢えずこれで。 */
 
 #include "mbed.h"
 #include "HMC6352.h"
@@ -7,9 +7,9 @@
 
 #define PAI 3.1415926535897932384626
 #define POWER 0
+#define PROPORTION 0.7
+#define INSTANCE 1.05
 #define LIMIT 1
-#define TRIALS 1
-#define ZERO 0
 
 BusOut m_led(LED1,LED2,LED3,LED4);
 //DigitalOut myled(LED1);
@@ -31,13 +31,15 @@
 void move(double see,int direction){
     double pwm[4] = {0};
     
-    pwm[0] = ( sin((see -  60.0)* PAI/180.0)*POWER )- direction * 0.7;
-    pwm[1] = ( sin((see - 300.0)* PAI/180.0)*POWER )- direction * 0.7;
-    pwm[2] = ( sin((see - 180.0)* PAI/180.0)*POWER )- direction * 0.7;
+    pwm[0] = ( sin((see -  60.0)* PAI/180.0)*POWER )- direction * PROPORTION * LIMIT;
+    pwm[1] = ( sin((see - 300.0)* PAI/180.0)*POWER )- direction * PROPORTION * LIMIT;
+    pwm[2] = ( sin((see - 180.0)* PAI/180.0)*POWER )- direction * PROPORTION * LIMIT;
     pwm[3] = 0;
-    pwm[0] *= LIMIT;
-    pwm[1] *= LIMIT;
-    pwm[2] *= LIMIT;
+    if(direction<0){
+    pwm[0] *= INSTANCE;   
+    pwm[1] *= INSTANCE;
+    pwm[2] *= INSTANCE; 
+    }    
     //pc.printf("%d %d %d\n",speed[0],speed[1],speed[2]);
     for(i = 0; i < 4; i++){
         if(pwm[i] > 100){
@@ -59,7 +61,7 @@
 
 int main() {
     int seeta=0,diff=0,getFirst=0,min1=0,min2=1,max1=359,max2=358;
-    int sampleC[TRIALS] = {0},getCompass[TRIALS] = {0};
+    int getCompass=0;
     compass.setOpMode(HMC6352_CONTINUOUS, 1, 20);//最初のSetting
     
     //
@@ -81,29 +83,12 @@
     //
     
     while(1){
-         //
-         /*for(j=0;j<TRIALS;j++){
-            getCompass[j] = ( compass.sample() / 10.0 );
-            //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);
+         getCompass = ( compass.sample() / 10.0 );
+         diff = diffKun(getCompass,getFirst);
          
          move(seeta,diff); 
-         pc.printf("%d %d  %d",getFirst,getCompass[0],diff);
+         pc.printf("%d %d  %d",getFirst,getCompass,diff);
          pc.printf("  %d %d %d\n",speed[0],speed[1],speed[2]);
          //wait(0.01);
     }
-    /*wait(1); 
-    speed[0] = 0;
-    speed[1] = 0;
-    speed[2] = 0;*/ 
-    while(1);
 }