Team Plastics Separation / Mbed 2 deprecated ECE4012-PHD_non_blocking

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:51:36 2015 +0000
Parent:
4:87e4b4299f6b
Commit message:
Non blocking code for turning on solenoid. Uses a fork of the solenoid class from Jim Hamblen. Does not have data logging functionality. Current issues: On delay time may be too short. May need to increase to .25 sec.

Changed in this revision

Solenoid.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Solenoid.lib	Thu Dec 03 06:37:32 2015 +0000
+++ b/Solenoid.lib	Wed Dec 09 19:51:36 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/mitchpang/code/Solenoid/#bd163b4ce456
+https://developer.mbed.org/teams/Team-Plastics-Separation/code/Solenoid/#b87c9e1546c5
--- a/main.cpp	Thu Dec 03 06:37:32 2015 +0000
+++ b/main.cpp	Wed Dec 09 19:51:36 2015 +0000
@@ -5,27 +5,27 @@
 
 #define OG1_TO_OG2_DIST 1
 #define OG1_TO_OG3_DIST 2
-#define SOLENOID_ON_DELAY 0.5
-#define SOLENOID_OFF_DELAY 0.0
-#define LED_ON_DELAY 0.5
-#define LED_OFF_DELAY 0.0
+#define SOLENOID_ON_TIME 0.125
+#define SOLENOID_ON_DELAY 0.087
+#define LED_ON_TIME 0.5
+#define LED_ON_DELAY SOLENOID_ON_DELAY
 #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 led1(LED1, LED_ON_TIME, LED_ON_DELAY); //Used as 1pps out indicator
+Solenoid led2(LED2, LED_ON_TIME, LED_ON_DELAY);
+Solenoid led3(LED3, LED_ON_TIME, LED_ON_DELAY);
+Solenoid led4(LED4, LED_ON_TIME, LED_ON_DELAY);
 DigitalOut onePPS_out(p29);
-Solenoid solenoid(p30, SOLENOID_ON_DELAY, SOLENOID_OFF_DELAY); //Solenoid(PinName pin, float ondelay, float offdelay)
+Solenoid solenoid(p30, SOLENOID_ON_TIME, SOLENOID_ON_DELAY); //Solenoid (PinName pin, float onTime=0.25, float onDelay=0.095);
 RioRandHBridge augerMotors(p21, p25, p22, p23); //RioRandHBridge( PinName pinPwm1, PinName pinDir1, PinName pinPwm2, PinName pinDir2);
 DigitalIn reverseMotor1pb(p26);
 DigitalIn reverseMotor2pb(p24);
 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(95);
             solenoid = 1; //actuate solenoid if red
+            led4 = 1;
             }
             else {
-            solenoid = 0; //Dont actuate if not red.
+            //wait_ms(95);
+            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