Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wolfmanjm/d10aafe38fb95967471fa9f23dffe4e5 to your computer and use it in GitHub Desktop.
Save wolfmanjm/d10aafe38fb95967471fa9f23dffe4e5 to your computer and use it in GitHub Desktop.
// this is the time it should take to execute this cartesian move, it is approximate
// as it does not take into account accel/decel
float secs = distance / rate_mm_s;
// check per-actuator speed limits by looking at the minimum time each axis can move its specified amount
// this is regardless of wether it is mm/sec or deg/sec for a rotary axis
for (size_t actuator = 0; actuator < n_motors; actuator++) {
// actual distance moved for this actuator
// NOTE for a rotary axis this will be degrees turned not distance
float d = fabsf(actuator_pos[actuator] - actuators[actuator]->get_last_milestone());
if(d == 0 || !actuators[actuator]->is_selected()) continue; // no movement for this actuator
// find approximate min time this axis needs to move its distance
float actuator_min_time= d / actuators[actuator]->get_max_rate();
if (secs < actuator_min_time ) {
// this move at the default rate will move too quickly for this actuator
// so we decrease the overall feed rate so it can complete within the min time for this actuator
rate_mm_s= distance / actuator_min_time;
// recalculate time from new rate
secs = distance / rate_mm_s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment