// This is just a way not to check for ( !this->moving || this->paused || this->fx_ticks_per_step == 0 ) at every tick()
inline void StepperMotor::update_exit_tick(){
if( !this->moving || this->paused || this->fx_ticks_per_step == 0 ){
- //printf("%p exit to true, moving: %u, paused: %u, fx_ticks_per_step: %u \r\n", this, this->moving, this->paused, this->fx_ticks_per_step);
this->exit_tick = true;
}else{
- //printf("%p exit to false, moving: %u, paused: %u, fx_ticks_per_step: %u \r\n", this, this->moving, this->paused, this->fx_ticks_per_step);
this->exit_tick = false;
}
}
// Instruct the StepperMotor to move a certain number of steps
void StepperMotor::move( bool direction, unsigned int steps ){
- //printf("stepper move %p moving %u steps\r\n", this, steps);
-
// We do not set the direction directly, we will set the pin just before the step pin on the next tick
this->direction_bit = direction;
void StepperMotor::set_speed( double speed ){
if( speed < 0.0001 ){
- //printf("speed is zero\r\n");
this->steps_per_second = 0;
this->fx_ticks_per_step = 1>>63;
return;
this->current_block = NULL;
this->paused = false;
this->trapezoid_generator_busy = false;
+ this->force_speed_update = false;
}
//Called when the module has just been loaded
// Setup acceleration for this block
this->trapezoid_generator_reset();
- if( block->initial_rate == 0 ){
- this->trapezoid_generator_tick(0);
- }
-
// Find the stepper with the more steps, it's the one the speed calculations will want to follow
this->main_stepper = this->kernel->robot->alpha_stepper_motor;
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; }
+
+ if( block->initial_rate == 0 ){
+ this->trapezoid_generator_tick(0);
+ }
+
}
// Current block is discarded
// When a stepper motor has finished it's assigned movement
inline uint32_t Stepper::stepper_motor_finished_move(uint32_t dummy){
- //printf("move finished in stepper %p:%d %p:%d %p:%d\r\n", this->kernel->robot->alpha_stepper_motor, this->kernel->robot->alpha_stepper_motor->moving, this->kernel->robot->beta_stepper_motor, this->kernel->robot->beta_stepper_motor->moving, this->kernel->robot->gamma_stepper_motor, this->kernel->robot->gamma_stepper_motor->moving );
-
// We care only if none is still moving
if( this->kernel->robot->alpha_stepper_motor->moving || this->kernel->robot->beta_stepper_motor->moving || this->kernel->robot->gamma_stepper_motor->moving ){ return 0; }
- //printf("move finished in stepper, releasing\r\n");
-
// This block is finished, release it
if( this->current_block != NULL ){
this->current_block->release();
// interrupt. It can be assumed that the trapezoid-generator-parameters and the
// current_block stays untouched by outside handlers for the duration of this function call.
uint32_t Stepper::trapezoid_generator_tick( uint32_t dummy ) {
+
if(this->current_block && !this->paused ) {
if(this->step_events_completed() < this->current_block->accelerate_until) {
this->trapezoid_adjusted_rate += this->current_block->rate_delta;
this->set_step_events_per_minute(this->trapezoid_adjusted_rate);
}
}
+ if( this->force_speed_update ){
+ this->force_speed_update = false;
+ this->set_step_events_per_minute(this->trapezoid_adjusted_rate);
+ }
}
+
}
// Initializes the trapezoid generator from the current block. Called whenever a new
// block begins.
inline void Stepper::trapezoid_generator_reset(){
this->trapezoid_adjusted_rate = this->current_block->initial_rate;
+ this->force_speed_update = true;
this->trapezoid_tick_cycle_counter = 0;
}