
2013 VCU Senior Design Expo Linear Rotary Motor Control Program. This is the actual program used by the team at the Expo.
Diff: main.cpp
- Revision:
- 4:29aafde2dcbc
- Parent:
- 3:1d681d86f1dd
diff -r 1d681d86f1dd -r 29aafde2dcbc main.cpp --- a/main.cpp Wed Apr 17 22:56:54 2013 +0000 +++ b/main.cpp Thu Apr 25 13:13:54 2013 +0000 @@ -91,7 +91,7 @@ void rotate_all_ccw(int set, float speed); void rotary_speed(); void fast_rotary_cw(); - +void small_rotary_speed(); /////////////////////////////////////////////////////////////////////////////// //////////////////////////////////MAIN///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -188,10 +188,10 @@ //Get valid user_input// scroll_up(30); xbee.printf("\r\n\n****Main Menu****"); - xbee.printf("\r\nFor Calibration press 1 and <Enter>."); - xbee.printf("\r\nTo enter a desired location press 2 and <Enter>."); - xbee.printf("\r\nFor display mode press 3 and <Enter>."); - scroll_up(24); + xbee.printf("\r\nFor Calibration press 1 and \r\n<Enter>."); + xbee.printf("\r\nTo enter a desired location press 2 and \r\n<Enter>."); + xbee.printf("\r\nFor display mode press 3 and\r\n<Enter>."); + scroll_up(22); user_instruction = error_check(); break; }//End of switch @@ -846,8 +846,8 @@ //LINEAR AUTO PROGRAM// for(int j=0; j<linear_auto; j++) { for(int i=0; i<12; i++) { - move_all_left(abs(six-i)); - move_all_right(abs(six-i)); + move_all_left(abs(five-i)); + move_all_right(abs(five-i)); }//End of for// }//End of for// option = -1; @@ -857,8 +857,8 @@ //LINEAR OSCILLATION// for(int j=0; j<linear_oscill; j++) { for(int i=0; i<12; i++) { - move_all_leftBobby(abs(six-i)); - move_all_rightBobby(abs(six-i)); + move_all_leftBobby(abs(five-i)); + move_all_rightBobby(abs(five-i)); }//End of for// }//End of for// option = -1; @@ -915,8 +915,8 @@ case 5: //ROTARY AUTO PROGRAM// for(int i=0; i<rotary_auto; i++) { + rotate_all_ccw(six, rot_fast); rotate_all_cw(six, rot_fast); - rotate_all_ccw(six, rot_fast); }//End of for// option = -1; break; @@ -924,6 +924,19 @@ fast_rotary_cw(); option = -1; break; + case 7: + //SMALL FORCER ROTARY AUTO PROGRAM// + rotary0 = 1; + rotary1 = 1; + rotary2 = 1; + rotary3 = 1; + rotary4 = 1; + rotary5 = 1; + for(int i=0; i<high_speed; i++) { + small_rotary_speed(); + }//End of for// + option = -1; + break; case 9: //SET UP CASE// xbee.printf("\r\n****Display Mode Set UP****"); @@ -939,31 +952,31 @@ case 1: //Edit LINEAR AUTO PROGRAM// xbee.printf("\r\nHow many times would you like to run Linear Auto Program?"); - scroll_up(29); + scroll_up(27); linear_auto = error_check(); break; case 2: //Edit LINEAR OSCILLATION// xbee.printf("\r\nHow many times would you like to run Linear Oscillation?"); - scroll_up(29); + scroll_up(27); linear_oscill = error_check(); break; case 3: //Edit COMBINED OPERATION// xbee.printf("\r\nHow many times would you like to run Combined Operation?"); - scroll_up(29); + scroll_up(27); combined = error_check(); break; case 4: //Edit HIGH SPEED ROTARY// xbee.printf("\r\nHow many times would you like to run High Speed Rotary?"); - scroll_up(29); + scroll_up(27); high_speed = error_check(); break; case 5: //Edit ROTARY AUTO PROGRAM// xbee.printf("\r\nHow many times would you like to run Rotary Auto Program?"); - scroll_up(29); + scroll_up(27); rotary_auto = error_check(); break; }//End of switch(setup) @@ -978,15 +991,16 @@ option = -1; scroll_up(30); xbee.printf("\r\n\n****Display Mode****"); - xbee.printf("\r\nTo run LINEAR AUTO PROGRAM press 1 and <Enter>."); - xbee.printf("\r\nTo run LINEAR OSCILLATION press 2 and <Enter>."); - xbee.printf("\r\nTo run COMBINED OPERATION press 3 and <Enter>."); - xbee.printf("\r\nTo run HIGH SPEED ROTARY press 4 and <Enter>."); - xbee.printf("\r\nTo run ROTARY AUTO PROGRAM press 5 and <Enter>."); - xbee.printf("\r\nTo run SMALL FORCER SPEED RUN press 6 and <Enter>."); - xbee.printf("\r\nFor SET UP press 9 and <Enter>."); - xbee.printf("\r\nTo return to the previous menu press 0 and <Enter>."); - scroll_up(14); + xbee.printf("\r\nTo run LINEAR AUTO PROGRAM press 1 and \r\n<Enter>."); + xbee.printf("\r\nTo run LINEAR OSCILLATION press 2 and \r\n<Enter>."); + xbee.printf("\r\nTo run COMBINED OPERATION press 3 and \r\n<Enter>."); + xbee.printf("\r\nTo run HIGH SPEED ROTARY press 4 and \r\n<Enter>."); + xbee.printf("\r\nTo run ROTARY AUTO PROGRAM press 5 and \r\n<Enter>."); + xbee.printf("\r\nTo run SMALL FORCER SPEED RUN press 6 and \r\n<Enter>."); + //xbee.printf("\r\nTo run SMALL FORCER AUTO ROTARY press 7 and \r\n<Enter>."); + xbee.printf("\r\nFor SET UP press 9 and \r\n<Enter>."); + xbee.printf("\r\nTo return to the previous menu press 0 and \r\n<Enter>."); + scroll_up(12); option = error_check(); break; }//End of switch// @@ -1047,9 +1061,9 @@ linear0 =! linear0; //Coil 1 wait(fast); linear0 =! linear0; - linear1 =! linear1; //Coil 2 - wait(fast); - linear1 =! linear1; + //linear1 =! linear1; //Coil 2 + //wait(fast); + //linear1 =! linear1; return; }//End of Funciton @@ -1107,6 +1121,10 @@ linear4 =! linear4; //Coil 5 wait(fast); linear4 =! linear4; + //linear3 =! linear3; //Coil 4 + //wait(fast); + //linear3 =! linear3; + return; }//End of Funciton @@ -1252,6 +1270,12 @@ /////////////////////////////////////////////////////////////////////////////// void rotate_all_cw(int set, float speed) { +rotary0 = 1; +rotary1 = 1; +rotary2 = 1; +rotary3 = 1; +rotary4 = 1; +rotary5 = 1; for(int i=0; i<set; i++) { rotary0 = !rotary0; wait(speed); @@ -1274,6 +1298,12 @@ //Function rotate the forcer void rotate_all_ccw(int set, float speed) { +rotary0 = 1; +rotary1 = 1; +rotary2 = 1; +rotary3 = 1; +rotary4 = 1; +rotary5 = 1; for(int i=0; i<set; i++) { rotary5 = !rotary5; wait(speed); @@ -1343,4 +1373,50 @@ //Special function for little forcer void fast_rotary_cw(){ rotate_all_cw(400, 0.01); -}//End of Function// \ No newline at end of file +}//End of Function// + +/////////////////////////////////////////////////////////////////////////////// +////////////////////////////////small_rotary_speed();////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +//small_rotary_speed() rotates the small forcer faster and faster// +void small_rotary_speed() +{ + float time = 0.080; + float step = 0.005; + int a = 0; + int cycle = 32; + int change = 0; + int turns = 8; + int maxint = 0.010; + + while(a<2) { + for(int i=cycle; i>0; i--) { + if(time == maxint) { + turns = 400; + } else if(time != maxint) { + turns = 8; + } + if(change == 0) { + if(i > cycle/2) { + rotate_all_cw(turns,time); + time = time - step; + }//End of if + if(i < ((cycle/2) + 1 ) && i > 0) { + rotate_all_cw(turns,time); + time = time + step; + }//End of if + } else if(change==1) { + if(i > cycle/2) { + rotate_all_ccw(turns,time); + time = time - step; + }//End of if + if(i < ((cycle/2) + 1 ) && i > 0) { + rotate_all_ccw(turns,time); + time = time + step; + }//End of if + }//End of else if// + }//End of for// + change = !change; + a++; + }//End of while +}//End of function \ No newline at end of file