Guest User

Untitled

a guest
Jan 6th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.96 KB | None | 0 0
  1. /   component orient;
  2.  
  3.  
  4. //1/3/2014//
  5. /// inputs ////
  6. //pin in bit mot_orient_on;//           //on command from emc
  7.  
  8. pin in bit mot_spl_on;              //on command from emc
  9. pin in bit cl_spnl_fault;      
  10. pin in bit timer_off;               // run pin of timer for spindle shift
  11. pin io bit orient_m119;              // mcode fo requesting spindle orient
  12. pin io bit orient_m118;               // mcode fo requesting spindle free
  13. pin io bit low_gear_m141;              // mcode fo requesting low gear
  14. pin io bit hi_gear_m142;                 // mcode fo requesting hi gear
  15. pin in bit ls3_low_gear;                    // ls indicating low gear
  16. pin in bit ls2_hi_gear;                // ls indicating hi gear
  17. pin in bit ls1_plunger_in;             // ls for indicating if the plunger is in or out
  18. pin in bit spl_fh_released;           // flag indicating feed hold is relaesed
  19. pin in bit orient_fh_released;           // flag indicating feed hold is relaesed
  20. pin in bit timer1_off;              // timer for freeing spidle
  21. pin in bit tc_orient;                  // flag from tc program for spindle orient
  22. pin in bit spindle_on_for;            // tied to motion.spindle-forward
  23. pin in bit spindle_on_rev;            // tied to motion.spindle-reverse
  24. pin in bit timer2_off;
  25. pin in float spindle_rpm_cmd;                       //connected to motion.spindle-speed-out
  26.  
  27.  
  28. ///outputs///
  29. pin out bit sl_splplunger_out;          //solinoid for locking the orient plunger  
  30. pin out bit sl_splplunger_in;            //solinoid for locking the orient plunger
  31. pin out bit cl_spnl_perm ;            //drive enable
  32. pin out bit spl_run;                           // connected to hm2_5i23.0.pwmgen.04.enable
  33. pin out bit timer2_run;                 // timer done for wait for actual shift
  34. pin out bit sl_hi_gear;             // solinoid for hi gear
  35. pin out bit sl_low_gear;             // solinoid for low gear
  36. pin io bit in_hi_gear;                // flag bit indicating trans is in hi gear
  37. pin io bit in_low_gear;                // flag bit indicating trans is in low gear
  38. pin out bit spl_feed_hold;              // pin out from spindle plc for applying feed hold
  39. pin out bit orient_feed_hold;              //pin in from orient plc for applying feed hold
  40. pin out bit timer_run ;               //run pin of timer for spindle shift
  41. pin out bit timer1_run;              // timer for freeing spindle b4 run
  42. pin out bit tc_orient_comp;         // flag to tc program for spindle orient complete
  43. pin in bit spl_enabled;             // connected to pwmgen.04.enable
  44. pin out bit spl_fh_release;           // flag indicating feed hold inrrd release
  45. pin out bit orient_fh_release;           // flag indicating feed hold is relaesed
  46. pin out float spindle_speed;            // hm2_5i23.0.pwmgen.04.value
  47.  
  48.  
  49.  
  50. // parameters//
  51.  
  52. param rw float spl_orient_speed ;            // actual rpm for orient to br connected to pwmgen.04.value
  53. param rw s32 orient_cond ;           // condition of this program
  54. param rw bit spin_oriented ;             // preset stae of spindle orientation
  55. param rw s32 shift_trans;            // condition of transmission
  56. param rw s32 orient_spdl;
  57. pin io bit spindle_index_enable;     // index  on encoder spindle tied to hm2_5i20.0.encoder.01.index enable
  58. param rw s32 spl_cond ;
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. function _ nofp;
  71. license "gpl";
  72. ;;
  73.  
  74. void orient_the_spindle(void);
  75. void shift_the_transmission(void);
  76. void free_the_spindle(void);
  77. void run_the_spindle(void);
  78.  
  79.  
  80.  
  81. FUNCTION(_)
  82. {
  83.  
  84.     switch (orient_cond){
  85.     case 0:
  86.         if((orient_m119)==1&&(ls1_plunger_in)==1)
  87.         {
  88.             orient_m119=0;
  89.             orient_cond = 59;           //spindle is oriented
  90.         }
  91.  
  92.     case 1:
  93.         if(((orient_m119)==1||(tc_orient)==1)&&(ls1_plunger_in)==0)
  94.         {
  95.             orient_feed_hold = 1;           // spindle needs orient
  96.             tc_orient_comp=0;
  97.             spl_run=0;
  98.             orient_the_spindle();
  99.         }
  100.     case 2:
  101.         if((orient_m118)==1&&(ls1_plunger_in)==1)       // shift to spindle free
  102.         {
  103.             orient_feed_hold = 1;
  104.             free_the_spindle();
  105.         }
  106.     case 3:
  107.         if((orient_m118)==1&&(ls1_plunger_in)==0)
  108.         {
  109.             orient_m118=0;
  110.             orient_cond = 61;           // spindle is free
  111.         }
  112.     case 4:
  113.         if((low_gear_m141)==1&&((ls3_low_gear)==1&&(ls2_hi_gear)==0))
  114.         {
  115.             low_gear_m141=0;
  116.             orient_cond = 61;           // spindle in low gear ,no shifting
  117.         }
  118.  
  119.     case 5:
  120.         if((low_gear_m141)==1&&((ls3_low_gear)==0&&(ls2_hi_gear)==1))
  121.         {      
  122.             orient_feed_hold = 1;
  123.             spl_run=0;                 // spindle in not low gear needs shift
  124.             shift_the_transmission();
  125.         }
  126.  
  127.     case 6:
  128.         if((hi_gear_m142)==1&&((ls2_hi_gear)==1&&(ls3_low_gear)==0))
  129.         {
  130.             hi_gear_m142=0;
  131.             orient_cond = 61;           // spindle in hi gear no shift
  132.         }
  133.  
  134.     case 7:
  135.         if(((hi_gear_m142)==1&&(ls2_hi_gear)==0)&&(ls3_low_gear)==1)
  136.         {
  137.             orient_feed_hold = 1;               // spindle not in hi gear need shift
  138.             spl_run=0;
  139.             shift_the_transmission();
  140.         }
  141.  
  142.     case 8:
  143.         if(((ls3_low_gear)==1&&(ls2_hi_gear)==1)||((ls3_low_gear)==0&&(ls2_hi_gear)==0))
  144.         {
  145.             orient_cond = 62;           // transmission shift malfunction
  146.             orient_feed_hold = 1;
  147.         }
  148.         break;
  149.     case 59:                            // spindle oriented
  150.     {
  151.         orient_m119=0;
  152.         spin_oriented = 1;
  153.         orient_feed_hold = 0;
  154.         orient_fh_release=1;
  155.         tc_orient_comp=1;  
  156.     }
  157.     break;
  158.     case 60:    
  159.     {
  160.         orient_feed_hold = 1;  
  161.         rtapi_print_msg (RTAPI_MSG_ERR, "Missed Orient");
  162.     }
  163.     break;
  164.     case 61:                            // spindle is free or no errors
  165.     {
  166.         spl_feed_hold =0;
  167.         orient_feed_hold = 0;
  168.         orient_fh_release=1;
  169.         orient_cond = 0;    
  170.     }
  171.     break;
  172.  
  173.     case 62:                            
  174.     {
  175.         orient_feed_hold = 1;  
  176.         rtapi_print_msg (RTAPI_MSG_ERR, "Gear Shift Fault");    
  177.     }
  178.     break;
  179.     case 63:
  180.     {
  181.         spl_feed_hold =1;
  182.         rtapi_print_msg (RTAPI_MSG_ERR, "Spindle fault");  
  183.     }
  184.     break;
  185.     case 64:
  186.         if((mot_spl_on)==1)
  187.         {
  188.             run_the_spindle();
  189.         }
  190.         break;
  191.     case 65:
  192.     {
  193.         spl_feed_hold =1;
  194.         rtapi_print_msg (RTAPI_MSG_ERR, "Spindle not free for run");
  195.     }
  196.     break;
  197.     }  
  198. }
  199.  
  200.  
  201. void orient_the_spindle(void){
  202.     switch (orient_spdl){
  203.     case 0:
  204.         if((ls1_plunger_in)==1)
  205.         {
  206.             spin_oriented=1;
  207.             orient_cond = 0;    // orient the spindle,if the plunger is in ,it is//
  208.         }
  209.         else
  210.         {
  211.             spl_run = 0;
  212.             orient_spdl= 1;
  213.         }
  214.         break;
  215.  
  216.     case 1:
  217.         if((ls1_plunger_in)==0&&(ls2_hi_gear)==1)  // in hi gear
  218.         {
  219.             spl_orient_speed = 90;
  220.             (spindle_speed)=(spl_orient_speed);
  221.             cl_spnl_perm = 1;
  222.             spl_run = 1;
  223.             spindle_index_enable = 1;
  224.             orient_m119=0;
  225.             orient_spdl= 2;
  226.         }
  227.         else
  228.             if((ls1_plunger_in)==0&&(ls3_low_gear)==1)          //in low gear
  229.             {
  230.                 spl_orient_speed = 270;
  231.                 (spindle_speed)=(spl_orient_speed);
  232.                 cl_spnl_perm = 1;
  233.                 spl_run = 1;
  234.                 spindle_index_enable = 1;
  235.                 orient_m119=0;
  236.                 orient_spdl = 2;    
  237.             }
  238.         break;          
  239.         // wait for index marker
  240.     case 2:                            
  241.         if((spindle_index_enable)==0)  
  242.         {
  243.             sl_splplunger_out =0;
  244.             sl_splplunger_in = 1;
  245.             spl_run = 0;
  246.             cl_spnl_perm = 0;
  247.             orient_spdl= 3;
  248.         }
  249.         break;
  250.     case 3:
  251.         if((spindle_index_enable)==0&&(ls1_plunger_in)==1)
  252.         {
  253.             spl_run = 0;
  254.             (spindle_speed)=(spindle_rpm_cmd);
  255.             orient_cond = 0;
  256.             spin_oriented=1;
  257.             orient_m119=0;
  258.         }
  259.         else
  260.         {
  261.             spin_oriented=0;
  262.             orient_cond = 60;                   // missed oreint
  263.         }
  264.         break;
  265.     }
  266.     return;
  267.  
  268. }
  269.  
  270.  
  271. /// shift transmission//
  272.  
  273. void shift_the_transmission(void){
  274.     switch (shift_trans){
  275.     case 18:
  276.         orient_the_spindle();
  277.         {
  278.             shift_trans = 19;
  279.         }  
  280.         break;
  281.     case 19:
  282.         if((spin_oriented)==1&&(ls1_plunger_in)==1)
  283.         {
  284.             spl_feed_hold=1;
  285.             shift_trans=20;
  286.         }
  287.         break;  
  288.     case 20:
  289.         if((low_gear_m141)==1&&(spin_oriented)==1)
  290.         {
  291.             sl_hi_gear = 0;
  292.             sl_low_gear = 1;
  293.             timer_run = 1;
  294.             shift_trans=21;
  295.         }
  296.         else
  297.             if((hi_gear_m142)==1&&(spin_oriented)==1)
  298.             {
  299.                 sl_low_gear = 0;
  300.                 sl_hi_gear = 1;
  301.                 timer_run = 1;
  302.                 shift_trans=22;
  303.             }
  304.         timer_run=0;    
  305.         break;
  306.  
  307.     case 21:
  308.         if(((ls3_low_gear)==1&&(ls2_hi_gear)==0)&&(timer_off)==1)
  309.         {
  310.             in_low_gear=1;
  311.             low_gear_m141=0;
  312.             timer_run = 0;
  313.             orient_cond = 61;
  314.         }
  315.         else
  316.             if(((ls3_low_gear)!=1&&(ls2_hi_gear)!=0)&&(timer_off)==1)
  317.             {
  318.                 in_low_gear=0;
  319.                 timer_run=0;    
  320.                 low_gear_m141=0;
  321.                 orient_cond= 62;
  322.             }
  323.         break;  
  324.     case 22:
  325.         if(((ls3_low_gear)==0&&(ls2_hi_gear)==1)&&(timer_off)==1)
  326.         {
  327.             in_hi_gear=1;
  328.             timer_run=0;
  329.             hi_gear_m142=0;
  330.             orient_cond = 61;
  331.         }
  332.         else
  333.             if(((ls3_low_gear)!=0&&(ls2_hi_gear)!=1)&&(timer_off)==1)
  334.             {
  335.                 in_hi_gear= 0;
  336.                 timer_run=0;
  337.                 hi_gear_m142=0;
  338.                 orient_cond= 62;
  339.             }
  340.         break;
  341.     default:
  342.         orient_cond= 62;
  343.         break;
  344.  
  345.     }
  346.     return;
  347. }
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357. void free_the_spindle(void)
  358. {
  359.     {                           // free spindle on m118
  360.         sl_splplunger_in = 0;
  361.         sl_splplunger_out =1;
  362.         orient_m118=0;
  363.         orient_cond = 61;  
  364.     }  
  365.     return;
  366. }
  367.  
  368.  
  369. ///run the spindle//
  370.  
  371.  
  372.  
  373. void run_the_spindle(void)
  374. {
  375.     switch (spl_cond){
  376.     case 40:    
  377.         if(((spindle_rpm_cmd)<=800&&(in_low_gear)==1)&&((mot_spl_on)==1&&(low_gear_m141)==1))
  378.         {
  379.             spl_cond = 43;
  380.         }
  381.         else
  382.             if(((spindle_rpm_cmd)>100&&(in_low_gear)==1)&&((mot_spl_on)==1&&(hi_gear_m142)==1))
  383.             {
  384.                 spl_cond = 41;
  385.             }
  386.             else
  387.                 if(((spindle_rpm_cmd)>100&&(in_hi_gear)==1)&&((mot_spl_on)==1&&(hi_gear_m142)==1))
  388.                 {  
  389.                     spl_cond = 43;
  390.                 }
  391.                 else
  392.                     if(((spindle_rpm_cmd)<=800&&(in_low_gear)==0)&&((mot_spl_on)==1&&(low_gear_m141)==1))
  393.                     {
  394.                         spl_cond = 41;
  395.                     }                      
  396.         break;
  397.  
  398.     case 41:
  399.         shift_the_transmission();
  400.         {
  401.             spl_cond = 42;
  402.         }
  403.         break;
  404.  
  405.     case 42:
  406.         if((in_hi_gear)==1||(in_low_gear)==1)
  407.         {
  408.             spl_cond = 43;
  409.         }
  410.         else
  411.         {
  412.             orient_cond = 62 ;
  413.         }
  414.         break;
  415.     case 43 :
  416.         if((mot_spl_on)==1&&(cl_spnl_fault)==1)
  417.         {
  418.             cl_spnl_perm=0;
  419.             spl_run = 0;
  420.             rtapi_print_msg (RTAPI_MSG_ERR, "Spindle drive fault");
  421.             orient_cond = 63;
  422.         }
  423.         else                
  424.             if(((spindle_on_for)==1||(spindle_on_rev)==1)&&(mot_spl_on)==1)
  425.             {
  426.                 timer1_run = 1;
  427.                 free_the_spindle();
  428.                 spl_cond= 44;
  429.             }
  430.         break;
  431.  
  432.     case 44:
  433.         if((timer1_off)==1&&(ls1_plunger_in)==0)         // check for plunger out
  434.         {
  435.             spl_cond= 45;
  436.         }
  437.         else
  438.  
  439.             if((timer1_off)==1&&(ls1_plunger_in)==1)
  440.             {
  441.                 orient_cond = 65;
  442.             }
  443.         break;
  444.     case 45:
  445.         if(((spindle_on_for)==1||(spindle_on_rev)==1)&&(mot_spl_on)==1)    // run spindle
  446.         {
  447.             (spindle_speed)=(spindle_rpm_cmd);
  448.             cl_spnl_perm=1;
  449.             spl_run = 1;
  450.             spl_cond= 46;
  451.         }
  452.         break;
  453.  
  454.     case 46:                            
  455.         if(((spindle_on_for)==0||(spindle_on_rev)==0)&&(mot_spl_on)==0)     // turn spindle off
  456.         {  
  457.             spl_run = 0;
  458.             cl_spnl_perm=0;
  459.             spl_cond=3;
  460.         }
  461.         break;
  462.     }
  463.     return;
  464.  
  465. }
Advertisement
Add Comment
Please, Sign In to add comment