Commit | Line | Data |
---|---|---|
7b49793d | 1 | /* |
feb204be AW |
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. | |
7b49793d | 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
feb204be AW |
6 | */ |
7 | ||
8 | #ifndef STEPPERMOTOR_H | |
9 | #define STEPPERMOTOR_H | |
10 | ||
5673fe39 | 11 | #include "Pin.h" |
cb2e6bc6 | 12 | #include <atomic> |
398e9edc | 13 | #include <functional> |
feb204be AW |
14 | |
15 | class StepTicker; | |
5673fe39 | 16 | class Hook; |
feb204be | 17 | |
670fa10b | 18 | class StepperMotor { |
feb204be | 19 | public: |
670fa10b | 20 | StepperMotor(); |
9c5fa39a | 21 | StepperMotor(Pin& step, Pin& dir, Pin& en); |
3494f3d0 | 22 | ~StepperMotor(); |
203213ae | 23 | |
8b260c2c JM |
24 | inline void step() { current_position_steps += (direction?-1:1); step_pin.set( 1 ); } |
25 | inline void unstep() { step_pin.set(0); } | |
26 | inline void set_direction(bool f) { direction= f; dir_pin.set(f); } | |
9c5fa39a | 27 | |
203213ae | 28 | inline void enable(bool state) { en_pin.set(!state); }; |
9c5fa39a | 29 | |
eab91f11 JM |
30 | bool is_moving() const { return moving; } |
31 | bool which_direction() const { return direction; } | |
8b260c2c JM |
32 | // void move_finished(); |
33 | // StepperMotor* move( bool direction, unsigned int steps, float initial_speed= -1.0F); | |
34 | // StepperMotor* set_speed( float speed ); | |
670fa10b | 35 | |
2fa50ca0 | 36 | float get_steps_per_second() const { return steps_per_second; } |
2fa50ca0 | 37 | float get_steps_per_mm() const { return steps_per_mm; } |
78d0e16a MM |
38 | void change_steps_per_mm(float); |
39 | void change_last_milestone(float); | |
90f70d46 | 40 | float get_last_milestone(void) const { return last_milestone_mm; } |
58c32991 | 41 | float get_current_position(void) const { return (float)current_position_steps/steps_per_mm; } |
3494f3d0 JM |
42 | float get_max_rate(void) const { return max_rate; } |
43 | void set_max_rate(float mr) { max_rate= mr; } | |
670fa10b | 44 | |
78d0e16a | 45 | int steps_to_target(float); |
2fa50ca0 | 46 | uint32_t get_stepped() const { return stepped; } |
778093ce | 47 | void force_finish_move() { force_finish= true; } |
670fa10b | 48 | |
2fa50ca0 JM |
49 | friend class StepTicker; |
50 | friend class Stepper; | |
51 | friend class Planner; | |
52 | friend class Robot; | |
53 | ||
54 | private: | |
728477c4 | 55 | void init(); |
3494f3d0 | 56 | |
1fce036c | 57 | int index; |
670fa10b | 58 | |
9c5fa39a MM |
59 | Pin step_pin; |
60 | Pin dir_pin; | |
61 | Pin en_pin; | |
feb204be | 62 | |
1ad23cd3 | 63 | float steps_per_second; |
78d0e16a | 64 | float steps_per_mm; |
3494f3d0 JM |
65 | float max_rate; // this is not really rate it is in mm/sec, misnamed used in Robot and Extruder |
66 | float minimum_step_rate; // this is the minimum step_rate in steps/sec for this motor for this block | |
9502f9d5 | 67 | static float default_minimum_actuator_rate; |
78d0e16a | 68 | |
58c32991 | 69 | volatile int32_t current_position_steps; |
78d0e16a MM |
70 | int32_t last_milestone_steps; |
71 | float last_milestone_mm; | |
72 | ||
8b260c2c | 73 | uint32_t stepped; // TBD may not be needed |
778093ce | 74 | volatile struct { |
f095cddd | 75 | volatile bool is_move_finished:1; // Whether the move just finished |
728477c4 | 76 | volatile bool moving:1; |
778093ce JM |
77 | volatile bool force_finish:1; // set to force a move to finish early |
78 | bool direction:1; | |
ec543686 | 79 | }; |
feb204be AW |
80 | }; |
81 | ||
feb204be AW |
82 | #endif |
83 |