imu01c

Files at this revision

API Documentation at this revision

Comitter:
HMFK03LST1
Date:
Wed Jul 20 14:13:23 2016 +0000
Parent:
2:4bfc36c368c2
Commit message:
first

Changed in this revision

LSM303D.cpp Show annotated file Show diff for this revision Revisions of this file
LSM303D.h Show annotated file Show diff for this revision Revisions of this file
vector.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4bfc36c368c2 -r a55edecc96e2 LSM303D.cpp
--- a/LSM303D.cpp	Tue Feb 09 07:46:40 2016 +0000
+++ b/LSM303D.cpp	Wed Jul 20 14:13:23 2016 +0000
@@ -42,7 +42,7 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-#define FILTER_SHIFT 2      // used in filtering acceleromter readings
+#define FILTER_SHIFT 1      // used in filtering acceleromter readings
 
 const int addr_ls303d = 0x3A;
 
@@ -130,13 +130,17 @@
     reg_v |= 0x00 << 0;     /* Mag Continuous Conversation*/
     write_reg(addr_ls303d,CTRL_REG7_A,reg_v); //26h
 
-    min.x =-4500;
-    min.y =-4500;
-    min.z =-4500;
+    min.x =-2000;
+    min.y =-2000;
+    min.z = 1000;
         
-    max.x = 1200;
-    max.y = 1200;
-    max.z = 100 ;
+    max.x = -1000;
+    max.y = -1000;
+    max.z =  4000;
+    
+    spreed.x = 6000;
+    spreed.y = 6000;
+    spreed.z = 6000;
 }
 
 
@@ -222,8 +226,8 @@
     vector_normalize(&temp_a);
 
     // compute E and N
-    vector E;
-    vector N;
+    vector E;                           //vector East
+    vector N;                           //vector Nord
     vector_cross(&mag,&temp_a,&E);
     vector_normalize(&E);
     vector_cross(&temp_a,&E,&N);
@@ -243,23 +247,34 @@
     //if (hdg > 360) hdg -= 360;
     
     vector_norm_xz(&temp_a);
-    pitch = asin(temp_a.x) * 180/M_PI + 25;
+    pitch = (asin(temp_a.x) * 180/M_PI) + 25;
     
 }
 
-void LSM303D::set_limits(void)
+void LSM303D::set_limits(int mode)
 {
-   if (max.x < mag_raw.x) max.x = mag_raw.x;
-   if (min.x > mag_raw.x) min.x = mag_raw.x;
-   if (max.y < mag_raw.y) max.y = mag_raw.y;
-   if (min.y > mag_raw.y) min.y = mag_raw.y; 
-   if (max.z < mag_raw.z) max.z = mag_raw.z;
-   if (min.z > mag_raw.z) min.z = mag_raw.z;
-   
+   if(mode == 1)                            //first cal.
+    {
+     if (max.x < mag_raw.x) max.x = mag_raw.x;
+     if (min.x > mag_raw.x) min.x = mag_raw.x;
+     if (max.y < mag_raw.y) max.y = mag_raw.y;
+     if (min.y > mag_raw.y) min.y = mag_raw.y; 
+     if (max.z < mag_raw.z) max.z = mag_raw.z;
+     if (min.z > mag_raw.z) min.z = mag_raw.z;
+   }
+   if(mode == 2)                            //autorecal.
+    {   
+     if (max.x < mag_raw.x) max.x += 5;
+     if (min.x > mag_raw.x) min.x -= 5;
+     if (max.y < mag_raw.y) max.y += 5;
+     if (min.y > mag_raw.y) min.y -= 5; 
+     if (max.z < mag_raw.z) max.z += 5;
+     if (min.z > mag_raw.z) min.z -= 5;  
+    }
        
-   if ((max.x - min.x) > 7200) {max.x--; min.x++;};
-   if ((max.y - min.y) > 7200) {max.y--; min.y++;};
-   if ((max.z - min.z) > 6200) {max.z--; min.z++;}; 
+   if ((max.x - min.x) > spreed.x) {max.x--; min.x++;};
+   if ((max.y - min.y) > spreed.y) {max.y--; min.y++;};
+   if ((max.z - min.z) > spreed.z) {max.z--; min.z++;}; 
 }
 
 void LSM303D::frequency(int hz)
diff -r 4bfc36c368c2 -r a55edecc96e2 LSM303D.h
--- a/LSM303D.h	Tue Feb 09 07:46:40 2016 +0000
+++ b/LSM303D.h	Wed Jul 20 14:13:23 2016 +0000
@@ -89,9 +89,14 @@
         //! Pitch
         float  pitch;
         
+        //! MAG Minimal readings
         vector min; 
         
-        vector max; 
+        //! MAG Maximal readings
+        vector max;
+        
+        //! MAG Min-Max estimated range
+        vector spreed;   
         
         /** Create a new interface for an LSM303D
          *
@@ -135,7 +140,7 @@
     
         /** Set Mag Limits 
          */
-        void set_limits(void);
+        void set_limits(int mode);
     
     
         /** sets the I2C bus frequency
diff -r 4bfc36c368c2 -r a55edecc96e2 vector.cpp
--- a/vector.cpp	Tue Feb 09 07:46:40 2016 +0000
+++ b/vector.cpp	Wed Jul 20 14:13:23 2016 +0000
@@ -23,7 +23,7 @@
 
 void vector_norm_xz(vector*a)
 {
- float mag = sqrt(a->x*a->x + a->z*a->z);
+ float mag = sqrt((a->x*a->x) + (a->z*a->z));
  a->x /= mag;
  a->y  = 0;
  a->z /= mag;