![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
no optics
Dependencies: Stepper mbed PinDetect
Diff: main.cpp
- Revision:
- 2:65c5232b9465
- Parent:
- 0:88834eed3de0
- Child:
- 3:af3195b3330d
diff -r 4bda04eecf66 -r 65c5232b9465 main.cpp --- a/main.cpp Sun Mar 18 23:51:04 2018 +0000 +++ b/main.cpp Wed Sep 04 18:03:54 2019 +0000 @@ -1,283 +1,52 @@ -/*#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); +#include "string" +DigitalIn optic(D5); +Stepper mot(D3,D2); //(PUL+,DIR+) +DigitalOut en(D4); 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() +int main() { - 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(); +optic.mode(PullDown); +wait(0.1); +int steps = 0; +int slot = 0; +en = 1; // stepper motor off +wait(1); +mot.setSpeed(400); //stepper speed +mot.setPositionZero(); //set origin for stepper steps +while(1) + { + pc.printf("\n\n\nEnter desired position: "); + pc.scanf("%d",&slot); + en = 0; //turns on stepper driver + mot.goesTo(slot*100); // move to absolute 100 + while(!mot.stopped()); // while motor is turning...do line below + steps = mot.getPosition(); //read in absolute step postition + while(optic == 0) + { + wait(1); + mot.goesTo(steps+25); //go to absolute step position + while(!mot.stopped()); + steps = mot.getPosition(); + pc.printf("\nNot in Position", steps); } - 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 "); - } + pc.printf("\nIn Position"); + en = 1; //disable the motor and driver + //if (tickcount<steps) + //{ + //mot.goesTo(steps+25); + //while(!mot.stopped()); + //steps = mot.getPosition(); + //pc.printf("\nNot in Position", steps); + //} + //if (tickcount>steps) + //{ + //mot.goesTo(steps-25); + //while(!mot.stopped()); + //steps = mot.getPosition(); + //pc.printf("\nNot in Position", steps); + //} } } -*/ \ No newline at end of file