enabled specifying numeric config values using all strtof capabilities
[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 #ifndef STEPPERMOTOR_H
9 #define STEPPERMOTOR_H
10
11 #include "libs/Hook.h"
12 #include "Pin.h"
13
14 class StepTicker;
15 class Hook;
16
17 class StepperMotor {
18 public:
19 StepperMotor();
20 StepperMotor(Pin& step, Pin& dir, Pin& en);
21
22 // Called a great many times per second, to step if we have to now
23 inline void tick() {
24 // increase the ( fixed point ) counter by one tick 11t
25 fx_counter += (uint32_t)(1<<16);
26
27 // if we are to step now 10t
28 if (fx_counter >= fx_ticks_per_step)
29 step();
30 };
31
32 void step();
33 inline void unstep() { step_pin.set(0); };
34
35 inline void enable(bool state) { en_pin.set(!state); };
36
37 void move_finished();
38 void move( bool direction, unsigned int steps );
39 void signal_move_finished();
40 void set_speed( float speed );
41 void update_exit_tick();
42 void pause();
43 void unpause();
44
45 void change_steps_per_mm(float);
46 void change_last_milestone(float);
47
48 int steps_to_target(float);
49
50 template<typename T> void attach( T *optr, uint32_t ( T::*fptr )( uint32_t ) ){
51 Hook* hook = new Hook();
52 hook->attach(optr, fptr);
53 this->end_hook = hook;
54 }
55
56 template<typename T> void attach_signal_step(uint32_t step, T *optr, uint32_t ( T::*fptr )( uint32_t ) ){
57 this->step_signal_hook->attach(optr, fptr);
58 this->signal_step_number = step;
59 this->signal_step = true;
60 }
61
62 Hook* end_hook;
63 Hook* step_signal_hook;
64
65 bool signal_step;
66 uint32_t signal_step_number;
67
68 StepTicker* step_ticker;
69 Pin step_pin;
70 Pin dir_pin;
71 Pin en_pin;
72
73 float steps_per_second;
74
75 volatile bool moving;
76 bool paused;
77
78 float steps_per_mm;
79 float max_rate;
80
81 int32_t last_milestone_steps;
82 float last_milestone_mm;
83
84 uint32_t steps_to_move;
85 uint32_t stepped;
86 uint32_t fx_counter;
87 uint32_t fx_ticks_per_step;
88
89 bool direction;
90
91 //bool exit_tick;
92 bool remove_from_active_list_next_reset;
93
94 bool is_move_finished; // Whether the move just finished
95 };
96
97 #endif
98