Advertisement
Guest User

Untitled

a guest
Aug 12th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. component thc_pid "Torch Height Control";
  2.  
  3. description
  4. """
  5. Torch Height Control
  6. Mesa THC > Mesa 5i20 Encoder > EMC THC
  7. The Mesa THC sends a frequency based on the voltage detected to the encoder.
  8. The velocity from the encoder is converted to volts with the velocity scale
  9. parameter.
  10. The THCAD card sends a frequency at 0 volts so the scale offset parameter is
  11. used to correct this.
  12.  
  13. Component Functions
  14. If enabled and torch is on and X + Y velocity is within tolerance of set speed
  15. allow the THC to offset the Z axis as needed to maintain voltage.
  16.  
  17. If enabled and torch is off and the Z axis is moving up remove any correction
  18. at a rate not to exceed the rate of movement of the Z axis.
  19.  
  20. If enabled and torch is off and there is no correction
  21. pass the Z position and feed back untouched.
  22.  
  23. If not enabled pass the Z position and feed back untouched.
  24.  
  25. Physical Connections
  26. Plasma Torch Arc Voltage Signal => 6 x 487k 1% resistors => THC Arc Voltage In
  27. THC Frequency Signal => Encoder #0, pin A (Input)
  28. Plasma Torch Arc OK Signal => parport.0.pin-15-in
  29. parport.0.pin-16-out => Plasma Torch Start Arc Contacts
  30.  
  31. HAL Plasma Connections
  32. hm2_5i20.0.encoder.00.velocity => thc.encoder-vel (tip voltage)
  33. motion.spindle-on => parport.0.pin-16-out (start the arc)
  34. thc.arc-ok <= motion.digital-in-00 <= parport.0.pin-15-in (arc ok signal)
  35.  
  36. HAL Motion Connections
  37. thc.requested-vel <= motion.requested-vel
  38. thc.current-vel <= motion.current-vel
  39.  
  40. """;
  41.  
  42. author "John Thornton";
  43.  
  44. license "GPLv2 or greater";
  45.  
  46. option singleton yes;
  47.  
  48. // Input Pins
  49. pin in float encoder_vel "Connect to hm2_5i20.0.encoder.00.velocity";
  50. pin in float current_vel "Connect to motion.current-vel";
  51. pin in float requested_vel "Connect to motion.requested-vel";
  52. pin in float volts_requested "Tip Volts current_vel >= min_velocityequested (SP)";
  53. pin in float vel_tol "Velocity Tolerance (Corner Lock)";
  54. pin in float volts_limit "Maximum Voltage Correction Limit";
  55. pin in bit torch_on "Connect to motion.spindle-on";
  56. pin in bit arc_ok "Arc OK from Plasma Torch";
  57. pin in bit enable "Enable the THC, if not enabled Z position is passed through";
  58. pin in float z_pos_in "Z Motor Position Command in from axis.n.motor-pos-cmd";
  59. pin in float p_gain "P Gain";
  60.  
  61. // Output Pins
  62. pin out float z_pos_out "Z Motor Position Command Out";
  63. pin out float z_fb_out "Z Position Feedback to Axis";
  64. pin out float volts "The Calculated Volts";
  65. pin out float offset_value "The Current Offset";
  66. pin out bit vel_status "When the THC thinks we are at requested speed";
  67.  
  68. // Parameters
  69. param rw float vel_scale "The scale to convert the Velocity signal to Volts";
  70. param rw float scale_offset "The offset of the velocity input at 0 volts";
  71. param rw float velocity_tol "The deviation percent from planned velocity";
  72. param rw float voltage_tol "The deviation of Tip Voltage before correction takes place";
  73.  
  74. // Global Variables
  75. variable float offset;
  76. variable float last_z_in;
  77.  
  78. function _;
  79.  
  80. ;;
  81.  
  82. #include "rtapi_math.h"
  83.  
  84. FUNCTION(_) {
  85. // convert encoder velocity to volts
  86. volts = (encoder_vel - scale_offset) * vel_scale;
  87. if(volts < 0){volts = 0;} // make sure volts is not negative
  88. offset_value = offset;
  89.  
  90. if(enable){
  91. float min_velocity = requested_vel -(requested_vel*(1/velocity_tol));
  92. if(current_vel > 0 && current_vel >= min_velocity){vel_status = 1;}
  93. else {vel_status = 0;}
  94.  
  95. if(torch_on && arc_ok && vel_status){ // allow correction
  96. //if(volts_requested - volts > volts_limit){
  97. // volts = volts_requested - volts_limit;
  98. //}
  99. //else if(volts_requested + volts > volts_limit){
  100. // volts = volts_requested +volts_limit;
  101. //}
  102. if (abs(volts_requested - volts) > voltage_tol) {
  103. offset += (volts_requested - volts) * p_gain;
  104. }
  105. last_z_in = 0;
  106. }
  107. if(!torch_on){ // remove any offset
  108. float z_diff;
  109. z_diff = z_pos_in - last_z_in;
  110. if(z_diff > 0 && offset != 0){ // torch is moving up
  111. if(offset > 0){ // positive offset
  112. if(offset > z_diff){ // remove some
  113. offset -= z_diff;
  114. }
  115. else {offset = 0;}
  116. }
  117. if(offset < 0){ // negative offset
  118. if(offset < z_diff){ // remove some
  119. offset += z_diff;
  120. }
  121. else {offset = 0;}
  122. }
  123. }
  124. last_z_in = z_pos_in;
  125. }
  126. z_pos_out = z_pos_in + offset;
  127. z_fb_out = z_pos_in; // keep axis motor position fb from being confused
  128. }
  129. if(!enable){
  130. z_pos_out = z_pos_in;
  131. z_fb_out = z_pos_in; // keep axis motor position fb from being confused
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement