BE@R lab / motion_control

Dependencies:   motor_relay

Dependents:   dog_V3_3_testmotor

Revision:
8:371686666f4d
Parent:
7:94518aee126b
--- a/motion_control.cpp	Fri Jul 24 21:15:45 2015 +0000
+++ b/motion_control.cpp	Tue Oct 06 12:30:56 2015 +0000
@@ -86,6 +86,7 @@
     SetMode(0);
     int state=0;
     uint32_t sum=0;
+    uint16_t min=65535,max=0;
 
     do {
         state = limit_motor(1);
@@ -100,9 +101,12 @@
 
     sum=0;
     for(int a=0; a<LOOP; a++) {
-        sum += _position.read_u16();
+        sum = _position.read_u16();
+        if( sum < min) {
+            min =sum;
+        }
     }
-    MAX_POSITION = sum/LOOP;
+    MAX_POSITION = min;
 
     do {
         state = limit_motor(2);
@@ -116,10 +120,13 @@
 
     sum=0;
     for(int a=0; a<LOOP; a++) {
-        sum += _position.read_u16();
+        sum = _position.read_u16();
+        if( sum > max) {
+            max =sum;
+        }
     }
-    MIN_POSITION = sum/LOOP;
-    
+    MIN_POSITION = max;
+
     SetMode(buff);
 }