diff --git a/config.h b/config.h index decf61d..c34171f 100644 --- a/config.h +++ b/config.h @@ -21,7 +21,7 @@ #ifndef config_h #define config_h -#define VERSION "0.0" +#define VERSION "0.5" #define X_STEPS_PER_MM (94.488188976378*16) #define Y_STEPS_PER_MM (94.488188976378*16) diff --git a/main.c b/main.c index 1083d31..b01d6a5 100644 --- a/main.c +++ b/main.c @@ -39,8 +39,6 @@ int main(void) gc_init(); // initialize gcode-parser sp_init(); // initialize the serial protocol - st_start(); // start the stepper subsystem - DDRD |= (1<<3)|(1<<4)|(1<<5); for(;;){ diff --git a/motion_control.c b/motion_control.c index 90fe6b2..e878411 100644 --- a/motion_control.c +++ b/motion_control.c @@ -40,27 +40,20 @@ #define ONE_MINUTE_OF_MICROSECONDS 60000000.0 -volatile int8_t mode; // The current operation mode int32_t position[3]; // The current position of the tool in absolute steps -uint8_t direction_bits; // The direction bits to be used with any upcoming step-instruction -void set_stepper_directions(int8_t *direction); inline void step_steppers(uint8_t bits); inline void step_axis(uint8_t axis); void prepare_linear_motion(uint32_t x, uint32_t y, uint32_t z, float feed_rate, int invert_feed_rate); void mc_init() { - mode = MC_MODE_AT_REST; clear_vector(position); } void mc_dwell(uint32_t milliseconds) { - mode = MC_MODE_DWELL; - st_synchronize(); - _delay_ms(milliseconds); - mode = MC_MODE_AT_REST; + st_buffer_line(0, 0, 0, milliseconds*1000); } // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second @@ -128,30 +121,6 @@ void mc_arc(double theta, double angular_travel, double radius, double linear_tr void mc_go_home() { - mode = MC_MODE_HOME; st_go_home(); - st_synchronize(); clear_vector(position); // By definition this is location [0, 0, 0] - mode = MC_MODE_AT_REST; -} - -int mc_status() -{ - return(mode); -} - -// Set the direction bits for the stepper motors according to the provided vector. -// direction is an array of three 8 bit integers representing the direction of -// each motor. The values should be negative (reverse), 0 or positive (forward). -void set_stepper_directions(int8_t *direction) -{ - /* Sorry about this convoluted code! It uses the fact that bit 7 of each direction - int is set when the direction == -1, but is 0 when direction is forward. This - way we can generate the whole direction bit-mask without doing any comparisions - or branching. Fast and compact, yet practically unreadable. Sorry sorry sorry. - */ - direction_bits = ( - ((direction[X_AXIS]&0x80)>>(7-X_DIRECTION_BIT)) | - ((direction[Y_AXIS]&0x80)>>(7-Y_DIRECTION_BIT)) | - ((direction[Z_AXIS]&0x80)>>(7-Z_DIRECTION_BIT))); } diff --git a/serial_protocol.c b/serial_protocol.c index f1cf29b..a4bbba5 100644 --- a/serial_protocol.c +++ b/serial_protocol.c @@ -26,40 +26,13 @@ #include #include "nuts_bolts.h" -#define LINE_BUFFER_SIZE 128 +#define LINE_BUFFER_SIZE 60 char line[LINE_BUFFER_SIZE]; -uint8_t line_counter; +uint8_t char_counter; void prompt() { printString("ok\r\n"); - line_counter = 0; -} - -void print_result() { - double position[3]; - int inches_mode; - uint8_t status_code; - uint32_t line_number; - int i; // loop variable - gc_get_status(position, &status_code, &inches_mode, &line_number); - printString("\r\n[ "); - for(i=X_AXIS; i<=Z_AXIS; i++) { - printInteger(trunc(position[i]*100)); - printByte(' '); - } - printByte(']'); - printByte('@'); - printInteger(line_number); - printByte(':'); - switch(status_code) { - case GCSTATUS_OK: printString("0 OK\r\n"); break; - case GCSTATUS_BAD_NUMBER_FORMAT: printString("1 Bad number format\r\n"); break; - case GCSTATUS_EXPECTED_COMMAND_LETTER: printString("2 Expected command letter\r\n"); break; - case GCSTATUS_UNSUPPORTED_STATEMENT: printString("3 Unsupported statement\r\n"); break; - case GCSTATUS_MOTION_CONTROL_ERROR: printString("4 Motion control error\r\n"); break; - case GCSTATUS_FLOATING_POINT_ERROR: printString("5 Floating point error\r\n"); break; - } } void sp_init() @@ -78,19 +51,15 @@ void sp_process() while((c = serialRead()) != -1) { if((c == '\n')) { // Line is complete. Then execute! - line[line_counter] = 0; - // printString("->"); - // printString(line); - // printString("<-\r\n"); + line[char_counter] = 0; gc_execute_line(line); - line_counter = 0; + char_counter = 0; prompt(); } else if (c <= ' ') { // Throw away whitepace and control characters } else if (c >= 'a' && c <= 'z') { // Upcase lowercase - line[line_counter++] = c-'a'+'A'; + line[char_counter++] = c-'a'+'A'; } else { - line[line_counter++] = c; + line[char_counter++] = c; } } } - diff --git a/serial_protocol.h b/serial_protocol.h index 27a9ed0..16bb448 100644 --- a/serial_protocol.h +++ b/serial_protocol.h @@ -27,8 +27,6 @@ // Initialize the serial protocol void sp_init(); -// Called by motion control just before the motion starts -void sp_send_execution_marker(); // Read command lines from the serial port and execute them as they // come in. Blocks until the serial buffer is emptied. void sp_process(); diff --git a/stepper.c b/stepper.c index ff41380..23eecba 100644 --- a/stepper.c +++ b/stepper.c @@ -33,7 +33,7 @@ #include "wiring_serial.h" #define TICKS_PER_MICROSECOND (F_CPU/1000000) -#define LINE_BUFFER_SIZE 8 +#define LINE_BUFFER_SIZE 10 struct Line { uint32_t steps_x, steps_y, steps_z; @@ -52,15 +52,11 @@ struct Line *current_line; volatile int32_t counter_x, counter_y, counter_z; uint32_t iterations; -uint8_t stepper_mode = STEPPER_MODE_STOPPED; - -void config_pace_timer(uint32_t microseconds); +void config_step_timer(uint32_t microseconds); // Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in // steps. Microseconds specify how many microseconds the move should take to perform. void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t microseconds) { - // Buffer nothing unless stepping subsystem is running - if (stepper_mode != STEPPER_MODE_RUNNING) { return; } // Calculate the buffer head after we push this byte int next_buffer_head = (line_buffer_head + 1) % LINE_BUFFER_SIZE; // If the buffer is full: good! That means we are well ahead of the robot. @@ -108,7 +104,7 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) PORTD ^= (1<<5); // Retrieve a new line and get ready to step it current_line = &line_buffer[line_buffer_tail]; - config_pace_timer(current_line->rate); + config_step_timer(current_line->rate); counter_x = -(current_line->maximum_steps/2); counter_y = counter_x; counter_z = counter_x; @@ -182,24 +178,21 @@ void st_init() TCCR2A = 0; // Normal operation TCCR2B = (1<