Fork of expo day code. Fires on every detected particle to calibrate delay time to solenoid firing, and solenoid on time.

Dependencies:   Regrind RioRandHBridge Solenoid mbed

Fork of ECE4012-PHD by Mitchell Pang

Files at this revision

API Documentation at this revision

Comitter:
mitchpang
Date:
Wed Dec 09 19:55:27 2015 +0000
Parent:
4:87e4b4299f6b
Commit message:
Fork of expo day code. Changed logic to actuate on all regrinds to test accuracy of system and find calibration of delay to solenoid firing and how long it fires for.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 87e4b4299f6b -r be4b501b9373 main.cpp
--- a/main.cpp	Thu Dec 03 06:37:32 2015 +0000
+++ b/main.cpp	Wed Dec 09 19:55:27 2015 +0000
@@ -5,15 +5,15 @@
 
 #define OG1_TO_OG2_DIST 1
 #define OG1_TO_OG3_DIST 2
-#define SOLENOID_ON_DELAY 0.5
+#define SOLENOID_ON_DELAY 0.25
 #define SOLENOID_OFF_DELAY 0.0
 #define LED_ON_DELAY 0.5
 #define LED_OFF_DELAY 0.0
 #define REGRIND_ARRAY_SIZE 1
-#define THRESHOLD 0.015
+#define THRESHOLD 0.02
 #define RETURN_THRESHOLD 0.01
 
-DigitalOut led1(LED1,0); //Used as 1pps out indicator
+Solenoid led1(LED1, LED_ON_DELAY, LED_OFF_DELAY); //Used as 1pps out indicator
 Solenoid led2(LED2, LED_ON_DELAY, LED_OFF_DELAY);
 Solenoid led3(LED3, LED_ON_DELAY, LED_OFF_DELAY);
 Solenoid led4(LED4, LED_ON_DELAY, LED_OFF_DELAY);
@@ -25,7 +25,7 @@
 AnalogIn topMotorAdjuster(p19);
 DigitalOut bottomMotorAdjuster(p16,0);
 DigitalOut unused1(p17,0);
-AnalogIn og1(p15);
+AnalogIn og1(p16);
 AnalogIn og2(p20);
 DigitalOut og3(p18,0);
 InterruptIn divertParticle(p5);
@@ -69,6 +69,7 @@
 */
 void divert(){
     regrindArray[og2Ndx].divert = 1;
+    led3 = 1;
     }
 void reverseMotor1(){
     augerMotors.Dir1 = !augerMotors.Dir1;
@@ -129,13 +130,13 @@
         og2_adc = og2.read()*3.3;
         //og3_adc = og3.read()*3.3;
         //wait(0.01);
-        //pc.printf("og1: %f og2: %f og3: %f\n\r",og1_adc, og2_adc, og3_adc);
-        
+        //pc.printf("og1: %f og2: %f \n\r",og1_adc, og2_adc);
+
         if((og1_calibration - og1_adc > THRESHOLD) && (og1Oneshot != 1)){ //Something passed through og1
             og1Oneshot = 1;
             divertParticle.rise(&divert);
             //pc.printf("Regrind seen at OG 1 : %fV\n\r", og1_adc);
-            led2 = 1;
+            led1 = 1;
             
             //Create Regrind
             regrindArray[og1Ndx%REGRIND_ARRAY_SIZE] = Regrind(totalT.read_us(), 1, 0, 0, 0, 0);
@@ -151,13 +152,18 @@
             og2Oneshot = 1;
             divertParticle.rise(NULL);
             regrindArray[og2Ndx%REGRIND_ARRAY_SIZE].setVelocity(OG1_TO_OG2_DIST);
-            led3 = 1;
+            led2 = 1;
             if(regrindArray[og2Ndx].divert == 1){
+            wait_ms(90);
             solenoid = 1; //actuate solenoid if red
+            led4 = 1;
             }
             else {
-            solenoid = 0; //Dont actuate if not red.
+            //wait_ms(90);
+            solenoid = 1; //Dont actuate if not red.
+            led4 = 1;
             }
+            regrindArray[og2Ndx].divert = 0; //reset divert flag
         }//if(og2..)
         else if(og2_calibration - og2_adc < RETURN_THRESHOLD){ //Regrind has passed ok to reset og
             og2Oneshot = 0;
@@ -177,6 +183,7 @@
             
         }//else if(og3 ...)
         */
+        /*
         //Check on 1pps clock
         if((totalT.read_us() % 2000000) < 1000000){
             led1 = 1;
@@ -185,7 +192,7 @@
         else {//timer is in off cycle
             led1 = 0;
             onePPS_out = 0;
-        }
+        }*/
         
         //Check if data writing flag is set - if so, write to SD card