#include <mri.h>
+// The stepper reacts to blocks that have XYZ movement to transform them into actual stepper motor moves
+// TODO: This does accel, accel should be in StepperMotor
+
Stepper* stepper;
uint32_t previous_step_count;
uint32_t skipped_speed_updates;
uint32_t speed_ticks_counter;
-
Stepper::Stepper(){
this->current_block = NULL;
this->paused = false;
this->kernel->robot->gamma_stepper_motor->unpause();
}
-
+// React to enable/disable gcodes
void Stepper::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
}
}
+// Enable steppers
void Stepper::turn_enable_pins_on(){
this->kernel->robot->alpha_en_pin.set(0);
this->kernel->robot->beta_en_pin.set(0);
this->enable_pins_status = true;
}
+// Disable steppers
void Stepper::turn_enable_pins_off(){
this->kernel->robot->alpha_en_pin.set(1);
this->kernel->robot->beta_en_pin.set(1);
if( this->kernel->robot->beta_stepper_motor->steps_to_move > this->main_stepper->steps_to_move ){ this->main_stepper = this->kernel->robot->beta_stepper_motor; }
if( this->kernel->robot->gamma_stepper_motor->steps_to_move > this->main_stepper->steps_to_move ){ this->main_stepper = this->kernel->robot->gamma_stepper_motor; }
-
+ // Set the initial speed for this move
this->trapezoid_generator_tick(0);
// Synchronise the acceleration curve with the stepping
this->current_block = NULL; //stfu !
}
-//#pragma GCC push_options
-//#pragma GCC optimize ("O0")
-
// When a stepper motor has finished it's assigned movement
uint32_t Stepper::stepper_motor_finished_move(uint32_t dummy){
// current_block stays untouched by outside handlers for the duration of this function call.
uint32_t Stepper::trapezoid_generator_tick( uint32_t dummy ) {
+ // Do not do the accel math for nothing
if(this->current_block && !this->paused && this->main_stepper->moving ) {
+
+ // Store this here because we use it a lot down there
uint32_t current_steps_completed = this->main_stepper->stepped;
+ // Do not accel, just set the value
if( this->force_speed_update ){
this->force_speed_update = false;
this->set_step_events_per_minute(this->trapezoid_adjusted_rate);
return 0;
}
+ // If we are accelerating
if(current_steps_completed <= this->current_block->accelerate_until + 1) {
- this->trapezoid_adjusted_rate += this->current_block->rate_delta;
-
+ // Increase speed
+ this->trapezoid_adjusted_rate += this->current_block->rate_delta;
if (this->trapezoid_adjusted_rate > this->current_block->nominal_rate ) {
this->trapezoid_adjusted_rate = this->current_block->nominal_rate;
}
this->set_step_events_per_minute(this->trapezoid_adjusted_rate);
+
+ // If we are decelerating
}else if (current_steps_completed > this->current_block->decelerate_after) {
- // NOTE: We will only reduce speed if the result will be > 0. This catches small
+ // Reduce speed
+ // NOTE: We will only reduce speed if the result will be > 0. This catches small
// rounding errors that might leave steps hanging after the last trapezoid tick.
if(this->trapezoid_adjusted_rate > this->current_block->rate_delta * 1.5) {
this->trapezoid_adjusted_rate -= this->current_block->rate_delta;
this->trapezoid_adjusted_rate = this->current_block->final_rate;
}
this->set_step_events_per_minute(this->trapezoid_adjusted_rate);
+
+ // If we are cruising
}else {
// Make sure we cruise at exactly nominal rate
if (this->trapezoid_adjusted_rate != this->current_block->nominal_rate) {
steps_per_minute = this->minimum_steps_per_minute;
}
-
// Instruct the stepper motors
if( this->kernel->robot->alpha_stepper_motor->moving ){ this->kernel->robot->alpha_stepper_motor->set_speed( (steps_per_minute/60L) * ( (double)this->current_block->steps[ALPHA_STEPPER] / (double)this->current_block->steps_event_count ) ); }
if( this->kernel->robot->beta_stepper_motor->moving ){ this->kernel->robot->beta_stepper_motor->set_speed( (steps_per_minute/60L) * ( (double)this->current_block->steps[BETA_STEPPER ] / (double)this->current_block->steps_event_count ) ); }
if( this->kernel->robot->gamma_stepper_motor->moving ){ this->kernel->robot->gamma_stepper_motor->set_speed( (steps_per_minute/60L) * ( (double)this->current_block->steps[GAMMA_STEPPER] / (double)this->current_block->steps_event_count ) ); }
+ // Other modules might want to know the speed changed
this->kernel->call_event(ON_SPEED_CHANGE, this);
}
return 0;
}
-
-//#pragma GCC pop_options