first

Dependencies:   ExperimentServer QEI_pmw MotorShield

Revision:
13:3a1f4e09789b
Parent:
12:84a6dcb60422
Child:
14:c0aa529968a2
diff -r 84a6dcb60422 -r 3a1f4e09789b main.cpp
--- a/main.cpp	Wed Aug 26 14:37:19 2020 +0000
+++ b/main.cpp	Wed Aug 26 19:35:05 2020 +0000
@@ -4,9 +4,11 @@
 #include "ExperimentServer.h"
 #include "QEI.h"
 #include "MotorShield.h" 
+#include "HardwareSetup.h"
 
 #define NUM_INPUTS 2
-#define NUM_OUTPUTS 3
+#define NUM_OUTPUTS 4
+
 
 Serial pc(USBTX, USBRX);    // USB Serial Terminal
 ExperimentServer server;    // Object that lets us communicate with MATLAB
@@ -17,11 +19,6 @@
 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)
 
-AnalogIn currentA(PF_12); //MOTOR A CURRENT SENSOR 
-AnalogIn currentB(PF_11); //MOTOR B CURRENT SENSOR 
-AnalogIn currentC(PF_13); //MOTOR C CURRENT SENSOR 
-AnalogIn currentD(PA_4);  //MOTOR D CURRENT SENSOR 
-
 MotorShield motorShield(12000); //initialize the motor shield with a period of 12000 ticks or ~20kHZ
 
 int main (void)
@@ -29,7 +26,7 @@
     // Link the terminal with our server and start it up
     server.attachTerminal(pc);
     server.init();
-
+    
     // Continually get input from MATLAB and run experiments
     float input_params[NUM_INPUTS];
     pc.printf("%f",input_params[0]);
@@ -59,13 +56,16 @@
 
                 // Form output to send to MATLAB
                 float output_data[NUM_OUTPUTS];
+                
                 output_data[0] = t.read();
-                output_data[1] = encoderA.getPulses();
+                output_data[1] = encoderA.getPulses(); 
                 output_data[2] = encoderA.getVelocity();
-
+                output_data[3] = readADC1(0);
+                
                 // Send data to MATLAB
                 server.sendData(output_data,NUM_OUTPUTS);
-                wait(.001);
+                
+                wait(.001); //run control loop at 1kHz
             }
             // Cleanup after experiment
             server.setExperimentComplete();