enabled specifying numeric config values using all strtof capabilities
[clinton/Smoothieware.git] / src / libs / StepperMotor.h
CommitLineData
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
feb204be 11#include "libs/Hook.h"
5673fe39 12#include "Pin.h"
feb204be
AW
13
14class StepTicker;
5673fe39 15class Hook;
feb204be 16
670fa10b 17class StepperMotor {
feb204be 18 public:
670fa10b 19 StepperMotor();
9c5fa39a 20 StepperMotor(Pin& step, Pin& dir, Pin& en);
9c5fa39a 21
203213ae
MM
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); };
9c5fa39a 34
203213ae 35 inline void enable(bool state) { en_pin.set(!state); };
9c5fa39a 36
670fa10b 37 void move_finished();
feb204be 38 void move( bool direction, unsigned int steps );
bd0f7508 39 void signal_move_finished();
1ad23cd3 40 void set_speed( float speed );
672298b2 41 void update_exit_tick();
83ecfc46
AW
42 void pause();
43 void unpause();
670fa10b 44
78d0e16a
MM
45 void change_steps_per_mm(float);
46 void change_last_milestone(float);
670fa10b 47
78d0e16a 48 int steps_to_target(float);
670fa10b
L
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
feb204be 68 StepTicker* step_ticker;
9c5fa39a
MM
69 Pin step_pin;
70 Pin dir_pin;
71 Pin en_pin;
feb204be 72
1ad23cd3 73 float steps_per_second;
670fa10b
L
74
75 volatile bool moving;
76 bool paused;
77
78d0e16a 78 float steps_per_mm;
df6a30f2 79 float max_rate;
78d0e16a
MM
80
81 int32_t last_milestone_steps;
82 float last_milestone_mm;
83
670fa10b
L
84 uint32_t steps_to_move;
85 uint32_t stepped;
86 uint32_t fx_counter;
87 uint32_t fx_ticks_per_step;
df6a30f2 88
9c5fa39a 89 bool direction;
670fa10b
L
90
91 //bool exit_tick;
92 bool remove_from_active_list_next_reset;
93
bd0f7508 94 bool is_move_finished; // Whether the move just finished
feb204be
AW
95};
96
feb204be
AW
97#endif
98