Implement endstops using new motion control
[clinton/Smoothieware.git] / src / modules / tools / endstops / Endstops.h
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 #pragma once
9
10 #include "libs/Module.h"
11 #include "libs/Pin.h"
12
13 #include <bitset>
14 #include <array>
15
16 class StepperMotor;
17 class Gcode;
18
19 class Endstops : public Module{
20 public:
21 Endstops();
22 void on_module_loaded();
23 void on_gcode_received(void* argument);
24
25 private:
26 void load_config();
27 void home();
28 bool wait_for_homed();
29 bool wait_for_homed_corexy(int axis);
30 void corexy_home(int home_axis, bool dirx, bool diry, float fast_rate, float slow_rate, unsigned int retract_steps);
31 void back_off_home();
32 void move_to_origin();
33 void on_get_public_data(void* argument);
34 void on_set_public_data(void* argument);
35 void on_idle(void *argument);
36 bool debounced_get(int pin);
37 void process_home_command(Gcode* gcode);
38 void set_homing_offset(Gcode* gcode);
39 uint32_t read_endstops(uint32_t dummy);
40
41 float homing_position[3];
42 float home_offset[3];
43 float saved_position[3]{0}; // save G28 (in grbl mode)
44 float alpha_max, beta_max, gamma_max;
45
46 unsigned int debounce_count;
47 float retract_mm[3];
48 float trim_mm[3];
49 float fast_rates[3];
50 float slow_rates[3];
51 Pin pins[6];
52 std::array<uint16_t, 3> debounce;
53
54 std::bitset<3> home_direction;
55 std::bitset<3> limit_enable;
56 std::bitset<3> axis_to_home;
57
58 struct {
59 uint8_t homing_order:6;
60 uint8_t bounce_cnt:4;
61 volatile char status:3;
62 bool is_corexy:1;
63 bool is_delta:1;
64 bool is_rdelta:1;
65 bool is_scara:1;
66 bool move_to_origin_after_home:1;
67 };
68 };