diff --git a/Makefile b/Makefile index 6f3de10..37b105e 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,10 @@ AVR_TOOLS_PATH = /usr/bin AVR_GCC_PATH = $(AVR_TOOLS_PATH) #Reasonable settings for Atmega1280 (regardless of board) -#UPLOAD_RATE = 57600 -#AVRDUDE_PROGRAMMER = stk500v1 -#PORT = /dev/ttyUSB0 -#MCU = atmega1280 +UPLOAD_RATE = 57600 +AVRDUDE_PROGRAMMER = stk500v1 +PORT = /dev/ttyUSB0 +MCU = atmega1280 #Reasonable settings for Atmega644p #UPLOAD_RATE = 38400 @@ -33,10 +33,10 @@ AVR_GCC_PATH = $(AVR_TOOLS_PATH) #MCU = atmega644p # Reasonable settings for Atmega2560 (regardless of board) -UPLOAD_RATE = 115200 -AVRDUDE_PROGRAMMER = stk500v2 -PORT = /dev/ttyACM0 -MCU = atmega2560 +#UPLOAD_RATE = 115200 +#AVRDUDE_PROGRAMMER = stk500v2 +#PORT = /dev/ttyACM0 +#MCU = atmega2560 diff --git a/Motion.cpp b/Motion.cpp index c61edb6..23042b3 100644 --- a/Motion.cpp +++ b/Motion.cpp @@ -385,19 +385,24 @@ void Motion::gcode_precalc(GCode& gcode, float& feedin, Point* lastend) // Diverent moves need to be handled specially. -void Motion::fix_diverge(float *ends, float *starts) -{ - float dA = fabs(ends[0] - ends[1]); - float dB = fabs(starts[0] - starts[1]); +// Divergent moves are ones where one axis is increasing in speed, while another is +// decreasing. This means if we blindly adjust one side, then the other, as we do, +// the second adjustment is likely to bring the first adjustment out of whack. +// So here we basically limit speed to the maximum speed from which it's impossible to go out of whack. +// TODO: Don't assume all diverence is on XY +void Motion::fix_diverge(int32_t *ends, int32_t *starts) +{ + int32_t dA = labs(ends[0] - ends[1]); + int32_t dB = labs(starts[0] - starts[1]); if(dA > AXES[0].getStartFeed() + dB) { - float ar = (AXES[0].getStartFeed() + dB) / dA; + float ar = (float)(AXES[0].getStartFeed() + dB) / (float)dA; if(ar < 1) { for(int ax=0;ax=0) != (ends[ax] >= 0)) desired = jump; - ar = desired / fabs(ends[ax]); + ar = float(desired) / fabs(ends[ax]); if(ar < ratio) { @@ -437,13 +446,17 @@ void Motion::join_moves(float *ends, float *starts) } for(int ax=0;ax= startspeeds[ax]) diverge++; else diverge--; } - // in diverence, lower each side so diverin axis speeds are within jump + opposite sides diverence - // TODO: Don't assume all diverence is on XY - + // in diverence, lower the divergent side(s) to a safe speed. if(diverge != NUM_AXES) { #ifdef DEBUG_OPT HOST.write("diverge.\n"); #endif + // Fix this move to be acceptably divergent for the next move. fix_diverge(endspeeds,startspeeds); + // Fix the next move to be acceptably divergent for this move. fix_diverge(startspeeds,endspeeds); } + // Calculate the end speeds (of this move) we can use to meet the start speeds (of the next move). join_moves(endspeeds,startspeeds); - -#ifdef DEBUG_LAME - for(int ax=0;ax", endspeeds[ax],false); - HOST.labelnum(", ", startspeeds[ax],false); - HOST.labelnum("->", nextspeeds[ax], false); - HOST.labelnum(" @jump:", AXES[ax].getStartFeed()); - } -#endif - + // Calculate the start speeds (of the next move) we can use to meet the end speeds (of this move) join_moves(startspeeds,endspeeds); + #ifdef DEBUG_OPT for(int ax=0;ax 1 && speedto0 < gcode.endfeed) + if(speedto0 < endspeeds[gcode.leading_axis]) { #ifdef DEBUG_OPT - HOST.labelnum("st0end:",gcode.endfeed,false); - HOST.labelnum(",",speedto0); + HOST.labelnum("st0end:",speedto0); #endif - gcode.endfeed = speedto0; - nextg.startfeed = gcode.endfeed / gcode.axisratio[nextg.leading_axis]; + endspeeds[gcode.leading_axis] = speedto0; } + gcode.endfeed = max(gcode.endfeed,labs(endspeeds[gcode.leading_axis])); + nextg.startfeed = max(nextg.startfeed,labs(startspeeds[nextg.leading_axis])); + // because we only lookahead one move, our maximum exit speed has to be either the desired + // exit speed or the speed that the next move can reach to 0 (0+jerk, actually) during. + computeAccel(gcode, &nextg); #endif // LOOKAHEAD } +// This computes an acceleration curve, given requested start, max, and end speeds for a move. +// Optimally, also pass the next move, and it will adjust the start speed there to match the +// actual speeds we can achieve < max. void Motion::computeAccel(GCode& gcode, GCode* nextg) { if(gcode[G].isUnused() || gcode[G].getInt() != 1) @@ -683,6 +689,8 @@ void Motion::computeAccel(GCode& gcode, GCode* nextg) #endif } + +// Takes the next queued gcode and begins running it. void Motion::gcode_execute(GCode& gcode) { // Only execute codes that are prepared. @@ -706,12 +714,13 @@ void Motion::gcode_execute(GCode& gcode) return; } - // set axis move data, invalidate all precomputes if bad data + // Prepare axis move data -- Invalidate all precomputes if bad data (happens on hitting an endstop) for(int ax=0;axmovesteps = 0; @@ -901,6 +915,8 @@ void Motion::disableInterrupt() TIMSK1 &= ~(_BV(OCIE1A)); } +// With a 16-bit timer operating at 1:1 with the clock, +// we have to verflow at 0xFFFF, thus the 60000 check below. void Motion::setInterruptCycles(unsigned long cycles) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) diff --git a/Motion.h b/Motion.h index d2eabb8..958b709 100644 --- a/Motion.h +++ b/Motion.h @@ -103,8 +103,8 @@ class Motion float getSmallestEndFeed(GCode& gcode); // opt support - void fix_diverge(float *ends, float* starts); - void join_moves(float *ends, float* starts); + void fix_diverge(int32_t *ends, int32_t* starts); + void join_moves(int32_t *ends, int32_t* starts); diff --git a/config-common.h b/config-common.h index 1f6d3e9..324107d 100644 --- a/config-common.h +++ b/config-common.h @@ -12,9 +12,9 @@ #define HOST_RECV_BUFSIZE 100 #define HOST_SEND_BUFSIZE 100 #else -#define GCODE_BUFSIZE 5 +#define GCODE_BUFSIZE 15 #define HOST_RECV_BUFSIZE 200 -#define HOST_SEND_BUFSIZE 2000 +#define HOST_SEND_BUFSIZE 200 #endif // Each source eats anough ram for 1 addtl gcode @@ -47,9 +47,9 @@ #define ACCEL_INC_TIME F_CPU/ACCELS_PER_SECOND //#define COMMS_ERR2 -#define DEBUG_OPT -#define DEBUG_MOVE -#define DEBUG_ACCEL +//#define DEBUG_OPT +//#define DEBUG_MOVE +//#define DEBUG_ACCEL #define BT_BAUD 9600 //#define BT_DEBUG diff --git a/util/host.pl b/util/host.pl index 855b81b..874368c 100755 --- a/util/host.pl +++ b/util/host.pl @@ -62,6 +62,7 @@ ($$) +my $t1 = time(); my $line = ''; while(1) @@ -104,8 +105,11 @@ ($$) my $char; if(sysread(STDIN,$char,1) != 1) { - die("All done.\n"); + my $t2 = time(); + my $mins = ($t2 - $t1) / 60; + printf("All done - took %4.4f mins.\n", $mins); sleep(30); # temporary hack + die("Finish."); } $line .= $char; if($char eq "\n")