[attach]442143[/attach]
在GRBL0.8中,单个线段的运动数据定义在block_t中。线段数据共分个三部分,第一部分用于bresenham 算法,第二部分第三部分用于对速度的控制,
前瞻算法能提前计算6-8个线段的运动数据,(BLOCK_BUFFER_SIZE=18),定时器驱动步进电机的时候,只需简单调用这些运动数据,无需复杂的计算。 typedef struct {
// Fields used by the bresenham algorithm for tracing the line 第一部分,用于bresenham 算法①
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
//轴运转方向
uint32_t steps_x, steps_y, steps_z; // Step count along each axis
//轴运转步数
int32_t step_event_count; // The number of step events required to complete this block
//总步数
// Fields used by the motion planner to manage acceleration 第二部分,用于mm/min速度②
// 这部分速度_speed单位为mm/min
float nominal_speed; // The nominal speed for this block in mm/min 正常速度,mm/分
float entry_speed; // Entry speed at previous-current block junction in mm/min起始速度,mm/分
float max_entry_speed; // Maximum allowable junction entry speed in mm/min最大转角速度,mm/分
float millimeters; // The total travel of this block in mm 总距离,mm
uint8_t recalculate_flag; // Planner flag to recalculate trapezoids on entry junction 重新计算标记
uint8_t nominal_length_flag; // Planner flag for nominal speed always reached
//= true表示该线段速度有平台期,就是说可以加速到正常速度
// Settings for the trapezoid generator 第三部分,用于梯形加速度③
// 这部分速度_rate单位为step_events/minute
uint32_t initial_rate; // The step rate at start of block 开始速度,步/分
uint32_t final_rate; // The step rate at end of block结束速度,步/分
int32_t rate_delta; // The steps/minute to add or subtract when changing speed (must be positive)
//在改变速度时需要要增加或减去的速度,加速度的斜率,步/分钟
uint32_t accelerate_until; // The index of the step event on which to stop acceleration
//加速段的步数
uint32_t decelerate_after; // The index of the step event on which to start decelerating
//减速段的步数=停止加速+平台期步数
uint32_t nominal_rate; // The nominal step rate for this block in step_events/minute
//步/分,这个块的标称步进速率