Guest User

Untitled

a guest
Jun 16th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1.  
  2. void Endstops::do_homing_cartesian(char axes_to_move)
  3. {
  4. // check if on_halt (eg kill)
  5. if(THEKERNEL->is_halted()) return;
  6.  
  7. /*
  8. Rack and Pinion Head Homing
  9. The Z axis has a home switch that is triggered for half the length
  10. of the axis. To home it we need to first check if the switch is
  11. triggered, and if it is we need to back off until it's no longer
  12. triggered. Then we can perform a normal homing operation.
  13. */
  14. int rp_axis = Z_AXIS;
  15. // If we are homing Z and Z switch is already triggered, back away first
  16. if (((axes_to_move >> rp_axis) & 1) && this->pins[rp_axis + (this->home_direction[rp_axis] ? 0 : 3)].get()) {
  17. // Start moving away from the switch
  18. this->status = MOVING_BACK;
  19. this->feed_rate[rp_axis]= this->fast_rates[rp_axis];
  20. STEPPER[rp_axis]->move(!this->home_direction[rp_axis], 10000000, 0);
  21.  
  22. // Wait for the switch to clear
  23. unsigned int debounce = 0;
  24. while (debounce <= debounce_count) {
  25. if (!this->pins[rp_axis + (this->home_direction[rp_axis] ? 0 : 3)].get()) {
  26. debounce++;
  27. }
  28. else {
  29. debounce = 0;
  30. }
  31.  
  32. THEKERNEL->call_event(ON_IDLE);
  33.  
  34. // check if on_halt (eg kill)
  35. if(THEKERNEL->is_halted()) return;
  36. }
  37.  
  38. // Stop the movement
  39. if (STEPPER[rp_axis]->is_moving()) {
  40. STEPPER[rp_axis]->move(0, 0);
  41. }
  42. }
  43. /*
  44. End of Rack and Pinion Homing
  45. */
  46.  
  47. // this homing works for cartesian and delta printers
  48. // Start moving the axes to the origin
  49. this->status = MOVING_TO_ENDSTOP_FAST;
  50. for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
  51. if ( ( axes_to_move >> c) & 1 ) {
  52. this->feed_rate[c]= this->fast_rates[c];
  53. STEPPER[c]->move(this->home_direction[c], 10000000, 0);
  54. }
  55. }
  56.  
  57. // Wait for all axes to have homed
  58. if(!this->wait_for_homed(axes_to_move)) return;
  59.  
  60. // Move back a small distance
  61. this->status = MOVING_BACK;
  62. bool inverted_dir;
  63. for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
  64. if ( ( axes_to_move >> c ) & 1 ) {
  65. inverted_dir = !this->home_direction[c];
  66. this->feed_rate[c]= this->slow_rates[c];
  67. STEPPER[c]->move(inverted_dir, this->retract_mm[c]*STEPS_PER_MM(c), 0);
  68. }
  69. }
  70.  
  71. // Wait for moves to be done
  72. for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
  73. if ( ( axes_to_move >> c ) & 1 ) {
  74. while ( STEPPER[c]->is_moving() ) {
  75. THEKERNEL->call_event(ON_IDLE);
  76. if(THEKERNEL->is_halted()) return;
  77. }
  78. }
  79. }
  80.  
  81. // Start moving the axes to the origin slowly
  82. this->status = MOVING_TO_ENDSTOP_SLOW;
  83. for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
  84. if ( ( axes_to_move >> c ) & 1 ) {
  85. this->feed_rate[c]= this->slow_rates[c];
  86. STEPPER[c]->move(this->home_direction[c], 10000000, 0);
  87. }
  88. }
  89.  
  90. // Wait for all axes to have homed
  91. if(!this->wait_for_homed(axes_to_move)) return;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment