Move most handling of steps from arm_solution,Robot,Planner to StepperMotor
[clinton/Smoothieware.git] / src / modules / robot / Stepper.h
index e816a1c..8c50e11 100644 (file)
@@ -1,8 +1,8 @@
-/*  
+/*
       This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
       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.
       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.
-      You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 
+      You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef STEPPER_H
 #include "Planner.h"
 #include "Block.h"
 
-#define microseconds_per_step_pulse_ckeckusm        42333
-#define acceleration_ticks_per_second_checksum      25075
-#define minimum_steps_per_minute_checksum           9003
-#define base_stepping_frequency_checksum            21918
-#define step_gpio_port_checksum                     29939
-#define dir_gpio_port_checksum                      39286
-#define alpha_step_pin_checksum                     11468
-#define beta_step_pin_checksum                      22114
-#define gamma_step_pin_checksum                     1225
-#define alpha_dir_pin_checksum                      55887
-#define beta_dir_pin_checksum                       28644
-#define gamma_dir_pin_checksum                      46412
+#define microseconds_per_step_pulse_checksum        CHECKSUM("microseconds_per_step_pulse")
+#define acceleration_ticks_per_second_checksum      CHECKSUM("acceleration_ticks_per_second")
+#define minimum_steps_per_minute_checksum           CHECKSUM("minimum_steps_per_minute")
+#define base_stepping_frequency_checksum            CHECKSUM("base_stepping_frequency")
 
 class Stepper : public Module {
     public:
         Stepper();
         void on_module_loaded();
         void on_config_reload(void* argument);
-        void on_stepper_wake_up(void* argument);
-        void main_interrupt();
+        void on_block_begin(void* argument);
+        void on_block_end(void* argument);
+        void on_gcode_received(void* argument);
+        void on_gcode_execute(void* argument);
+        void on_play(void* argument);
+        void on_pause(void* argument);
+        uint32_t main_interrupt(uint32_t dummy);
         void trapezoid_generator_reset();
-        void set_step_events_per_minute(double steps_per_minute);
-        void trapezoid_generator_tick();
-        void reset_step_pins();
-        void update_offsets();
+        void set_step_events_per_minute(float steps_per_minute);
+        uint32_t trapezoid_generator_tick(uint32_t dummy);
+        uint32_t stepper_motor_finished_move(uint32_t dummy);
         int config_step_timer( int cycles );
+        void turn_enable_pins_on();
+        void turn_enable_pins_off();
+        uint32_t synchronize_acceleration(uint32_t dummy);
+
         Block* current_block;
-        Ticker acceleration_ticker;
-        Timeout flipper;
         int counters[3];
-        int stepped[3]; 
-        int offsets[3]; 
+        int stepped[3];
+        int offsets[3];
         float counter_alpha;
         float counter_beta;
         float counter_gamma;
-        int step_events_completed; 
-        unsigned int out_bits; 
-        double trapezoid_adjusted_rate;
+        //int step_events_completed;
+        unsigned int out_bits;
+        float trapezoid_adjusted_rate;
         int trapezoid_tick_cycle_counter;
-        int cycles_per_step_event; 
+        int cycles_per_step_event;
         bool trapezoid_generator_busy;
-        int microseconds_per_step_pulse; 
+        int microseconds_per_step_pulse;
         int acceleration_ticks_per_second;
-        int divider;
-        int minimum_steps_per_minute;
+        unsigned int minimum_steps_per_minute;
         int base_stepping_frequency;
-        LPC_GPIO_TypeDef* step_gpio_port;
-        LPC_GPIO_TypeDef* dir_gpio_port; 
-        unsigned short alpha_step_pin;
-        unsigned short beta_step_pin;
-        unsigned short gamma_step_pin;
-        unsigned short alpha_dir_pin;
-        unsigned short beta_dir_pin;
-        unsigned short gamma_dir_pin;
-        unsigned int step_mask;
-        unsigned int dir_mask;
+        unsigned short step_bits[3];
+        int counter_increment;
+        bool paused;
+        bool force_speed_update;
+        bool enable_pins_status;
+        Hook* acceleration_tick_hook;
+
+        StepperMotor* main_stepper;
+
 };