2010-06-28 23:29:58 +02:00
|
|
|
/*
|
|
|
|
acceleration.c - support methods for acceleration-related calcul
|
|
|
|
Part of Grbl
|
|
|
|
|
2011-01-14 16:45:18 +01:00
|
|
|
Copyright (c) 2009-2011 Simen Svale Skogsrud
|
2010-06-28 23:29:58 +02:00
|
|
|
|
|
|
|
Grbl is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Grbl is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Estimate the maximum speed at a given distance when you need to reach the given
|
2011-01-14 12:10:18 +01:00
|
|
|
// target_velocity with max_acceleration.
|
|
|
|
double estimate_max_speed(double max_acceleration, double target_velocity, double distance) {
|
|
|
|
return(sqrt(-2*max_acceleration*distance+target_velocity*target_velocity))
|
2010-06-28 23:29:58 +02:00
|
|
|
}
|
|
|
|
|
2011-01-14 12:10:18 +01:00
|
|
|
// At what distance must we start accelerating/braking to reach target_speed from current_speed given the
|
|
|
|
// specified constant acceleration.
|
|
|
|
double estimate_acceleration_distance(double current_speed, double target_speed, double acceleration) {
|
2010-06-28 23:29:58 +02:00
|
|
|
return((target_speed*target_speed-current_speed*current_speed)/(2*acceleration));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate feed rate in length-units/second for a single axis
|
2011-01-14 12:10:18 +01:00
|
|
|
double axis_feed_rate(double steps_per_stepping, uint32_t stepping_rate, double steps_per_unit) {
|
2010-06-28 23:29:58 +02:00
|
|
|
if (stepping_rate == 0) { return(0.0); }
|
|
|
|
return((TICKS_PER_MICROSECOND*1000000)*steps_per_stepping/(stepping_rate*steps_per_unit));
|
|
|
|
}
|
|
|
|
|
2011-01-14 12:10:18 +01:00
|
|
|
// The 'swerve' of a joint is equal to the maximum acceleration of any single
|
2010-06-28 23:29:58 +02:00
|
|
|
// single axis in the corner between the outgoing and the incoming line. Accelleration control
|
|
|
|
// will regulate speed to avoid excessive swerve.
|
2011-01-14 12:10:18 +01:00
|
|
|
double calculate_swerve(struct Line* outgoing, struct Line* incoming) {
|
|
|
|
double x_swerve = abs(
|
2010-06-28 23:29:58 +02:00
|
|
|
axis_feed_rate(
|
2011-01-14 12:10:18 +01:00
|
|
|
((double)incoming->steps_x)/incoming->maximum_steps, incoming->rate, settings.steps_per_mm[X_AXIS])
|
2010-06-28 23:29:58 +02:00
|
|
|
- axis_feed_rate(
|
2011-01-14 12:10:18 +01:00
|
|
|
((double)incoming->steps_x)/incoming->maximum_steps, outgoing-> rate, settings.steps_per_mm[X_AXIS]));
|
|
|
|
double y_swerve = abs(
|
2010-06-28 23:29:58 +02:00
|
|
|
axis_feed_rate(
|
2011-01-14 12:10:18 +01:00
|
|
|
((double)incoming->steps_y)/incoming->maximum_steps, incoming->rate, settings.steps_per_mm[Y_AXIS])
|
2010-06-28 23:29:58 +02:00
|
|
|
- axis_feed_rate(
|
2011-01-14 12:10:18 +01:00
|
|
|
((double)incoming->steps_y)/incoming->maximum_steps, outgoing-> rate, settings.steps_per_mm[Y_AXIS]));
|
|
|
|
double z_swerve = abs(
|
2010-06-28 23:29:58 +02:00
|
|
|
axis_feed_rate(
|
2011-01-14 12:10:18 +01:00
|
|
|
((double)incoming->steps_z)/incoming->maximum_steps, incoming->rate, settings.steps_per_mm[Z_AXIS])
|
2010-06-28 23:29:58 +02:00
|
|
|
- axis_feed_rate(
|
2011-01-14 12:10:18 +01:00
|
|
|
((double)incoming->steps_z)/incoming->maximum_steps, outgoing-> rate, settings.steps_per_mm[Z_AXIS]));
|
2010-06-28 23:29:58 +02:00
|
|
|
return max(x_swerve, max(y_swerve, z_swerve));
|
|
|
|
}
|
|
|
|
|