2.74 Nucleo Code

Dependencies:   ExperimentServer QEI_pmw MotorShield

Dependents:   Position_ctrl

Revision:
5:1ab9b2527794
Parent:
4:7a1b35f081bb
Child:
6:1faceb53dabe
diff -r 7a1b35f081bb -r 1ab9b2527794 main.cpp
--- a/main.cpp	Fri Aug 21 16:59:39 2020 +0000
+++ b/main.cpp	Fri Aug 21 22:13:19 2020 +0000
@@ -9,12 +9,16 @@
 
 Serial pc(USBTX, USBRX);    // USB Serial Terminal
 ExperimentServer server;    // Object that lets us communicate with MATLAB
+Timer t;                    // Timer to measure elapsed time of experiment
+
+QEI encoderA(PE_9,PE_11, NC, 1200, QEI::X4_ENCODING);  // MOTOR A ENCODER (no index, 1200 counts/rev, Quadrature encoding)
+QEI encoderB(PA_5, PB_3, NC, 1200, QEI::X4_ENCODING);  // MOTOR B ENCODER (no index, 1200 counts/rev, Quadrature encoding)
+QEI encoderC(PC_6, PC_7, NC, 1200, QEI::X4_ENCODING);  // MOTOR C ENCODER (no index, 1200 counts/rev, Quadrature encoding)
+QEI encoderD(PD_12, PD_13, NC, 1200, QEI::X4_ENCODING);// MOTOR D ENCODER (no index, 1200 counts/rev, Quadrature encoding)
+
 PwmOut motorPWM(D5);        // Motor PWM output
 DigitalOut motorFwd(D6);    // Motor forward enable
 DigitalOut motorRev(D7);    // Motor backward enable
-Timer t;                    // Timer to measure elapsed time of experiment
-
-QEI encoder(D3,D4, NC, 1200, QEI::X4_ENCODING);  // Pins D3, D4, no index, 1200 counts/rev, Quadrature encoding
 
 int main (void)
 {
@@ -27,7 +31,8 @@
 
     // Continually get input from MATLAB and run experiments
     float input_params[NUM_INPUTS];
-
+    pc.printf("%f",input_params[0]);
+    
     while(1) {
         if (server.getParams(input_params,NUM_INPUTS)) {
             float v1   = input_params[0]; // Voltage for first second
@@ -36,7 +41,10 @@
             // Setup experiment
             t.reset();
             t.start();
-            encoder.reset();
+            encoderA.reset();
+            encoderB.reset();
+            encoderC.reset();
+            encoderD.reset();
             motorFwd = 1;
             motorRev = 0;
             motorPWM.write(0);
@@ -52,8 +60,8 @@
                 // Form output to send to MATLAB
                 float output_data[NUM_OUTPUTS];
                 output_data[0] = t.read();
-                output_data[1] = encoder.getPulses();
-                output_data[2] = encoder.getVelocity();
+                output_data[1] = encoderA.getPulses();
+                output_data[2] = encoderA.getVelocity();
 
                 // Send data to MATLAB
                 server.sendData(output_data,NUM_OUTPUTS);