David Pasztor / Mbed 2 deprecated Motor_control

Dependencies:   mbed-rtos mbed

Revision:
2:fe637a5f3387
Parent:
0:74a5723d604a
Child:
4:dc705df93090
--- a/main.cpp	Mon Mar 13 15:45:23 2017 +0000
+++ b/main.cpp	Mon Mar 13 17:12:25 2017 +0000
@@ -7,6 +7,7 @@
 volatile uint8_t orState = 0;                   //Motor rotor offset.
 volatile float w [3] = {0, 0, 0};               //Angular velocities
 volatile float avgW = 0;
+volatile int duty = 0;
 
 const uint16_t angle = 6283;                    //2*pi*1000 for 1 revolution
 Timer dt_I1;
@@ -16,7 +17,7 @@
 
 void i1rise(){
     state = updateState();
-    motorOut((state-orState+lead+6)%6);
+    motorOut((state-orState+lead+6)%6, duty);
     
     dt_I1.stop();
     w[0] = angle/dt_I1.read_ms();                //Calc angular velocity
@@ -27,7 +28,7 @@
 
 void i2rise(){
     state = updateState();
-    motorOut((state-orState+lead+6)%6);
+    motorOut((state-orState+lead+6)%6, duty);
     
     dt_I2.stop();
     w[1] = angle/dt_I2.read_ms();
@@ -38,7 +39,7 @@
 
 void i3rise(){
     state = updateState();
-    motorOut((state-orState+lead+6)%6);
+    motorOut((state-orState+lead+6)%6, duty);
     
     dt_I3.stop();
     w[2] = angle/dt_I3.read_ms();
@@ -49,7 +50,7 @@
 
 void i_fall(){
    state = updateState();
-   motorOut((state-orState+lead+6)%6);
+   motorOut((state-orState+lead+6)%6, duty);
 }  
 
 void CHA_rise(){
@@ -69,7 +70,7 @@
     dt_I2.start();          //Probably put these in an init function?
     dt_I3.start();
     
-    motorOut(4);            //Kickstart the motor
+    motorOut(4, 100);            //Kickstart the motor
     motorTimer.start();
     
     I1.rise(&i1rise);       //Assign interrupt handlers for LEDs
@@ -84,10 +85,16 @@
 //    CHB.fall(&CHB_fall);
 
     while (1) {
-        avgW = (w[0] + w[1] + w[2])/3;    //average speeds for better prediction
-        if(motorTimer.read_ms() >= 10000) {
+        duty += 5;
+        wait(2);
+        if(duty == 100) {
             stopMotor();
             return 0;    
         }
+        avgW = (w[0] + w[1] + w[2])/3;    //average speeds for better prediction
+        //if(motorTimer.read_ms() >= 10000) {
+        //    stopMotor();
+        //    return 0;    
+        //}
     }
 }
\ No newline at end of file