final

Dependencies:   MatrixMath Matrix ExperimentServer QEI_pmw MotorShield

Files at this revision

API Documentation at this revision

Comitter:
elijahsj
Date:
Wed Aug 26 02:44:03 2020 +0000
Parent:
9:97360c92666f
Child:
11:4eb579687dda
Commit message:
updated for shield

Changed in this revision

MotorShield.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MotorShield.lib	Wed Aug 26 00:24:56 2020 +0000
+++ b/MotorShield.lib	Wed Aug 26 02:44:03 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/elijahsj/code/MotorShield/#30503be9a375
+https://os.mbed.com/users/elijahsj/code/MotorShield/#2f46953e7c8b
--- a/main.cpp	Wed Aug 26 00:24:56 2020 +0000
+++ b/main.cpp	Wed Aug 26 02:44:03 2020 +0000
@@ -23,35 +23,14 @@
 AnalogIn currentC(PF_13); //MOTOR C CURRENT SENSOR 
 AnalogIn currentD(PA_4);  //MOTOR D CURRENT SENSOR 
 
-//MotorShield motorA(PE_5, PE_6);   //MOTOR A PWM 
-//MotorShield motorB(PB_14, PB_15); //MOTOR B PWM 
-//MotorShield motorC(PA_6, PF_9);   //MOTOR C PWM 
-//MotorShield motorD(PF_6, PF_7);   //MOTOR D PWM
+MotorShield motors(1000); //initialize the motor shield with a period of 1000 ticks or xxx kHZ
 
 int main (void)
 {
-    initHardware();   // Setup PWM
-    wait_us(100);
-    
-    TIM12->CCR2 = 100;
-    TIM12->CCR1 = 200;
-    TIM13->CCR1 = 200;
-    TIM14->CCR1 = 200;
-    TIM15->CCR1 = 200;
-    TIM15->CCR2 = 200;
-    TIM16->CCR1 = 200;
-    TIM17->CCR1 = 200; 
-    
-    while(1){
-    }
-    /*
     // Link the terminal with our server and start it up
     server.attachTerminal(pc);
     server.init();
 
-    // PWM period should nominally be a multiple of our control loop
-    motorPWM.period_us(500);
-
     // Continually get input from MATLAB and run experiments
     float input_params[NUM_INPUTS];
     pc.printf("%f",input_params[0]);
@@ -68,17 +47,16 @@
             encoderB.reset();
             encoderC.reset();
             encoderD.reset();
-            motorFwd = 1;
-            motorRev = 0;
-            motorPWM.write(0);
+
+            motors.motorAWrite(0, 0); //turn motor A off
 
             // Run experiment
             while( t.read() < 2 ) {
                 // Perform control loop logic
                 if (t.read() < 1)
-                    motorPWM.write(v1);
+                    motors.motorAWrite(v1, 0); //run motor A at "v1" duty cycle and in the forward direction 
                 else
-                    motorPWM.write(v2);
+                    motors.motorAWrite(v2, 0); //run motor A at "v2" duty cycle and in the forward direction 
 
                 // Form output to send to MATLAB
                 float output_data[NUM_OUTPUTS];
@@ -92,9 +70,9 @@
             }
             // Cleanup after experiment
             server.setExperimentComplete();
-            motorPWM.write(0);
+            motors.motorAWrite(0, 0); //turn motor A off
         } // end if
     } // end while
-    */
+    
 } // end main