+ // Figure out how long the move takes total ( in seconds )
+ float total_move_time = time_to_accelerate + time_to_decelerate + plateau_time;
+ //puts "total move time: #{total_move_time}s time to accelerate: #{time_to_accelerate}, time to decelerate: #{time_to_decelerate}"
+
+ // We now have the full timing for acceleration, plateau and deceleration,
+ // yay \o/ Now this is very important these are in seconds, and we need to
+ // round them into ticks. This means instead of accelerating in 100.23
+ // ticks we'll accelerate in 100 ticks. Which means to reach the exact
+ // speed we want to reach, we must figure out a new/slightly different
+ // acceleration/deceleration to be sure we accelerate and decelerate at
+ // the exact rate we want
+
+ // First off round total time, acceleration time and deceleration time in ticks
+ uint32_t acceleration_ticks = floorf( time_to_accelerate * STEP_TICKER_FREQUENCY );
+ uint32_t deceleration_ticks = floorf( time_to_decelerate * STEP_TICKER_FREQUENCY );
+ uint32_t total_move_ticks = floorf( total_move_time * STEP_TICKER_FREQUENCY );
+
+ // Now deduce the plateau time for those new values expressed in tick
+ //uint32_t plateau_ticks = total_move_ticks - acceleration_ticks - deceleration_ticks;
+
+ // Now we figure out the acceleration value to reach EXACTLY maximum_rate(steps/s) in EXACTLY acceleration_ticks(ticks) amount of time in seconds
+ float acceleration_time = acceleration_ticks / STEP_TICKER_FREQUENCY; // This can be moved into the operation below, separated for clarity, note we need to do this instead of using time_to_accelerate(seconds) directly because time_to_accelerate(seconds) and acceleration_ticks(seconds) do not have the same value anymore due to the rounding
+ float deceleration_time = deceleration_ticks / STEP_TICKER_FREQUENCY;
+
+ float acceleration_in_steps = (acceleration_time > 0.0F ) ? ( this->maximum_rate - initial_rate ) / acceleration_time : 0;
+ float deceleration_in_steps = (deceleration_time > 0.0F ) ? ( this->maximum_rate - final_rate ) / deceleration_time : 0;
+
+ // we have a potential race condition here as we could get interrupted anywhere in the middle of this call, we need to lock
+ // the updates to the blocks to get around it
+ this->locked= true;
+ // Now figure out the two acceleration ramp change events in ticks
+ this->accelerate_until = acceleration_ticks;
+ this->decelerate_after = total_move_ticks - deceleration_ticks;
+
+ // We now have everything we need for this block to call a Steppermotor->move method !!!!
+ // Theorically, if accel is done per tick, the speed curve should be perfect.
+ this->total_move_ticks = total_move_ticks;
+
+ this->initial_rate = initial_rate;