Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize planner with precalculation, etc. #4389

Merged
merged 6 commits into from
Jul 25, 2016

Conversation

thinkyhead
Copy link
Member

@thinkyhead thinkyhead commented Jul 24, 2016

Assuming all steps-per-mm are set to equal values on a DELTA (the usual case) we can reduce overhead by two float divisions and three float squarings. The key is to first calculate the distance moved sqrt(sq(dx) + sq(dy) + sq(dz)) in steps, and only afterward divide by steps_per_mm.

This PR applies this approach to optimize the planner for DELTA, and also generally fixes and optimizes the planner with the following changes:

  • Add Planner::steps_to_mm[4] to contain 1.0 / axis_steps_per_mm[].
  • Add Planner::refresh_positioning() to handle any change of axis_steps_per_mm:
    • Updates steps_to_mm, planner.position, and stepper.count
  • Call planner.refresh_positioning() in Config_Postprocess() and gcode_M92().
  • Call planner.refresh_positioning() for menu items that alter axis_steps_per_mm

Other math optimizations:

  • Multiply by 0.5, 0.125, etc., rather than divide by 2.0, 8.0, etc.

@Wurstnase has also suggested using the inverse-sqrt from the Quake source code. I'm investigating that next.

float inverse_sqrt(float number) {
  long i;
  float x2, y;
  const float threehalfs = 1.5f;

  x2 = number * 0.5F;
  y  = number;
  i  = * ( long * ) &y;                     // evil floating point bit level hacking
  i  = 0x5f3759df - ( i >> 1 );             // what the fuck? 
  y  = * ( float * ) &i;
  y  *= ( threehalfs - ( x2 * y * y ) );    // 1st iteration
  // y *= ( threehalfs - ( x2 * y * y ) );  // 2nd iteration, this can be removed

  return y;
}

@thinkyhead thinkyhead added PR: Improvement Needs: Testing Testing is needed for this change T: Design Concept Technical ideas about ways and methods. Needs: Discussion Discussion is needed Bug: Confirmed ! PR: Bug Fix labels Jul 24, 2016
@thinkyhead thinkyhead changed the title Optimize block->millimeters for DELTA Optimize planner with precalculation, etc. Jul 24, 2016
#endif
delta_mm[E_AXIS] = (de / axis_steps_per_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;
delta_mm[E_AXIS] = (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * extruder_multiplier[extruder] / 100.0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 0.01 ?

@thinkyhead thinkyhead force-pushed the rc_optimize_planner branch 3 times, most recently from 1d429b8 to fe0c5bc Compare July 24, 2016 19:31
@Wurstnase
Copy link
Contributor

You don't need to shift 32, 512 or similar. The compiler will do this for you. This will not save anything.

@thinkyhead thinkyhead merged commit b7b7c90 into MarlinFirmware:RCBugFix Jul 25, 2016
@thinkyhead thinkyhead deleted the rc_optimize_planner branch July 25, 2016 00:48
@jbrazio jbrazio modified the milestone: 1.1.0 Jul 25, 2016
drewmoseley pushed a commit to drewmoseley/Marlin that referenced this pull request May 31, 2024
…_whitespace

Cleanup: whitespace in nProbeRetryCount var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Confirmed ! Needs: Discussion Discussion is needed Needs: Testing Testing is needed for this change PR: Bug Fix PR: Improvement T: Design Concept Technical ideas about ways and methods.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants