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/>.
11 #include "libs/Kernel.h"
12 #include "libs/Hook.h"
19 StepperMotor(Pin
& step
, Pin
& dir
, Pin
& en
);
28 void move( bool direction
, unsigned int steps
);
29 void signal_move_finished();
30 void set_speed( float speed
);
31 void update_exit_tick();
35 void change_steps_per_mm(float);
36 void change_last_milestone(float);
38 int steps_to_target(float);
40 template<typename T
> void attach( T
*optr
, uint32_t ( T::*fptr
)( uint32_t ) ){
41 Hook
* hook
= new Hook();
42 hook
->attach(optr
, fptr
);
43 this->end_hook
= hook
;
46 template<typename T
> void attach_signal_step(uint32_t step
, T
*optr
, uint32_t ( T::*fptr
)( uint32_t ) ){
47 this->step_signal_hook
->attach(optr
, fptr
);
48 this->signal_step_number
= step
;
49 this->signal_step
= true;
53 Hook
* step_signal_hook
;
56 uint32_t signal_step_number
;
58 StepTicker
* step_ticker
;
63 float steps_per_second
;
71 int32_t last_milestone_steps
;
72 float last_milestone_mm
;
74 uint32_t steps_to_move
;
77 uint32_t fx_ticks_per_step
;
82 bool remove_from_active_list_next_reset
;
84 bool is_move_finished
; // Whether the move just finished
88 // Called a great many times per second, to step if we have to now
89 inline void StepperMotor::tick(){
91 // increase the ( fixed point ) counter by one tick 11t
92 this->fx_counter
+= (uint32_t)(1<<16);
94 // if we are to step now 10t
95 if( this->fx_counter
>= this->fx_ticks_per_step
){ this->step(); }
99 inline void StepperMotor::unstep()
104 inline void StepperMotor::enable(bool state
)