Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- / component orient;
- //1/3/2014//
- /// inputs ////
- //pin in bit mot_orient_on;// //on command from emc
- pin in bit mot_spl_on; //on command from emc
- pin in bit cl_spnl_fault;
- pin in bit timer_off; // run pin of timer for spindle shift
- pin io bit orient_m119; // mcode fo requesting spindle orient
- pin io bit orient_m118; // mcode fo requesting spindle free
- pin io bit low_gear_m141; // mcode fo requesting low gear
- pin io bit hi_gear_m142; // mcode fo requesting hi gear
- pin in bit ls3_low_gear; // ls indicating low gear
- pin in bit ls2_hi_gear; // ls indicating hi gear
- pin in bit ls1_plunger_in; // ls for indicating if the plunger is in or out
- pin in bit spl_fh_released; // flag indicating feed hold is relaesed
- pin in bit orient_fh_released; // flag indicating feed hold is relaesed
- pin in bit timer1_off; // timer for freeing spidle
- pin in bit tc_orient; // flag from tc program for spindle orient
- pin in bit spindle_on_for; // tied to motion.spindle-forward
- pin in bit spindle_on_rev; // tied to motion.spindle-reverse
- pin in bit timer2_off;
- pin in float spindle_rpm_cmd; //connected to motion.spindle-speed-out
- ///outputs///
- pin out bit sl_splplunger_out; //solinoid for locking the orient plunger
- pin out bit sl_splplunger_in; //solinoid for locking the orient plunger
- pin out bit cl_spnl_perm ; //drive enable
- pin out bit spl_run; // connected to hm2_5i23.0.pwmgen.04.enable
- pin out bit timer2_run; // timer done for wait for actual shift
- pin out bit sl_hi_gear; // solinoid for hi gear
- pin out bit sl_low_gear; // solinoid for low gear
- pin io bit in_hi_gear; // flag bit indicating trans is in hi gear
- pin io bit in_low_gear; // flag bit indicating trans is in low gear
- pin out bit spl_feed_hold; // pin out from spindle plc for applying feed hold
- pin out bit orient_feed_hold; //pin in from orient plc for applying feed hold
- pin out bit timer_run ; //run pin of timer for spindle shift
- pin out bit timer1_run; // timer for freeing spindle b4 run
- pin out bit tc_orient_comp; // flag to tc program for spindle orient complete
- pin in bit spl_enabled; // connected to pwmgen.04.enable
- pin out bit spl_fh_release; // flag indicating feed hold inrrd release
- pin out bit orient_fh_release; // flag indicating feed hold is relaesed
- pin out float spindle_speed; // hm2_5i23.0.pwmgen.04.value
- // parameters//
- param rw float spl_orient_speed ; // actual rpm for orient to br connected to pwmgen.04.value
- param rw s32 orient_cond ; // condition of this program
- param rw bit spin_oriented ; // preset stae of spindle orientation
- param rw s32 shift_trans; // condition of transmission
- param rw s32 orient_spdl;
- pin io bit spindle_index_enable; // index on encoder spindle tied to hm2_5i20.0.encoder.01.index enable
- param rw s32 spl_cond ;
- function _ nofp;
- license "gpl";
- ;;
- void orient_the_spindle(void);
- void shift_the_transmission(void);
- void free_the_spindle(void);
- void run_the_spindle(void);
- FUNCTION(_)
- {
- switch (orient_cond){
- case 0:
- if((orient_m119)==1&&(ls1_plunger_in)==1)
- {
- orient_m119=0;
- orient_cond = 59; //spindle is oriented
- }
- case 1:
- if(((orient_m119)==1||(tc_orient)==1)&&(ls1_plunger_in)==0)
- {
- orient_feed_hold = 1; // spindle needs orient
- tc_orient_comp=0;
- spl_run=0;
- orient_the_spindle();
- }
- case 2:
- if((orient_m118)==1&&(ls1_plunger_in)==1) // shift to spindle free
- {
- orient_feed_hold = 1;
- free_the_spindle();
- }
- case 3:
- if((orient_m118)==1&&(ls1_plunger_in)==0)
- {
- orient_m118=0;
- orient_cond = 61; // spindle is free
- }
- case 4:
- if((low_gear_m141)==1&&((ls3_low_gear)==1&&(ls2_hi_gear)==0))
- {
- low_gear_m141=0;
- orient_cond = 61; // spindle in low gear ,no shifting
- }
- case 5:
- if((low_gear_m141)==1&&((ls3_low_gear)==0&&(ls2_hi_gear)==1))
- {
- orient_feed_hold = 1;
- spl_run=0; // spindle in not low gear needs shift
- shift_the_transmission();
- }
- case 6:
- if((hi_gear_m142)==1&&((ls2_hi_gear)==1&&(ls3_low_gear)==0))
- {
- hi_gear_m142=0;
- orient_cond = 61; // spindle in hi gear no shift
- }
- case 7:
- if(((hi_gear_m142)==1&&(ls2_hi_gear)==0)&&(ls3_low_gear)==1)
- {
- orient_feed_hold = 1; // spindle not in hi gear need shift
- spl_run=0;
- shift_the_transmission();
- }
- case 8:
- if(((ls3_low_gear)==1&&(ls2_hi_gear)==1)||((ls3_low_gear)==0&&(ls2_hi_gear)==0))
- {
- orient_cond = 62; // transmission shift malfunction
- orient_feed_hold = 1;
- }
- break;
- case 59: // spindle oriented
- {
- orient_m119=0;
- spin_oriented = 1;
- orient_feed_hold = 0;
- orient_fh_release=1;
- tc_orient_comp=1;
- }
- break;
- case 60:
- {
- orient_feed_hold = 1;
- rtapi_print_msg (RTAPI_MSG_ERR, "Missed Orient");
- }
- break;
- case 61: // spindle is free or no errors
- {
- spl_feed_hold =0;
- orient_feed_hold = 0;
- orient_fh_release=1;
- orient_cond = 0;
- }
- break;
- case 62:
- {
- orient_feed_hold = 1;
- rtapi_print_msg (RTAPI_MSG_ERR, "Gear Shift Fault");
- }
- break;
- case 63:
- {
- spl_feed_hold =1;
- rtapi_print_msg (RTAPI_MSG_ERR, "Spindle fault");
- }
- break;
- case 64:
- if((mot_spl_on)==1)
- {
- run_the_spindle();
- }
- break;
- case 65:
- {
- spl_feed_hold =1;
- rtapi_print_msg (RTAPI_MSG_ERR, "Spindle not free for run");
- }
- break;
- }
- }
- void orient_the_spindle(void){
- switch (orient_spdl){
- case 0:
- if((ls1_plunger_in)==1)
- {
- spin_oriented=1;
- orient_cond = 0; // orient the spindle,if the plunger is in ,it is//
- }
- else
- {
- spl_run = 0;
- orient_spdl= 1;
- }
- break;
- case 1:
- if((ls1_plunger_in)==0&&(ls2_hi_gear)==1) // in hi gear
- {
- spl_orient_speed = 90;
- (spindle_speed)=(spl_orient_speed);
- cl_spnl_perm = 1;
- spl_run = 1;
- spindle_index_enable = 1;
- orient_m119=0;
- orient_spdl= 2;
- }
- else
- if((ls1_plunger_in)==0&&(ls3_low_gear)==1) //in low gear
- {
- spl_orient_speed = 270;
- (spindle_speed)=(spl_orient_speed);
- cl_spnl_perm = 1;
- spl_run = 1;
- spindle_index_enable = 1;
- orient_m119=0;
- orient_spdl = 2;
- }
- break;
- // wait for index marker
- case 2:
- if((spindle_index_enable)==0)
- {
- sl_splplunger_out =0;
- sl_splplunger_in = 1;
- spl_run = 0;
- cl_spnl_perm = 0;
- orient_spdl= 3;
- }
- break;
- case 3:
- if((spindle_index_enable)==0&&(ls1_plunger_in)==1)
- {
- spl_run = 0;
- (spindle_speed)=(spindle_rpm_cmd);
- orient_cond = 0;
- spin_oriented=1;
- orient_m119=0;
- }
- else
- {
- spin_oriented=0;
- orient_cond = 60; // missed oreint
- }
- break;
- }
- return;
- }
- /// shift transmission//
- void shift_the_transmission(void){
- switch (shift_trans){
- case 18:
- orient_the_spindle();
- {
- shift_trans = 19;
- }
- break;
- case 19:
- if((spin_oriented)==1&&(ls1_plunger_in)==1)
- {
- spl_feed_hold=1;
- shift_trans=20;
- }
- break;
- case 20:
- if((low_gear_m141)==1&&(spin_oriented)==1)
- {
- sl_hi_gear = 0;
- sl_low_gear = 1;
- timer_run = 1;
- shift_trans=21;
- }
- else
- if((hi_gear_m142)==1&&(spin_oriented)==1)
- {
- sl_low_gear = 0;
- sl_hi_gear = 1;
- timer_run = 1;
- shift_trans=22;
- }
- timer_run=0;
- break;
- case 21:
- if(((ls3_low_gear)==1&&(ls2_hi_gear)==0)&&(timer_off)==1)
- {
- in_low_gear=1;
- low_gear_m141=0;
- timer_run = 0;
- orient_cond = 61;
- }
- else
- if(((ls3_low_gear)!=1&&(ls2_hi_gear)!=0)&&(timer_off)==1)
- {
- in_low_gear=0;
- timer_run=0;
- low_gear_m141=0;
- orient_cond= 62;
- }
- break;
- case 22:
- if(((ls3_low_gear)==0&&(ls2_hi_gear)==1)&&(timer_off)==1)
- {
- in_hi_gear=1;
- timer_run=0;
- hi_gear_m142=0;
- orient_cond = 61;
- }
- else
- if(((ls3_low_gear)!=0&&(ls2_hi_gear)!=1)&&(timer_off)==1)
- {
- in_hi_gear= 0;
- timer_run=0;
- hi_gear_m142=0;
- orient_cond= 62;
- }
- break;
- default:
- orient_cond= 62;
- break;
- }
- return;
- }
- void free_the_spindle(void)
- {
- { // free spindle on m118
- sl_splplunger_in = 0;
- sl_splplunger_out =1;
- orient_m118=0;
- orient_cond = 61;
- }
- return;
- }
- ///run the spindle//
- void run_the_spindle(void)
- {
- switch (spl_cond){
- case 40:
- if(((spindle_rpm_cmd)<=800&&(in_low_gear)==1)&&((mot_spl_on)==1&&(low_gear_m141)==1))
- {
- spl_cond = 43;
- }
- else
- if(((spindle_rpm_cmd)>100&&(in_low_gear)==1)&&((mot_spl_on)==1&&(hi_gear_m142)==1))
- {
- spl_cond = 41;
- }
- else
- if(((spindle_rpm_cmd)>100&&(in_hi_gear)==1)&&((mot_spl_on)==1&&(hi_gear_m142)==1))
- {
- spl_cond = 43;
- }
- else
- if(((spindle_rpm_cmd)<=800&&(in_low_gear)==0)&&((mot_spl_on)==1&&(low_gear_m141)==1))
- {
- spl_cond = 41;
- }
- break;
- case 41:
- shift_the_transmission();
- {
- spl_cond = 42;
- }
- break;
- case 42:
- if((in_hi_gear)==1||(in_low_gear)==1)
- {
- spl_cond = 43;
- }
- else
- {
- orient_cond = 62 ;
- }
- break;
- case 43 :
- if((mot_spl_on)==1&&(cl_spnl_fault)==1)
- {
- cl_spnl_perm=0;
- spl_run = 0;
- rtapi_print_msg (RTAPI_MSG_ERR, "Spindle drive fault");
- orient_cond = 63;
- }
- else
- if(((spindle_on_for)==1||(spindle_on_rev)==1)&&(mot_spl_on)==1)
- {
- timer1_run = 1;
- free_the_spindle();
- spl_cond= 44;
- }
- break;
- case 44:
- if((timer1_off)==1&&(ls1_plunger_in)==0) // check for plunger out
- {
- spl_cond= 45;
- }
- else
- if((timer1_off)==1&&(ls1_plunger_in)==1)
- {
- orient_cond = 65;
- }
- break;
- case 45:
- if(((spindle_on_for)==1||(spindle_on_rev)==1)&&(mot_spl_on)==1) // run spindle
- {
- (spindle_speed)=(spindle_rpm_cmd);
- cl_spnl_perm=1;
- spl_run = 1;
- spl_cond= 46;
- }
- break;
- case 46:
- if(((spindle_on_for)==0||(spindle_on_rev)==0)&&(mot_spl_on)==0) // turn spindle off
- {
- spl_run = 0;
- cl_spnl_perm=0;
- spl_cond=3;
- }
- break;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment