kopia lustrzana https://github.com/gnea/grbl
improved the serial protocol, added some debug pins for a while
rodzic
551b4ed274
commit
36fd3a9bfb
2
main.c
2
main.c
|
@ -41,6 +41,8 @@ int main(void)
|
|||
|
||||
st_start(); // start the stepper subsystem
|
||||
|
||||
DDRD |= (1<<3)|(1<<4)|(1<<5);
|
||||
|
||||
for(;;){
|
||||
sleep_mode();
|
||||
sp_process(); // process the serial protocol
|
||||
|
|
|
@ -90,34 +90,44 @@ void mc_line(double x, double y, double z, float feed_rate, int invert_feed_rate
|
|||
maximum_steps; // The larges absolute step-count of any axis
|
||||
|
||||
// Setup ---------------------------------------------------------------------------------------------------
|
||||
|
||||
PORTD |= (1<<4);
|
||||
PORTD |= (1<<5);
|
||||
target[X_AXIS] = round(x*X_STEPS_PER_MM);
|
||||
target[Y_AXIS] = round(y*Y_STEPS_PER_MM);
|
||||
target[Z_AXIS] = round(z*Z_STEPS_PER_MM);
|
||||
PORTD ^= (1<<5);
|
||||
// Determine direction and travel magnitude for each axis
|
||||
for(axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
||||
step_count[axis] = labs(target[axis] - position[axis]);
|
||||
direction[axis] = signof(target[axis] - position[axis]);
|
||||
}
|
||||
PORTD ^= (1<<5);
|
||||
// Find the magnitude of the axis with the longest travel
|
||||
maximum_steps = max(step_count[Z_AXIS],
|
||||
max(step_count[X_AXIS], step_count[Y_AXIS]));
|
||||
PORTD ^= (1<<5);
|
||||
// Nothing to do?
|
||||
if (maximum_steps == 0) { return; }
|
||||
if (maximum_steps == 0) { PORTD &= ~(1<<4); PORTD |= (1<<5); return; }
|
||||
PORTD ^= (1<<5);
|
||||
// Set up a neat counter for each axis
|
||||
for(axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
||||
counter[axis] = -maximum_steps/2;
|
||||
}
|
||||
PORTD ^= (1<<5);
|
||||
// Set our direction pins
|
||||
set_stepper_directions(direction);
|
||||
PORTD ^= (1<<5);
|
||||
|
||||
// Ask old Phytagoras to estimate how many mm our next move is going to take us
|
||||
double millimeters_of_travel =
|
||||
sqrt(square(X_STEPS_PER_MM*step_count[X_AXIS]) +
|
||||
square(Y_STEPS_PER_MM*step_count[Y_AXIS]) +
|
||||
square(Z_STEPS_PER_MM*step_count[Z_AXIS]));
|
||||
PORTD ^= (1<<5);
|
||||
// And set the step pace
|
||||
compute_and_set_step_pace(feed_rate, millimeters_of_travel, maximum_steps, invert_feed_rate);
|
||||
PORTD &= ~(1<<5);
|
||||
PORTD &= ~(1<<4);
|
||||
|
||||
// Execution -----------------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ void sp_process()
|
|||
char c;
|
||||
while((c = serialRead()) != -1)
|
||||
{
|
||||
if((c < 32)) { // Line is complete. Then execute!
|
||||
if((c == '\n')) { // Line is complete. Then execute!
|
||||
line[line_counter] = 0;
|
||||
// printString("->");
|
||||
// printString(line);
|
||||
|
@ -85,7 +85,7 @@ void sp_process()
|
|||
gc_execute_line(line);
|
||||
line_counter = 0;
|
||||
prompt();
|
||||
} else if (c == ' ' || c == '\t') { // Throw away whitepace
|
||||
} else if (c <= ' ') { // Throw away whitepace and control characters
|
||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||
line[line_counter++] = c-'a'+'A';
|
||||
} else {
|
||||
|
|
|
@ -53,6 +53,7 @@ void config_pace_timer(uint32_t microseconds);
|
|||
SIGNAL(SIG_OUTPUT_COMPARE1A)
|
||||
{
|
||||
if (step_buffer_head != step_buffer_tail) {
|
||||
PORTD &= ~(1<<3);
|
||||
uint8_t popped = step_buffer[step_buffer_tail];
|
||||
if(popped == PACE_CHANGE_MARKER) {
|
||||
// This is not a step-instruction, but a pace-change-marker: change pace
|
||||
|
@ -69,6 +70,8 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
|
|||
}
|
||||
// move the step buffer tail to the next instruction
|
||||
step_buffer_tail = (step_buffer_tail + 1) % STEP_BUFFER_SIZE;
|
||||
} else {
|
||||
PORTD |= (1<<3);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue