Skip to content

Commit

Permalink
Yet another major stepper algorithm and planner overhaul.
Browse files Browse the repository at this point in the history
- Overhauled the stepper algorithm and planner again. This time
concentrating on the decoupling of the stepper ISR completely. It is
now dumb, relying on the segment generator to provide the number of
steps to execute and how fast it needs to go. This freed up lots of
memory as well because it made a lot tracked variables obsolete.

- The segment generator now computes the velocity profile of the
executing planner block on the fly in floating point math, instead of
allowing the stepper algorithm to govern accelerations in the previous
code. What this accomplishes is the ability and framework to (somewhat)
easily install a different physics model for generating a velocity
profile, i.e. s-curves.

- Made some more planner enhancements and increased efficiency a bit.

- The changes also did not increase the compiled size of Grbl, but
decreased it slightly as well.

- Cleaned up a lot of the commenting.

- Still much to do, but this push works and still is missing feedholds
(coming next.)
  • Loading branch information
chamnit committed Nov 23, 2013
1 parent 2eb5aca commit b36e30d
Show file tree
Hide file tree
Showing 15 changed files with 4,706 additions and 719 deletions.
669 changes: 669 additions & 0 deletions archive/planner_dist.c

Large diffs are not rendered by default.

459 changes: 459 additions & 0 deletions archive/planner_time_archive.c

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
706 changes: 706 additions & 0 deletions archive/stepper_dist.c

Large diffs are not rendered by default.

File renamed without changes.
775 changes: 775 additions & 0 deletions archive/stepper_time.c

Large diffs are not rendered by default.

823 changes: 823 additions & 0 deletions archive/stepper_time_archive.c

Large diffs are not rendered by default.

File renamed without changes.
12 changes: 10 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
// CNC applications, the following multiplier value will work more than well enough. If you do have
// happened to weird stepper motion issues, try modifying this value by adding or subtracting a
// zero and report it to the Grbl administrators.
#define INV_TIME_MULTIPLIER 10000000.0
#define INV_TIME_MULTIPLIER 100000

// Minimum stepper rate for the "Stepper Driver Interrupt". Sets the absolute minimum stepper rate
// in the stepper program and never runs slower than this value. If the INVE_TIME_MULTIPLIER value
// changes, it will affect how this value works. So, if a zero is add/subtracted from the
// INV_TIME_MULTIPLIER value, do the same to this value if you want to same response.
// NOTE: Compute by (desired_step_rate/60) * INV_TIME_MULTIPLIER/ISR_TICKS_PER_SECOND. (mm/min)
#define MINIMUM_STEP_RATE 1000L // Integer (mult*mm/isr_tic)
// #define MINIMUM_STEP_RATE 1000L // Integer (mult*mm/isr_tic)

// Minimum stepper rate. Only used by homing at this point. May be removed in later releases.
#define MINIMUM_STEPS_PER_MINUTE 800 // (steps/min) - Integer value only
Expand Down Expand Up @@ -161,6 +161,14 @@
// up with planning new incoming motions as they are executed.
// #define BLOCK_BUFFER_SIZE 18 // Uncomment to override default in planner.h.

// Governs the size of the intermediary step segment buffer between the step execution algorithm
// and the planner blocks. Each segment is set of steps executed at a constant velocity over a
// fixed time defined by ACCELERATION_TICKS_PER_SECOND. They are computed such that the planner
// block velocity profile is traced exactly. The size of this buffer governs how much step
// execution lead time there is for other Grbl processes have to compute and do their thing
// before having to come back and refill this buffer, currently at ~50msec of step moves.
// #define SEGMENT_BUFFER_SIZE 7 // Uncomment to override default in stepper.h.

// Line buffer size from the serial input stream to be executed. Also, governs the size of
// each of the startup blocks, as they are each stored as a string of this size. Make sure
// to account for the available EEPROM at the defined memory address in settings.h and for
Expand Down
385 changes: 76 additions & 309 deletions planner.c

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ typedef struct {
// Fields used by the bresenham algorithm for tracing the line
// NOTE: Do not change any of these values once set. The stepper algorithm uses them to execute the block correctly.
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
int32_t steps[N_AXIS]; // Step count along each axis
int32_t step_event_count; // The maximum step axis count and number of steps required to complete this block.
int32_t steps[N_AXIS]; // Step count along each axis
int32_t step_event_count; // The maximum step axis count and number of steps required to complete this block.

// Fields used by the motion planner to manage acceleration
float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2
float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and
// neighboring nominal speeds with overrides in (mm/min)^2
float max_junction_speed_sqr; // Junction entry speed limit based on direction vectors in (mm/min)^2
float nominal_speed_sqr; // Axis-limit adjusted nominal speed for this block in (mm/min)^2
float acceleration; // Axis-limit adjusted line acceleration in mm/min^2
float millimeters; // The remaining distance for this block to be executed in mm
float acceleration; // Axis-limit adjusted line acceleration in (mm/min^2)
float millimeters; // The remaining distance for this block to be executed in (mm)

} plan_block_t;


// Initialize the motion plan subsystem
void plan_init();
Expand All @@ -64,13 +65,11 @@ void plan_discard_current_block();
// Gets the current block. Returns NULL if buffer empty
plan_block_t *plan_get_current_block();

// Called periodically by step segment buffer. Mostly used internally by planner.
uint8_t plan_next_block_index(uint8_t block_index);

plan_block_t *plan_get_block_by_index(uint8_t block_index);

float plan_calculate_velocity_profile(uint8_t block_index);

// void plan_update_partial_block(uint8_t block_index, float millimeters_remaining, uint8_t is_decelerating);
// Called by step segment buffer when computing executing block velocity profile.
float plan_get_exec_block_exit_speed();

// Reset the planner position vector (in steps)
void plan_sync_position();
Expand Down
Loading

0 comments on commit b36e30d

Please sign in to comment.