update

Dependencies:   Stepper mbed SDFileSystem Ultrasonic PinDetect millis

Revision:
0:88834eed3de0
Child:
2:e8f8095464cf
diff -r 000000000000 -r 88834eed3de0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 18 02:40:25 2018 +0000
@@ -0,0 +1,283 @@
+/*#include "mbed.h"
+#include <vector>
+//--------Brushed Motor -------------------
+DigitalOut in3(PTC17); 
+DigitalOut in4(PTC16);
+//---------Stepper Motor ------------------
+Stepper mot(PTA1,D2);//d2 and d3
+DigitalOut en(D4); 
+Serial pc(USBTX, USBRX); 
+ 
+//--Internal pullup resistors for Bumper Switches---
+DigitalIn bswitch(D1);
+DigitalIn tswitch(D0);
+int main() {
+    vector<int> time;
+    vector<int> plates;
+    int n,t,h,m,s = 0; 
+    int tests = 0;
+    PULp.period(0.0006f); 
+    ENp = 1;
+    DIRp = 0;
+    PULp.write(0.5f); 
+    in3=0;
+    in4=0;
+    pc.printf("\nCommands  ");
+    pc.scanf("%d",&tests); 
+    
+    for (int i = 1; i<=tests;i++){
+        pc.printf("\nEnter the Number of Plates for test %d: ",i);
+        pc.scanf("%d",&n);
+        pc.printf("\nEnter hours and minutes to test these plates\n\nHours: ");
+        pc.scanf("%d",&h);
+        pc.printf("Minutes: ");
+        pc.scanf("%d",&m);
+        pc.printf("Seconds: ");
+        pc.scanf("%d",&s);
+        t=(h*3600)+(m*60)+s;
+        time.push_back(t);
+        plates.push_back(n);
+    }
+    pc.printf("\nTesting in Progress...");
+   for (unsigned y=0; y<time.size(); y++){
+       
+        //--------Turn Stepper on for a certain amount of time based on the number of plates----
+        in3=0;   // stop actuator
+        in4=0;   // stop actuator
+        ENp = 0; 
+        DIRp = 0;
+        wait(1.9*(plates.at(y)-1)); 
+        ENp = 1;
+        wait(0.5);
+        //-------Move Plates Under X ray Beam---------------------------------------------------
+        in3=0;
+        in4=1;
+        wait(14); //reaches end after 10 seconds
+        in3=0;   // stop actuator
+        in4=0;   // stop actuator
+        //-----Test the Plate for specified time ----------------------------------------------
+        wait(time.at(y)); //Leave plates in beam path for the user inputted amount of time
+        //-----Retract plates to original position---------------------------------------------
+        in3=1;
+        in4=0;
+        wait(14); 
+        in3=0; 
+        in4=0; 
+        wait(0.5);
+        //--------Return Stepper to base height with one plate selected------------------------
+        ENp = 0; 
+        DIRp = 1; 
+        wait(2*(plates.at(y)-1));
+        ENp = 1; 
+        //-------------------------------------------------------------------------------------
+        pc.printf("\n\nTest number %d complete", y+1);
+        pc.printf("\nNumber of Plates: %d", plates.at(y));
+        pc.printf("\nLength of Test: %d seconds", time.at(y));
+        }
+        pc.printf("\n\nAll testing complete");
+    }
+*/
+
+/*#include "mbed.h" 
+
+Serial pc(USBTX, USBRX);
+ 
+int main() {
+    char c;
+    char buffer[128];
+    pc.gets(buffer, 4);
+    pc.printf("I got '%s'\n", buffer);  
+    if(strcmp(buffer,"on")==0) {
+        printf("success");
+        }   
+    else{
+        printf("fail");
+        }   
+}
+*/
+#include "mbed.h"
+#include "Stepper.h"
+DigitalIn homeSwitch(D8);
+DigitalIn endSwitch(D1);
+DigitalIn bottomSwitch(D0);
+DigitalIn topSwitch(D9);
+Stepper mot(PTA1,D2);
+DigitalOut en(D4); 
+DigitalOut in1(D11); 
+DigitalOut in2(D10);
+Serial pc(USBTX, USBRX);
+
+void positionStatus()
+{
+     int plateposition;  //plate position -> 1 is home, 2 is traveling, 3 is under beam path 
+     if(homeSwitch==0 && endSwitch==1)
+     {
+      plateposition = 1;
+      pc.printf("\nPlate position is home %d",plateposition);
+     } 
+     else if (homeSwitch==1 && endSwitch==1)
+     {
+      plateposition = 2;
+      pc.printf("\nPlates are currently moving %d",plateposition); 
+     }
+     else if(homeSwitch==1 && endSwitch==0)
+     {
+     plateposition = 3;
+     pc.printf("\nPlates are under beam path %d",plateposition); 
+     }
+     else
+     {
+      pc.printf("\nError, cannot locate plate position"); 
+     }
+}
+
+void retractPMMA()
+{
+    in1=1;
+    in2=0;
+    wait(14);
+    in1=0;
+    in2=0;
+    positionStatus();
+}
+
+void sendPMMA()                                                   //Command: Send plates
+ {                                                                //Returns: plates arrived(),plates didn't arrive() 
+    wait(2);
+    in1=1;
+    in2=0;
+    wait(14);
+    in1=0;
+    in2=0;
+    positionStatus();
+}
+
+void autoCalibrate()     //if machine is plugged in when the plate selector isn't at the origin...
+{   
+    en = 0;                      //...it automatically lowers it to the origin position 
+    mot.setSpeed(800);
+    mot.rotate(0);                 
+    while(bottomSwitch);        //While bottom switch is unpressed   
+    mot.stop();                 //Stop rotation when switch is pressed (pressed = logical level low)           
+    en=1;                       //Disable driver
+    mot.setPositionZero();      //Set absolute origin for plate selector at switch hit
+}
+
+void internalpullups()
+{
+    bottomSwitch.mode (PullUp);
+    topSwitch.mode (PullUp);
+    homeSwitch.mode (PullUp);
+    endSwitch.mode (PullUp);
+    wait (.01);
+}
+
+void numberofPlates()       // Command: Number of PMMA to send (plates)
+                            // Returns: Actual number of plates selected (selectedplates), selectionerror (1 for command error, 0 for correct command) 
+{    
+     int stepheight,plates,selectionerror;
+     double selectedplates;                        
+     pc.printf("\nEnter the Number of Plates to send ");
+     pc.scanf("%d",&plates);
+     if (plates <= 0)
+     { 
+     pc.printf("\nNot a valid number, must be 1 to 16");
+     selectionerror = 1;
+     }
+     else if (plates >= 17)
+     { 
+     pc.printf("\nNot a valid number, must be 1 to 16");
+     selectionerror = 1;
+     }
+     else
+     {
+     selectionerror = 0;
+     pc.printf("\nCommand Valid\n"); 
+     en = 0;
+     mot.goesTo(plates*1620);
+     while(!mot.stopped());
+     stepheight = mot.getPosition();        
+     selectedplates = stepheight/1620;                 
+     pc.printf("\n Steps taken: %d ",selectedplates);  
+     mot.stop();
+     en = 1;   
+    }
+}      
+void selectionStatus()
+{
+   int stepheight;
+   double selectedplates;
+   stepheight = mot.getPosition();        
+   selectedplates = stepheight/1620;                 
+   pc.printf("\n Number of plates currently selected: %d ",selectedplates);
+     
+}                             
+
+ 
+int main()
+{  
+    char command[256] = { 0 };
+    internalpullups();
+    wait (.01);
+    autoCalibrate(); //...it automatically lowers it to the origin position for initial power up
+                     
+    while(1)
+    {
+      pc.printf("\nEnter Command: \n send \n retract \n position (get status) \n selection (get status)" );
+      pc.scanf("\n%s", &command);
+        if (strcmp (command, "send") == 0)
+        {  
+            pc.printf ("\nCommand Recieved: Send");   //confirmation of recieved command
+            numberofPlates();                       //select number of plates to send
+            sendPMMA();                  
+        }
+        if (strcmp (command, "retract") == 0)
+        {     
+            pc.printf ("\nCommand Recieved: retract");
+            retractPMMA();   
+        } 
+        if (strcmp (command, "position") == 0)
+        {     
+            pc.printf ("\nCommand Recieved: position");
+            positionStatus();  
+        }
+        if (strcmp (command, "selection") == 0)
+        {
+            pc.printf ("\nCommand Recieved: selection");
+            selectionStatus();
+        }
+    }  
+}    
+
+
+/* int main () 
+{  
+    int steps, plates;
+    bswitch.mode (PullUp); 
+    wait (.01);
+    mot.setSpeed (600);
+    mot.rotate (0);         //if machine is plugged in when the plate selector isn't at the origin...
+    
+    while (bswitch);        //...it automatically lowers it to the origin positio
+    mot.stop ();            //Stop rotation when switch is pressed (pressed = logical level low)
+    en = 1;                 //Disable driver
+    mot.setPositionZero (); //Set absolute origin for plate selector at switch hit
+    char c[256] = { 0 };
+    
+    while (1)
+    {
+        pc.printf("Choose a command:\nPMMA 1");   
+        pc.scanf ("%s", &c);   
+        
+        if (strcmp (c, "PMMA1") == 0)
+        {  
+            pc.printf ("\n match ");
+        }
+      
+        if (strcmp (c, "no") == 0)
+        {     
+            pc.printf ("\n not match ");
+        }   
+    }
+}
+*/
\ No newline at end of file