Revert ea5b8942db2616e93fc0478922010c3bab7c0481^..HEAD
This commit is contained in:
parent
896a6b9199
commit
ed5e5d1181
7
gcode.c
7
gcode.c
@ -117,8 +117,7 @@ static double theta(double x, double y)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Executes one line of 0-terminated G-Code. The line is assumed to contain only uppercase
|
// Executes one line of 0-terminated G-Code. The line is assumed to contain only uppercase
|
||||||
// characters and signed floating point values (no whitespace). Comments and block delete
|
// characters and signed floating point values (no whitespace).
|
||||||
// characters have been removed.
|
|
||||||
uint8_t gc_execute_line(char *line) {
|
uint8_t gc_execute_line(char *line) {
|
||||||
uint8_t char_counter = 0;
|
uint8_t char_counter = 0;
|
||||||
char letter;
|
char letter;
|
||||||
@ -140,6 +139,10 @@ uint8_t gc_execute_line(char *line) {
|
|||||||
|
|
||||||
gc.status_code = STATUS_OK;
|
gc.status_code = STATUS_OK;
|
||||||
|
|
||||||
|
// Disregard comments and block delete
|
||||||
|
if (line[0] == '(') { return(gc.status_code); }
|
||||||
|
if (line[0] == '/') { char_counter++; } // ignore block delete
|
||||||
|
|
||||||
// Pass 1: Commands
|
// Pass 1: Commands
|
||||||
while(next_statement(&letter, &value, line, &char_counter)) {
|
while(next_statement(&letter, &value, line, &char_counter)) {
|
||||||
int_value = trunc(value);
|
int_value = trunc(value);
|
||||||
|
75
planner.c
75
planner.c
@ -80,42 +80,6 @@ static double intersection_distance(double initial_rate, double final_rate, doub
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
+--------+ <- nominal_rate
|
|
||||||
/ \
|
|
||||||
nominal_rate*entry_factor -> + \
|
|
||||||
| + <- nominal_rate*exit_factor
|
|
||||||
+-------------+
|
|
||||||
time -->
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Calculates trapezoid parameters so that the entry- and exit-speed is compensated by the provided factors.
|
|
||||||
// The factors represent a factor of braking and must be in the range 0.0-1.0.
|
|
||||||
|
|
||||||
static void calculate_trapezoid_for_block(block_t *block, double entry_factor, double exit_factor) {
|
|
||||||
block->initial_rate = ceil(block->nominal_rate*entry_factor);
|
|
||||||
block->final_rate = ceil(block->nominal_rate*exit_factor);
|
|
||||||
int32_t acceleration_per_minute = block->rate_delta*ACCELERATION_TICKS_PER_SECOND*60.0;
|
|
||||||
int32_t accelerate_steps =
|
|
||||||
ceil(estimate_acceleration_distance(block->initial_rate, block->nominal_rate, acceleration_per_minute));
|
|
||||||
int32_t decelerate_steps =
|
|
||||||
floor(estimate_acceleration_distance(block->nominal_rate, block->final_rate, -acceleration_per_minute));
|
|
||||||
|
|
||||||
// Calculate the size of Plateau of Nominal Rate.
|
|
||||||
int32_t plateau_steps = block->step_event_count-accelerate_steps-decelerate_steps;
|
|
||||||
|
|
||||||
// Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
|
|
||||||
// have to use intersection_distance() to calculate when to abort acceleration and start braking
|
|
||||||
// in order to reach the final_rate exactly at the end of this block.
|
|
||||||
if (plateau_steps < 0) {
|
|
||||||
accelerate_steps = ceil(
|
|
||||||
intersection_distance(block->initial_rate, block->final_rate, acceleration_per_minute, block->step_event_count));
|
|
||||||
plateau_steps = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
block->accelerate_until = accelerate_steps;
|
|
||||||
block->decelerate_after = accelerate_steps+plateau_steps;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
|
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
|
||||||
// acceleration within the allotted distance.
|
// acceleration within the allotted distance.
|
||||||
@ -146,6 +110,7 @@ static double factor_for_safe_speed(block_t *block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The kernel called by planner_recalculate() when scanning the plan from last to first entry.
|
// The kernel called by planner_recalculate() when scanning the plan from last to first entry.
|
||||||
static void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
static void planner_reverse_pass_kernel(block_t *previous, block_t *current, block_t *next) {
|
||||||
if(!current) { return; }
|
if(!current) { return; }
|
||||||
@ -235,6 +200,42 @@ static void planner_forward_pass() {
|
|||||||
planner_forward_pass_kernel(block[1], block[2], NULL);
|
planner_forward_pass_kernel(block[1], block[2], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
+--------+ <- nominal_rate
|
||||||
|
/ \
|
||||||
|
nominal_rate*entry_factor -> + \
|
||||||
|
| + <- nominal_rate*exit_factor
|
||||||
|
+-------------+
|
||||||
|
time -->
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Calculates trapezoid parameters so that the entry- and exit-speed is compensated by the provided factors.
|
||||||
|
// The factors represent a factor of braking and must be in the range 0.0-1.0.
|
||||||
|
static void calculate_trapezoid_for_block(block_t *block, double entry_factor, double exit_factor) {
|
||||||
|
block->initial_rate = ceil(block->nominal_rate*entry_factor);
|
||||||
|
block->final_rate = ceil(block->nominal_rate*exit_factor);
|
||||||
|
int32_t acceleration_per_minute = block->rate_delta*ACCELERATION_TICKS_PER_SECOND*60.0;
|
||||||
|
int32_t accelerate_steps =
|
||||||
|
ceil(estimate_acceleration_distance(block->initial_rate, block->nominal_rate, acceleration_per_minute));
|
||||||
|
int32_t decelerate_steps =
|
||||||
|
floor(estimate_acceleration_distance(block->nominal_rate, block->final_rate, -acceleration_per_minute));
|
||||||
|
|
||||||
|
// Calculate the size of Plateau of Nominal Rate.
|
||||||
|
int32_t plateau_steps = block->step_event_count-accelerate_steps-decelerate_steps;
|
||||||
|
|
||||||
|
// Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
|
||||||
|
// have to use intersection_distance() to calculate when to abort acceleration and start braking
|
||||||
|
// in order to reach the final_rate exactly at the end of this block.
|
||||||
|
if (plateau_steps < 0) {
|
||||||
|
accelerate_steps = ceil(
|
||||||
|
intersection_distance(block->initial_rate, block->final_rate, acceleration_per_minute, block->step_event_count));
|
||||||
|
plateau_steps = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
block->accelerate_until = accelerate_steps;
|
||||||
|
block->decelerate_after = accelerate_steps+plateau_steps;
|
||||||
|
}
|
||||||
|
|
||||||
// Recalculates the trapezoid speed profiles for all blocks in the plan according to the
|
// Recalculates the trapezoid speed profiles for all blocks in the plan according to the
|
||||||
// entry_factor for each junction. Must be called by planner_recalculate() after
|
// entry_factor for each junction. Must be called by planner_recalculate() after
|
||||||
// updating the blocks.
|
// updating the blocks.
|
||||||
@ -269,7 +270,7 @@ static void planner_recalculate_trapezoids() {
|
|||||||
// be performed using only the one, true constant acceleration, and where no junction jerk is jerkier than
|
// be performed using only the one, true constant acceleration, and where no junction jerk is jerkier than
|
||||||
// the set limit. Finally it will:
|
// the set limit. Finally it will:
|
||||||
//
|
//
|
||||||
// 3. Recalculate trapezoids for all blocks.
|
// 3. Recalculate trapezoids for all blocks using the recently updated factors
|
||||||
|
|
||||||
static void planner_recalculate() {
|
static void planner_recalculate() {
|
||||||
planner_reverse_pass();
|
planner_reverse_pass();
|
||||||
|
32
protocol.c
32
protocol.c
@ -72,36 +72,14 @@ uint8_t protocol_execute_line(char *line) {
|
|||||||
void protocol_process()
|
void protocol_process()
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
uint8_t iscomment = false;
|
|
||||||
while((c = serial_read()) != SERIAL_NO_DATA)
|
while((c = serial_read()) != SERIAL_NO_DATA)
|
||||||
{
|
{
|
||||||
if ((c == '\n') || (c == '\r')) { // End of block reached
|
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
|
||||||
if (char_counter > 0) {// Line is complete. Then execute!
|
line[char_counter] = 0; // treminate string
|
||||||
line[char_counter] = 0; // terminate string
|
|
||||||
status_message(protocol_execute_line(line));
|
status_message(protocol_execute_line(line));
|
||||||
} else {
|
char_counter = 0; // reset line buffer index
|
||||||
// Empty or comment line. Skip block.
|
} else if (c <= ' ') {
|
||||||
status_message(STATUS_OK); // Send status message for syncing purposes.
|
|
||||||
}
|
|
||||||
char_counter = 0; // Reset line buffer index
|
|
||||||
iscomment = false; // Reset comment flag
|
|
||||||
} else {
|
|
||||||
if (iscomment) {
|
|
||||||
// Throw away all comment characters
|
|
||||||
if (c == ')') {
|
|
||||||
// End of comment. Resume line.
|
|
||||||
iscomment = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (c <= ' ') {
|
|
||||||
// Throw away whitepace and control characters
|
// Throw away whitepace and control characters
|
||||||
} else if (c == '/') {
|
|
||||||
// Disable block delete and throw away character
|
|
||||||
// To enable block delete, uncomment following line. Will ignore until EOL.
|
|
||||||
// iscomment = true;
|
|
||||||
} else if (c == '(') {
|
|
||||||
// Enable comments flag and ignore all characters until ')' or EOL.
|
|
||||||
iscomment = true;
|
|
||||||
} else if (char_counter >= LINE_BUFFER_SIZE-1) {
|
} else if (char_counter >= LINE_BUFFER_SIZE-1) {
|
||||||
// Throw away any characters beyond the end of the line buffer
|
// Throw away any characters beyond the end of the line buffer
|
||||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||||
@ -111,5 +89,3 @@ void protocol_process()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user