basic homing
[clinton/Smoothieware.git] / src / modules / tools / endstops / Endstops.cpp
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #include "libs/Module.h"
9 #include "libs/Kernel.h"
10 #include "modules/communication/utils/Gcode.h"
11 #include "modules/robot/Player.h"
12 #include "Endstops.h"
13 #include "libs/nuts_bolts.h"
14 #include "libs/StepperMotor.h"
15 #include "wait_api.h" // mbed.h lib
16
17 Endstops::Endstops(){
18 this->status = NOT_HOMING;
19 }
20
21 void Endstops::on_module_loaded() {
22 this->register_for_event(ON_GCODE_RECEIVED);
23
24 // Take StepperMotor objects from Robot and keep them here
25 this->steppers[0] = this->kernel->robot->alpha_stepper_motor;
26 this->steppers[1] = this->kernel->robot->beta_stepper_motor;
27 this->steppers[2] = this->kernel->robot->gamma_stepper_motor;
28
29 }
30
31
32 // Start homing sequences by response to GCode commands
33 void Endstops::on_gcode_received(void* argument){
34 Gcode* gcode = static_cast<Gcode*>(argument);
35 if( gcode->has_letter('G' )){
36 if( gcode->get_value('G') == 28 ){
37 // G28 is received, we have homing to do
38
39 // First wait for the queue to be empty
40 while(this->kernel->player->queue.size() > 0) { wait_us(500); }
41
42 // Do we move select axes or all of them
43 bool home_all_axes = true;
44 if( gcode->has_letter('X') || gcode->has_letter('Y') || gcode->has_letter('Z') ){ home_all_axes = false; }
45
46 // Start moving the axes to the origin
47 this->status = MOVING_TO_ORIGIN_FAST;
48 for( char c = 'X'; c <= 'Z'; c++ ){
49 if( home_all_axes || gcode->has_letter(c) ){
50 this->steppers[c - 'X']->move(0,10000000);
51 this->steppers[c - 'X']->set_speed(1);
52 }
53 }
54
55 // Wait for all axes to have homed
56
57
58
59 // Homing is done
60 this->status = NOT_HOMING;
61
62 }
63 }
64 }
65