Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Endstops::do_homing_cartesian(char axes_to_move)
- {
- // check if on_halt (eg kill)
- if(THEKERNEL->is_halted()) return;
- /*
- Rack and Pinion Head Homing
- The Z axis has a home switch that is triggered for half the length
- of the axis. To home it we need to first check if the switch is
- triggered, and if it is we need to back off until it's no longer
- triggered. Then we can perform a normal homing operation.
- */
- int rp_axis = Z_AXIS;
- // If we are homing Z and Z switch is already triggered, back away first
- if (((axes_to_move >> rp_axis) & 1) && this->pins[rp_axis + (this->home_direction[rp_axis] ? 0 : 3)].get()) {
- // Start moving away from the switch
- this->status = MOVING_BACK;
- this->feed_rate[rp_axis]= this->fast_rates[rp_axis];
- STEPPER[rp_axis]->move(!this->home_direction[rp_axis], 10000000, 0);
- // Wait for the switch to clear
- unsigned int debounce = 0;
- while (debounce <= debounce_count) {
- if (!this->pins[rp_axis + (this->home_direction[rp_axis] ? 0 : 3)].get()) {
- debounce++;
- }
- else {
- debounce = 0;
- }
- THEKERNEL->call_event(ON_IDLE);
- // check if on_halt (eg kill)
- if(THEKERNEL->is_halted()) return;
- }
- // Stop the movement
- if (STEPPER[rp_axis]->is_moving()) {
- STEPPER[rp_axis]->move(0, 0);
- }
- }
- /*
- End of Rack and Pinion Homing
- */
- // this homing works for cartesian and delta printers
- // Start moving the axes to the origin
- this->status = MOVING_TO_ENDSTOP_FAST;
- for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
- if ( ( axes_to_move >> c) & 1 ) {
- this->feed_rate[c]= this->fast_rates[c];
- STEPPER[c]->move(this->home_direction[c], 10000000, 0);
- }
- }
- // Wait for all axes to have homed
- if(!this->wait_for_homed(axes_to_move)) return;
- // Move back a small distance
- this->status = MOVING_BACK;
- bool inverted_dir;
- for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
- if ( ( axes_to_move >> c ) & 1 ) {
- inverted_dir = !this->home_direction[c];
- this->feed_rate[c]= this->slow_rates[c];
- STEPPER[c]->move(inverted_dir, this->retract_mm[c]*STEPS_PER_MM(c), 0);
- }
- }
- // Wait for moves to be done
- for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
- if ( ( axes_to_move >> c ) & 1 ) {
- while ( STEPPER[c]->is_moving() ) {
- THEKERNEL->call_event(ON_IDLE);
- if(THEKERNEL->is_halted()) return;
- }
- }
- }
- // Start moving the axes to the origin slowly
- this->status = MOVING_TO_ENDSTOP_SLOW;
- for ( int c = X_AXIS; c <= Z_AXIS; c++ ) {
- if ( ( axes_to_move >> c ) & 1 ) {
- this->feed_rate[c]= this->slow_rates[c];
- STEPPER[c]->move(this->home_direction[c], 10000000, 0);
- }
- }
- // Wait for all axes to have homed
- if(!this->wait_for_homed(axes_to_move)) return;
- }
Advertisement
Add Comment
Please, Sign In to add comment