this->fx_ticks_per_step = 0;
this->steps_to_move = 0;
this->direction_bit = 0;
- //this->update_exit_tick();
this->remove_from_active_list_next_reset = false;
this->is_move_finished = false;
+ this->signal_step = false;
+ this->step_signal_hook = new Hook();
}
StepperMotor::StepperMotor(Pin* step, Pin* dir, Pin* en) : step_pin(step), dir_pin(dir), en_pin(en) {
this->fx_ticks_per_step = 0;
this->steps_to_move = 0;
this->direction_bit = 0;
- //this->update_exit_tick();
this->remove_from_active_list_next_reset = false;
this->is_move_finished = false;
+ this->signal_step = false;
+ this->step_signal_hook = new Hook();
}
// Called a great many times per second, to step if we have to now
-bool StepperMotor::tick(){
+void StepperMotor::tick(){
// increase the ( fixed point ) counter by one tick 11t
this->fx_counter += (uint64_t)((uint64_t)1<<32);
// we have moved a step 9t
this->stepped++;
+ // Do we need to signal this step
+ if( this->stepped == this->signal_step_number && this->signal_step ){
+ this->step_signal_hook->call();
+ }
+
// is this move finished ? 11t
if( this->stepped == this->steps_to_move ){
this->is_move_finished = true;
}
+// If the move is finished, the StepTicker will call this ( because we asked it to in tick() )
void StepperMotor::signal_move_finished(){
// work is done ! 8t
}
this->is_move_finished = false;
-
}
// 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(){
- //printf("try update list %u %u %u\r\n", this->moving, this->paused, this->fx_ticks_per_step == 0 );
if( !this->moving || this->paused || this->steps_to_move == 0 ){
// We must exit tick() after setting the pins, no bresenham is done
- //this->remove_from_active_list_next_reset = true;
this->step_ticker->remove_motor_from_active_list(this);
}else{
// We must do the bresenham in tick()
// We have to do this or there could be a bug where the removal still happens when it doesn't need to
- //this->remove_from_active_list_next_reset = false;
this->step_ticker->add_motor_to_active_list(this);
}
}
// Instruct the StepperMotor to move a certain number of steps
void StepperMotor::move( bool direction, unsigned int steps ){
-
- //printf("stepper %p moving %u \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;
this->fx_counter = 0; // Bresenheim counter
this->stepped = 0;
+ // Do not signal steps until we get instructed to
+ this->signal_step = false;
+
// Starting now we are moving
if( steps > 0 ){
this->moving = true;
}
+//#pragma GCC push_options
+//#pragma GCC optimize ("O0")
+
// Set the speed at which this steper moves
void StepperMotor::set_speed( double speed ){
- //printf(" steppermotor %p set speed : %f \r\n", this, speed);
if( speed < 0.0001 ){
- this->steps_per_second = 0;
- this->fx_ticks_per_step = 1>>63;
+ //__debugbreak();
return;
}
- //if( speed < this->steps_per_second ){
- LPC_GPIO1->FIOSET = 1<<19;
- //}
-
// How many steps we must output per second
this->steps_per_second = speed;
double double_fx_ticks_per_step = (double)(1<<16) * ( (double)(1<<16) * ticks_per_step );
this->fx_ticks_per_step = (uint64_t)( floor(double_fx_ticks_per_step) );
- LPC_GPIO1->FIOCLR = 1<<19;
-
}
+//#pragma GCC pop_options
+
void StepperMotor::pause(){
this->paused = true;
this->update_exit_tick();