MarginallyClever / GcodeCNCDemo

a simple example of making a CNC machine from an Adafruit Motor Shield
213 stars 133 forks source link

Fix serialBuffer, parseNumber errors and add Stepper.h driver #33

Closed drf5n closed 2 years ago

drf5n commented 2 years ago

This is a PR to fix https://github.com/MarginallyClever/GcodeCNCDemo/issues/29 and parts of https://github.com/MarginallyClever/GcodeCNCDemo/issues/28

It:

These changes make it compile for Arduino and the Wokwi simulator.

See https://wokwi.com/projects/327748577668366932

image
drf5n commented 2 years ago

With those changes, all of the codes appear to compile in Arduino IDE.

The code will compile in Wokwi, but since only 4-wire steppers are available so far, ( https://github.com/wokwi/wokwi-features/issues/191#issuecomment-1085187294 ) the multi-axis code depending on step-dir type drivers won't have steppers to control. For example: ### https://wokwi.com/projects/327767540778402388

i-make-robots commented 2 years ago

I'm with you in spirit. why rename parseNumber and serialBuffer?

drf5n commented 2 years ago

In several of the codes, serialBuffer is filled with assignments into buffer, and parseNumber is called by parsenumber For example:

https://github.com/MarginallyClever/GcodeCNCDemo/blob/5209a601d3b4c5b3c07fa50f90f5fe7098efa822/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino#L14

https://github.com/MarginallyClever/GcodeCNCDemo/blob/5209a601d3b4c5b3c07fa50f90f5fe7098efa822/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino#L312-L315

https://github.com/MarginallyClever/GcodeCNCDemo/blob/5209a601d3b4c5b3c07fa50f90f5fe7098efa822/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino#L238-L277

versus

https://github.com/MarginallyClever/GcodeCNCDemo/blob/5209a601d3b4c5b3c07fa50f90f5fe7098efa822/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino#L179-L181

Left uncorrected, they fail to compile with errors like:

/Users/drf/Work/GcodeCNCDemo/GcodeCNCDemo2Axis/HG7881.ino:10:1: warning: multi-line comment [-Wcomment]
 // * to reduce and avoid overheat on HG7881, use M18 after every G00, G01, G02, G03 on Gcode * \\
 ^
/Users/drf/Work/GcodeCNCDemo/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino: In function 'float parseNumber(char, float)':
GcodeCNCDemo2Axis:180:13: error: 'serialBuffer' was not declared in this scope
   char *ptr=serialBuffer;  // start at the beginning of buffer
             ^~~~~~~~~~~~
/Users/drf/Work/GcodeCNCDemo/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino: In function 'void processCommand()':
GcodeCNCDemo2Axis:239:13: error: 'parsenumber' was not declared in this scope
   int cmd = parsenumber('G',-1);
             ^~~~~~~~~~~
/Users/drf/Work/GcodeCNCDemo/GcodeCNCDemo2Axis/GcodeCNCDemo2Axis.ino:239:13: note: suggested alternative: 'parseNumber'
   int cmd = parsenumber('G',-1);
             ^~~~~~~~~~~
             parseNumber
Using library AFMotorDrawbot in folder: /Users/drf/Documents/Arduino/libraries/AFMotorDrawbot (legacy)
exit status 1
'serialBuffer' was not declared in this scope

I see that the newer codes, like GcodeCNCDemo6AxisRumbaTimerInterrupt.ino use serialBuffer and parseNumber

https://github.com/MarginallyClever/GcodeCNCDemo/blob/5209a601d3b4c5b3c07fa50f90f5fe7098efa822/GcodeCNCDemo6AxisRumbaTimerInterrupt/GcodeCNCDemo6AxisRumbaTimerInterrupt.ino#L113

https://github.com/MarginallyClever/GcodeCNCDemo/blob/5209a601d3b4c5b3c07fa50f90f5fe7098efa822/GcodeCNCDemo6AxisRumbaTimerInterrupt/GcodeCNCDemo6AxisRumbaTimerInterrupt.ino#L513

...but the older ones are a mix.

drf5n commented 2 years ago

With these changes, they all compile on a mega:

GcodeCNCDemo2Axis:

Sketch uses 11218 bytes (4%) of program storage space. Maximum is 253952 bytes.
Global variables use 350 bytes (4%) of dynamic memory, leaving 7842 bytes for local variables. Maximum is 8192 bytes.

GcodeCNCDemo4AxisCNCShield:

Sketch uses 8878 bytes (3%) of program storage space. Maximum is 253952 bytes.
Global variables use 436 bytes (5%) of dynamic memory, leaving 7756 bytes for local variables. Maximum is 8192 bytes.

GcodeCNCDemo4AxisRAMPS

Sketch uses 8894 bytes (3%) of program storage space. Maximum is 253952 bytes.
Global variables use 436 bytes (5%) of dynamic memory, leaving 7756 bytes for local variables. Maximum is 8192 bytes.

GcodeCNCDemo4axisV2

Sketch uses 14696 bytes (5%) of program storage space. Maximum is 253952 bytes.
Global variables use 778 bytes (9%) of dynamic memory, leaving 7414 bytes for local variables. Maximum is 8192 bytes.

GcodeCNCDemo6AxisRumba

Sketch uses 11962 bytes (4%) of program storage space. Maximum is 253952 bytes.
Global variables use 488 bytes (5%) of dynamic memory, leaving 7704 bytes for local variables. Maximum is 8192 bytes.

GcodeCNCDemo6AxisRumbaTimerInterrupt

Sketch uses 12800 bytes (5%) of program storage space. Maximum is 253952 bytes.
Global variables use 4094 bytes (49%) of dynamic memory, leaving 4098 bytes for local variables. Maximum is 8192 bytes.

GcodeCNCDemo6AxisV2

Sketch uses 14848 bytes (5%) of program storage space. Maximum is 253952 bytes.
Global variables use 886 bytes (10%) of dynamic memory, leaving 7306 bytes for local variables. Maximum is 8192 bytes.
i-make-robots commented 2 years ago

Nice. Personally I would have kept the camelCasing and the longer serialBuffer (says more about what it does) but I'm not going to look a gift horse in the mouth.

Thank you!

drf5n commented 2 years ago

Nice. Personally I would have kept the camelCasing and the longer serialBuffer (says more about what it does) but I'm not going to look a gift horse in the mouth.

Thank you!

You're welcome.

Yeah it would be nicer to have it all consistent, but I started from the 2 Axis code, and un-camel-casing the function and going with the less descriptive buffer name looked like a less invasive change.

Maybe I'll do a global search & replace and do another PR to regularize them.