2.74 Experiment Example Code (updated)

Dependencies:   ExperimentServer MotorShield QEI_pmw

Revision:
4:7a1b35f081bb
Parent:
1:95a7fddd25a9
Child:
5:1ab9b2527794
--- a/main.cpp	Fri Jul 19 16:57:28 2019 +0000
+++ b/main.cpp	Fri Aug 21 16:59:39 2020 +0000
@@ -14,24 +14,25 @@
 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
+QEI encoder(D3,D4, NC, 1200, QEI::X4_ENCODING);  // Pins D3, D4, no index, 1200 counts/rev, Quadrature encoding
 
-int main (void) {
+int main (void)
+{
     // 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];
-    
+
     while(1) {
         if (server.getParams(input_params,NUM_INPUTS)) {
             float v1   = input_params[0]; // Voltage for first second
             float v2   = input_params[1]; // Voltage for second second
-        
+
             // Setup experiment
             t.reset();
             t.start();
@@ -41,23 +42,23 @@
             motorPWM.write(0);
 
             // Run experiment
-            while( t.read() < 2 ) { 
+            while( t.read() < 2 ) {
                 // Perform control loop logic
-                if (t.read() < 1) 
+                if (t.read() < 1)
                     motorPWM.write(v1);
-                else 
+                else
                     motorPWM.write(v2);
-                    
-                // Form output to send to MATLAB    
+
+                // 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();
-             
+
                 // Send data to MATLAB
                 server.sendData(output_data,NUM_OUTPUTS);
-                wait(.001); 
-            }     
+                wait(.001);
+            }
             // Cleanup after experiment
             server.setExperimentComplete();
             motorPWM.write(0);