ES2017 coursework 2

Dependencies:   PID

Fork of ES_CW2_Starter by Edward Stott

Revision:
19:93ca06d2e311
Parent:
18:55cd33a3e69f
Child:
21:3cc94df7321c
--- a/main.cpp	Thu Mar 09 16:17:12 2017 +0000
+++ b/main.cpp	Thu Mar 09 17:23:33 2017 +0000
@@ -82,7 +82,6 @@
 //Timer used for calculating speed
 Timer speedTimer;
 float measuredRevs = 0, revtimer = 0;
-Ticker printSpeed;
 
 Serial pc(SERIAL_TX, SERIAL_RX);
 
@@ -94,7 +93,6 @@
 int i=0;
 int quadraturePosition=0;
 bool spinCW=0;
-float u = 0; //Set point for VPI
 
 //Set a given drive state
 void motorOut(int8_t driveState)
@@ -191,8 +189,6 @@
         controller.setProcessValue(measuredRevs);
         speedControl = controller.compute();
 //        printf("speed setpoint: %2.3f\r\n", speedControl);
-        if(speedControl<0) speedControl = -speedControl;
-        else if (speedControl==0) speedControl = 1;
         spinWait = (1/speedControl)/6;
         Thread::wait(PIDrate);
     }
@@ -201,7 +197,7 @@
 void sing(float singFreq)
 {
     motor = driveTable[1];
-    wait(1.0);
+    wait(5.0);
     float singDelayus = 1000000/singFreq;
     for(int count=0; count<singFreq; count++) {
         motor = driveTable[2];
@@ -223,6 +219,8 @@
 {
     pc.printf("spin\n\r");
 
+    motorStop();
+
     //Run the motor synchronisation
     orState = motorHome();
     //orState is subtracted from future rotor state inputs to align rotor and motor states
@@ -321,7 +319,7 @@
                     revsec = float(tens)*10 + float(units) + float(decimals)/10;
                     //Calculate the required wait period
 
-
+                    spinWait = (1/revsec)/6;
                     //Print values for verification
                     pc.printf("Rev/S: %2.4f\n\r", revsec);
 
@@ -451,7 +449,7 @@
                     controller.setBias(bias);
                     break;
                 case 'l':
-                    sing(10000);
+                    sing(261.63);
                     break;
                 default:
                     //Set speed variables to zero to stop motor spinning