Laser Cutter Build Night: It Works!!!!

After many unproductive and dissatisfying hours of trying to modify the code I downloaded off of here, I finally gave up, realized that the code was never going to work with my setup, and began to completely rewrite two of the files I downloaded.  If you look at the code, you will see that there are three files: Bipolar_Stepper_Motor_Class, Motor_control, and Gcode_executer.  I totally rewrote the first two.  Bascially, my code uses threaded programming in Python to make both axes move at the same time.  This is what makes diagonal lines instead of just a bunch of "staircase" lines imitating a diagonal line (these happen if you only drive one motor at once).  I will be posting my code very shortly; however, it isn't done yet, so I will wait on that.

Rewriting the code and testing it to debug it wasn't as hard as I thought.  I found that typing up a document in a text editor outlining what my code would do helped a lot.  It kept me on track and gave me some room to think about what the code actually had to do before jumping in.  I only had a few bugs to fix - division by zero (added an if statement to catch that case) and syntax errors.

When I tried the code, I was amazed to see that it actually worked!  It successfully drew the circle I told it to draw using G-code and even cut it at a reasonable pace instead of super-slowly!  Elated by my long-awaited success, I drew a sort of ninja star in a box using Inkscape and then converted it to G-code using the instructions provided here.  Amazingly, it worked!  Mostly, that is.  For some odd reason, the center circle of the ninja star and one of its arms were about an inch away from the real center of the ninja star.  I theorize that this could have been because of one axis getting stuck, because when the program went to the home position, it actually stopped about an inch away from the limit switches (still have to code those in).  What this means is that the code thought that the stepper was moving when in reality it wasn't; thus, when it told the motor to move x steps to go home, it didn't reach home because it the motor was farther from home than the software thought it was.

There are a few minor bugs to work out (besides fixing the sticking problem, or whatever else caused the ninja star misplacement).  I noticed that my circles I cut had flattish parts on them along one axis of movement.  I think that this is caused by the minor backlash issue I have - when one axis has reached the "vertex" of the circle along its axis of movement, it should turn around and start moving the other way.  Backlash causes it to go straight for a few hundred steps as the motor is rotating in its backlash.  Adding some simple code to detect change in direction should fix this.

Timing is another issue.  It was probably the biggest issue with the ready-made code, and it is possibly still a minor issue with mine.  Sometimes one axis will finish its movement to a point before the other finishes its movement to a point.  Additionally, when doing very small, detailed movements, the laser seems to move more slowly than when it is doing a "line drive" by moving a large distance in one move command.  I believe that this these issues are caused by minor mishaps in timing and tiny bits of lost time here and there in the thousands of start and stop movements required for fine detail.  I'll have to see if I can alleviate this issue; it may not be entirely correctable.