More '%' modulo opertor removals and some housecleaning.

- Serial functions contained quite a few modulo operations that would
be executed with high frequency when streaming. AVR processors are very
slow when operating these. In one test on the Arduino forums, it showed
about a 15x slow down compared to a simple if-then statement. -
Clarified some variable names and types and comments.
pull/1/head
Sonny J 2011-09-15 20:32:15 -06:00
rodzic 4d03c4febc
commit 110faae986
5 zmienionych plików z 19 dodań i 16 usunięć

Wyświetl plik

@ -328,7 +328,7 @@ uint8_t gc_execute_line(char *line) {
}
// Set clockwise/counter-clockwise sign for mc_arc computations
int8_t isclockwise = false;
uint8_t isclockwise = false;
if (gc.motion_mode == MOTION_MODE_CW_ARC) { isclockwise = true; }
// Trace the arc

Wyświetl plik

@ -48,7 +48,7 @@ void mc_dwell(uint32_t milliseconds)
// The arc is approximated by generating a huge number of tiny, linear segments. The length of each
// segment is configured in settings.mm_per_arc_segment.
void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, uint8_t axis_1,
uint8_t axis_linear, double feed_rate, uint8_t invert_feed_rate, double radius, int8_t isclockwise)
uint8_t axis_linear, double feed_rate, uint8_t invert_feed_rate, double radius, uint8_t isclockwise)
{
// int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
// plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
@ -106,7 +106,7 @@ void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, ui
double cos_T = 1-0.5*theta_per_segment*theta_per_segment; // Small angle approximation
double sin_T = theta_per_segment;
double trajectory[3];
double arc_target[3];
double sin_Ti;
double cos_Ti;
double r_axisi;
@ -114,7 +114,7 @@ void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, ui
int8_t count = 0;
// Initialize the linear axis
trajectory[axis_linear] = position[axis_linear];
arc_target[axis_linear] = position[axis_linear];
for (i = 1; i<segments; i++) { // Increment (segments-1)
@ -134,11 +134,11 @@ void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, ui
count = 0;
}
// Update trajectory location
trajectory[axis_0] = center_axis0 + r_axis0;
trajectory[axis_1] = center_axis1 + r_axis1;
trajectory[axis_linear] += linear_per_segment;
plan_buffer_line(trajectory[X_AXIS], trajectory[Y_AXIS], trajectory[Z_AXIS], feed_rate, invert_feed_rate);
// Update arc_target location
arc_target[axis_0] = center_axis0 + r_axis0;
arc_target[axis_1] = center_axis1 + r_axis1;
arc_target[axis_linear] += linear_per_segment;
plan_buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], feed_rate, invert_feed_rate);
}
// Ensure last segment arrives at target location.

Wyświetl plik

@ -38,10 +38,10 @@
#ifdef __AVR_ATmega328P__
// Execute an arc in offset mode format. position == current xyz, target == target xyz,
// offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is
// the direction of helical travel, radius == circle radius, clockwise_sign == -1 or 1. Used
// the direction of helical travel, radius == circle radius, isclockwise boolean. Used
// for vector transformation direction.
void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, uint8_t axis_1,
uint8_t axis_linear, double feed_rate, uint8_t invert_feed_rate, double radius, int8_t isclockwise);
uint8_t axis_linear, double feed_rate, uint8_t invert_feed_rate, double radius, uint8_t isclockwise);
#endif
// Dwell for a couple of time units

Wyświetl plik

@ -67,7 +67,8 @@ void serial_init(long baud)
void serial_write(uint8_t data) {
// Calculate next head
uint8_t next_head = (tx_buffer_head + 1) % TX_BUFFER_SIZE;
uint8_t next_head = tx_buffer_head + 1;
if (next_head == TX_BUFFER_SIZE) { next_head = 0; }
// Wait until there's a space in the buffer
while (next_head == tx_buffer_tail) { sleep_mode(); };
@ -90,7 +91,7 @@ SIGNAL(USART_UDRE_vect) {
// Update tail position
tail ++;
tail %= TX_BUFFER_SIZE;
if (tail == TX_BUFFER_SIZE) { tail = 0; }
// Turn off Data Register Empty Interrupt to stop tx-streaming if this concludes the transfer
if (tail == tx_buffer_head) { UCSR0B &= ~(1 << UDRIE0); }
@ -104,7 +105,8 @@ uint8_t serial_read()
return SERIAL_NO_DATA;
} else {
uint8_t data = rx_buffer[rx_buffer_tail];
rx_buffer_tail = (rx_buffer_tail + 1) % RX_BUFFER_SIZE;
rx_buffer_tail++;
if (rx_buffer_tail == RX_BUFFER_SIZE) { rx_buffer_tail = 0; }
return data;
}
}
@ -112,7 +114,8 @@ uint8_t serial_read()
SIGNAL(USART_RX_vect)
{
uint8_t data = UDR0;
uint8_t next_head = (rx_buffer_head + 1) % RX_BUFFER_SIZE;
uint8_t next_head = rx_buffer_head + 1;
if (next_head == RX_BUFFER_SIZE) { next_head = 0; }
// Write data to buffer unless it is full.
if (next_head != rx_buffer_tail) {

Wyświetl plik

@ -3,7 +3,7 @@
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
Copyright (c) 2011 Sungeun Jeon
Copyright (c) 2011 Sungeun K. Jeon
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by