remove the minimum stepper rate as it is no longer used
[clinton/Smoothieware.git] / src / libs / StepperMotor.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 "Module.h"
11 #include "Pin.h"
12
13 class StepperMotor : public Module {
14 public:
15 StepperMotor(Pin& step, Pin& dir, Pin& en);
16 ~StepperMotor();
17
18 // called from step ticker ISR
19 inline void step() { step_pin.set(1); current_position_steps += (direction?-1:1); }
20 // called from unstep ISR
21 inline void unstep() { step_pin.set(0); }
22 // called from step ticker ISR
23 inline void set_direction(bool f) { dir_pin.set(f); direction= f; }
24
25 inline void enable(bool state) { en_pin.set(!state); };
26 inline bool is_enabled() const { return !en_pin.get(); };
27 inline bool is_moving() const { return moving; };
28
29 void manual_step(bool dir);
30
31 bool which_direction() const { return direction; }
32
33 float get_steps_per_second() const { return steps_per_second; }
34 float get_steps_per_mm() const { return steps_per_mm; }
35 void change_steps_per_mm(float);
36 void change_last_milestone(float);
37 float get_last_milestone(void) const { return last_milestone_mm; }
38 float get_current_position(void) const { return (float)current_position_steps/steps_per_mm; }
39 uint32_t get_current_step(void) const { return current_position_steps; }
40 float get_max_rate(void) const { return max_rate; }
41 void set_max_rate(float mr) { max_rate= mr; }
42
43 int steps_to_target(float);
44
45 friend class StepTicker;
46 friend class Stepper;
47 friend class Planner;
48 friend class Robot;
49
50 private:
51 void on_halt(void *argument);
52 void on_enable(void *argument);
53
54 int index;
55
56 Pin step_pin;
57 Pin dir_pin;
58 Pin en_pin;
59
60 float steps_per_second;
61 float steps_per_mm;
62 float max_rate; // this is not really rate it is in mm/sec, misnamed used in Robot and Extruder
63
64 volatile int32_t current_position_steps;
65 int32_t last_milestone_steps;
66 float last_milestone_mm;
67
68 volatile struct {
69 volatile bool direction:1;
70 volatile bool moving:1;
71 };
72 };
73