yay, big stepper branch bug solved, we forgot to set speed to initial_rate because...
authorArthur Wolf <wolf.arthur@gmail.com>
Mon, 13 Aug 2012 22:31:54 +0000 (00:31 +0200)
committerArthur Wolf <wolf.arthur@gmail.com>
Mon, 13 Aug 2012 22:31:54 +0000 (00:31 +0200)
src/libs/StepperMotor.cpp
src/modules/robot/Stepper.cpp
src/modules/robot/Stepper.h

index ec0652e..01edb31 100644 (file)
@@ -88,10 +88,8 @@ bool StepperMotor::tick(){
 // 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;
     }
 }
@@ -101,8 +99,6 @@ inline void StepperMotor::update_exit_tick(){
 // 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;
 
@@ -123,7 +119,6 @@ void StepperMotor::move( bool direction, unsigned int steps ){
 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; 
index 6dc6b16..6399d41 100644 (file)
@@ -20,6 +20,7 @@ Stepper::Stepper(){
     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
@@ -113,15 +114,16 @@ void Stepper::on_block_begin(void* argument){
     // 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
@@ -133,13 +135,9 @@ void Stepper::on_block_end(void* argument){
 // 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(); 
@@ -155,6 +153,7 @@ inline uint32_t Stepper::step_events_completed(){
 // 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;
@@ -183,13 +182,19 @@ uint32_t Stepper::trapezoid_generator_tick( uint32_t dummy ) {
                   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;
 }
 
index 3a05316..3c5c32e 100644 (file)
@@ -75,6 +75,7 @@ class Stepper : public Module {
         unsigned short step_bits[3];
         int counter_increment;
         bool paused;
+        bool force_speed_update;
 
         StepperMotor* main_stepper;