Team Plastics Separation / Mbed 2 deprecated ECE4012-PHD_expo_code

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:41:59 2015 +0000
Parent:
4:87e4b4299f6b
Commit message:
Commit of code run on Senior Design Capstone Expo day

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Dec 03 06:37:32 2015 +0000
+++ b/main.cpp	Wed Dec 09 19:41:59 2015 +0000
@@ -5,18 +5,19 @@
 
 #define OG1_TO_OG2_DIST 1
 #define OG1_TO_OG3_DIST 2
-#define SOLENOID_ON_DELAY 0.5
+#define SOLENOID_ON_DELAY 1
 #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 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);
+//Solenoid led4(LED4, LED_ON_DELAY, LED_OFF_DELAY);
+DigitalOut led4(LED4);
 DigitalOut onePPS_out(p29);
 Solenoid solenoid(p30, SOLENOID_ON_DELAY, SOLENOID_OFF_DELAY); //Solenoid(PinName pin, float ondelay, float offdelay)
 RioRandHBridge augerMotors(p21, p25, p22, p23); //RioRandHBridge( PinName pinPwm1, PinName pinDir1, PinName pinPwm2, PinName pinDir2);
@@ -25,13 +26,13 @@
 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);
+//InterruptIn divertParticle(p5);
 Timer totalT;
 DigitalOut startColor(p6);
-//DigitalIn redColor(p5);
+DigitalIn redColor(p5);
 DigitalIn blueColor(p7);
 DigitalIn greenColor(p8);
 //Ticker 1pps;
@@ -59,6 +60,7 @@
 float og1_calibration = 0;
 float og2_calibration = 0;
 float og3_calibration = 0;
+int nextRegrindActuate = 0;
 
 Regrind regrindArray[REGRIND_ARRAY_SIZE];
 /*
@@ -111,7 +113,7 @@
     printf("og2_calibration value: %f\n\r",og2_calibration);
     wait(3);
     
-    divertParticle.rise(&divert);
+    //divertParticle.rise(&divert);
     
     while(1) {
         /*
@@ -125,11 +127,12 @@
             }
             */
         //Sample ADCs
-        og1_adc = og1.read()*3.3;
+        //og1_adc = og1.read()*3.3;
         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;
@@ -146,23 +149,32 @@
             og1Oneshot = 0;
             
         }//else if(og1 ...)
-        
+        */
+        led4 = redColor;
+        if(redColor == 1){
+            nextRegrindActuate = 1;
+            }
         if((og2_calibration - og2_adc > THRESHOLD) && (og2Oneshot != 1)){
             og2Oneshot = 1;
-            divertParticle.rise(NULL);
-            regrindArray[og2Ndx%REGRIND_ARRAY_SIZE].setVelocity(OG1_TO_OG2_DIST);
+            //divertParticle.rise(NULL);
+            //regrindArray[og2Ndx%REGRIND_ARRAY_SIZE].setVelocity(OG1_TO_OG2_DIST);
             led3 = 1;
-            if(regrindArray[og2Ndx].divert == 1){
+            if(nextRegrindActuate == 1){
+            wait_ms(1);
             solenoid = 1; //actuate solenoid if red
+            led2 = 1;
+            nextRegrindActuate = 0;
             }
             else {
             solenoid = 0; //Dont actuate if not red.
             }
         }//if(og2..)
         else if(og2_calibration - og2_adc < RETURN_THRESHOLD){ //Regrind has passed ok to reset og
+            //nextRegrindActuate = 0;
             og2Oneshot = 0;
             
         }//else if(og2 ...)
+        nextRegrindActuate = 0;
         /*
         if((og3_adc == 0) && (og3Oneshot != 1)){
             og3Oneshot = 1;