Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for WAVGAT boards #1

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# Horus 3D Scanner Firmware

This firmware is written in C. Version 0.2.
# Horus 3D Scanner Firmware for WAVGAT + ZUMSCAN boards

This firmware is derived from Horus firmware v 2.0
Derived from Grbl v0.9 by Jesús Arroyo (Mundo Reader S.L.)

Grbl's lead developer is Simen Svale Skogsrud. Sonney Jeon (Chamnit) improved some parts of grbl.

Firmware adds extra initialization code to setup WAVGAT boards.
It also should be compatible with generic arduino boards.

This firmware get back some grbl features stripped out by Horus/Ciclop:
- multiple axis support (X,Y,Z)
- limit switches and homing
- G0, G4 G Codes support

So you can use this firmware with your experimental hardware.

To use second stepper on ZUMSCAN shield with this firmware it is needed to rewire two pins on the shield board:
- desolder or cut pins 6,7 on ZUMSCAN shield so they not connected to arduino
- wire 6->9, 7->10


## Features

Expand All @@ -14,13 +26,16 @@ Grbl's lead developer is Simen Svale Skogsrud. Sonney Jeon (Chamnit) improved so
* Laser modules control
* Analog sensor read
* Configuration interface with $ commands
* Up to 3 steppers
* Use limit switches

The default baudrate is 115200.


## Implemented G Codes

* G1 - Angular movement
* G0,G1- Angular movement
* G4 - Dwell (delay)
* G50 - Reset all positions to zero
* M0 - Program pause
* M2 - Program end and reset
Expand All @@ -34,7 +49,20 @@ The default baudrate is 115200.

### Arduino

Open *horus-fw.ino*, select your board and upload.
Open *horus-fw.ino*, select your board

Adjust configuration for your hardware:

- axis resolution (defaults.h, section DEFAULTS_HORUS)
For Ciclop hardware with Nema-17 stepper and x16 microstepping driver
DEFAULT_X_STEPS_PER_DEG 16\*200/360 // step/deg

- limit switches
cpu_map.h, section CPU_MAP_ATMEGA328P_ZUMSCAN: adjust limit switches pins. More detailed info in cpu_map.h
config.h: homing probe order and params HOMING_INIT_LOCK, HOMING_CYCLE_\*, N_HOMING_LOCATE_CYCLE


Build and upload.

### Make

Expand Down
8 changes: 5 additions & 3 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@

// Default cpu mappings. Grbl officially supports the Arduino Uno only. Other processor types
// may exist from user-supplied templates or directly user-defined in cpu_map.h
#define CPU_MAP_ATMEGA328P_HORUS // Arduino Uno CPU for Horus Project
//#define CPU_MAP_ATMEGA328P_HORUS // Arduino Uno CPU for Horus Project
#define CPU_MAP_ATMEGA328P_ZUMSCAN

// Define runtime command special characters. These characters are 'picked-off' directly from the
// serial read data stream and are not passed to the grbl line execution parser. Select characters
Expand Down Expand Up @@ -84,9 +85,10 @@
// on separate pin, but homed in one cycle. Also, it should be noted that the function of hard limits
// will not be affected by pin sharing.
// NOTE: Defaults are set for a traditional 3-axis CNC machine. Z-axis first to clear, followed by X & Y.
#define HOMING_CYCLE_0 (1<<Z_AXIS) // REQUIRED: First move Z to clear workspace.
#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) // OPTIONAL: Then move X,Y at the same time.
//#define HOMING_CYCLE_0 (1<<Z_AXIS) // REQUIRED: First move Z to clear workspace.
//#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) // OPTIONAL: Then move X,Y at the same time.
// #define HOMING_CYCLE_2 // OPTIONAL: Uncomment and add axes mask to enable
#define HOMING_CYCLE_0 (1<<Y_AXIS) // HORUS: X is turntable, homing not required. Home Y axis

// Number of homing cycles performed after when the machine initially jogs to limit switches.
// This help in preventing overshoot and should improve repeatability. This value should be one or
Expand Down
60 changes: 60 additions & 0 deletions cpu_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,66 @@

#endif

#ifdef CPU_MAP_ATMEGA328P_ZUMSCAN // Arduino Uno + ZUM Scan board

// Define laser pulse output pins. NOTE: All laser pins must be on the same port.
#define LASER_DDR DDRD
#define LASER_PORT PORTD
#define LASER1_BIT 2 // Uno Digital Pin 2
#define LASER2_BIT 3 // Uno Digital Pin 3
#define LASER3_BIT 4 // Uno Digital Pin 4
#define LASER4_BIT 5 // Uno Digital Pin 5
#define LASER_MASK ((1<<LASER1_BIT)|(1<<LASER2_BIT)|(1<<LASER3_BIT)|(1<<LASER4_BIT)) // All step bits

// Define serial port pins and interrupt vectors.
#define SERIAL_RX USART_RX_vect
#define SERIAL_UDRE USART_UDRE_vect

// Define step pulse output pins. NOTE: All step bit pins must be on the same port.
#define STEP_DDR DDRB
#define STEP_PORT PORTB
#define X_STEP_BIT 4 // Uno Digital Pin 12
#define Y_STEP_BIT 2 // Uno Digital Pin 10 rewired from 7
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)) // All step bits

// Define step direction output pins. NOTE: All direction pins must be on the same port.
#define DIRECTION_DDR DDRB
#define DIRECTION_PORT PORTB
#define X_DIRECTION_BIT 5 // Uno Digital Pin 13
#define Y_DIRECTION_BIT 0 // Uno Digital Pin 8
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)) // All direction bits

// Define stepper driver enable/disable output pin.
#define STEPPERS_DISABLE_DDR DDRB
#define STEPPERS_DISABLE_PORT PORTB
#define STEPPERS_DISABLE_BIT 1 // Uno Digital Pin 9 + rewired pin 6
#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)

// Define homing/hard limit switch input pins and limit interrupt vectors.
// NOTE: All limit bit pins must be on the same port, but not on a port with other input pins (pinout).
// https://github.com/gnea/grbl/wiki/Wiring-Limit-Switches

#define LIMIT_DDR DDRB
#define LIMIT_PIN PINB
#define LIMIT_PORT PORTB
// #define X_LIMIT_BIT 1 // Uno Digital Pin 9
#define Y_LIMIT_BIT 3 // Uno Digital Pin 11
#define LIMIT_MASK (1<<Y_LIMIT_BIT) //((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // All limit bits
#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
#define LIMIT_INT_vect PCINT0_vect // PCINT0_vect - D8 to D13 (Port B); PCINT1_vect - A0 to A5; PCINT2_vect - D0 to D7 (Port D)
#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register

// Define probe switch input pin.
#define PROBE_DDR DDRC
#define PROBE_PIN PINC
#define PROBE_PORT PORTC
#define PROBE_BIT 5 // Uno Analog Pin 5
#define PROBE_MASK (1<<PROBE_BIT)

#endif

//----------------------------------------------------------------------------------------

#ifdef CPU_MAP_ATMEGA328P // (Arduino Uno) Officially supported by Grbl.

// Define serial port pins and interrupt vectors.
Expand Down
20 changes: 10 additions & 10 deletions defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@

#ifdef DEFAULTS_HORUS
// Grbl generic default settings. Should work across different machines.
#define DEFAULT_X_STEPS_PER_DEG 16/1.8 // step/deg
#define DEFAULT_Y_STEPS_PER_DEG 16/1.8 // step/deg
#define DEFAULT_Z_STEPS_PER_DEG 16/1.8 // step/deg
#define DEFAULT_X_STEPS_PER_DEG 16*11 // step/deg
#define DEFAULT_Y_STEPS_PER_DEG 16*200/32 // step/deg
#define DEFAULT_Z_STEPS_PER_DEG 16*200/360 // step/deg
#define DEFAULT_X_MAX_RATE (180.0*60) // 180*60 deg/min = 180 deg/sec
#define DEFAULT_Y_MAX_RATE (180.0*60) // 180*60 deg/min = 180 deg/sec
#define DEFAULT_Y_MAX_RATE (150.0*60) // 180*60 deg/min = 180 deg/sec
#define DEFAULT_Z_MAX_RATE (180.0*60) // 180*60 deg/min = 180 deg/sec
#define DEFAULT_X_ACCELERATION (180.0*60*60) // 180*60*60 deg/min^2 = 180 deg/sec^2
#define DEFAULT_Y_ACCELERATION (180.0*60*60) // 180*60*60 deg/min^2 = 180 deg/sec^2
#define DEFAULT_Z_ACCELERATION (180.0*60*60) // 180*60*60 deg/min^2 = 180 deg/sec^2
#define DEFAULT_X_MAX_TRAVEL 1080.0 // deg
#define DEFAULT_Y_MAX_TRAVEL 1080.0 // deg
#define DEFAULT_Y_MAX_TRAVEL 2000.0 // deg
#define DEFAULT_Z_MAX_TRAVEL 1080.0 // deg
#define DEFAULT_STEP_PULSE_MICROSECONDS 10
#define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK ((1<<Y_AXIS)|(1<<Z_AXIS))
#define DEFAULT_DIRECTION_INVERT_MASK 0 // ((1<<Y_AXIS)|(1<<Z_AXIS))
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_STATUS_REPORT_MASK ((BITFLAG_RT_STATUS_MACHINE_POSITION)|(BITFLAG_RT_STATUS_WORK_POSITION))
#define DEFAULT_JUNCTION_DEVIATION 0.02 // deg
Expand All @@ -57,11 +57,11 @@
#define DEFAULT_AUTO_START 1 // true
#define DEFAULT_INVERT_ST_ENABLE 0 // false
#define DEFAULT_INVERT_LIMIT_PINS 0 // false
#define DEFAULT_SOFT_LIMIT_ENABLE 0 // false
#define DEFAULT_HARD_LIMIT_ENABLE 0 // false
#define DEFAULT_HOMING_ENABLE 0 // false
#define DEFAULT_SOFT_LIMIT_ENABLE 1 // false
#define DEFAULT_HARD_LIMIT_ENABLE 1 // false
#define DEFAULT_HOMING_ENABLE 1 // false
#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir
#define DEFAULT_HOMING_FEED_RATE 25.0 // mm/min
#define DEFAULT_HOMING_FEED_RATE 60.0 // mm/min
#define DEFAULT_HOMING_SEEK_RATE 500.0 // mm/min
#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
#define DEFAULT_HOMING_PULLOFF 1.0 // mm
Expand Down
24 changes: 19 additions & 5 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,24 @@ uint8_t gc_execute_line(char *line)
case 'G':
// Determine 'G' command and its modal group
switch(int_value) {
case 1:
case 0: case 1:
if (axis_command) { FAIL(STATUS_GCODE_AXIS_COMMAND_CONFLICT); } // [Axis word/command conflict]
axis_command = AXIS_COMMAND_MOTION_MODE;
gc_block.modal.motion = MOTION_MODE_LINEAR;
gc_block.modal.motion = int_value; // MOTION_MODE_LINEAR;
word_bit = MODAL_GROUP_G1;
break;

case 4: // G4 Dwell
word_bit = MODAL_GROUP_G0;
gc_block.non_modal_command = NON_MODAL_DWELL;
break;

case 50:
gc_block.non_modal_command = NON_MODAL_RESET_POSITION;
break;
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G command]

default:
FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G command]
}
if (mantissa > 0) { FAIL(STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER); } // [Unsupported or invalid Gxx.x command]
// Check for more than one command per modal group violations in the current block
Expand Down Expand Up @@ -203,10 +211,16 @@ uint8_t gc_execute_line(char *line)
words (I,J,K,L,P,R) have multiple connotations and/or depend on the issued commands. */
switch(letter){
case 'F': word_bit = WORD_F; gc_block.values.f = value; break;
case 'P': word_bit = WORD_P; gc_block.values.p = value; break;
case 'S': word_bit = WORD_S; gc_block.values.s = value; break;
case 'T': word_bit = WORD_T; gc_block.values.t = int_value; break; // gc.values.t = int_value;
case 'X': word_bit = WORD_X; gc_block.values.xyz[X_AXIS] = value; axis_words |= (1<<X_AXIS); break;
/*case 'Y': word_bit = WORD_Y; gc_block.values.xyz[Y_AXIS] = value; axis_words |= (1<<Y_AXIS); break;
case 'Z': word_bit = WORD_Z; gc_block.values.xyz[Z_AXIS] = value; axis_words |= (1<<Z_AXIS); break;*/
#ifdef Y_STEP_BIT
case 'Y': word_bit = WORD_Y; gc_block.values.xyz[Y_AXIS] = value; axis_words |= (1<<Y_AXIS); break;
#endif
#ifdef Z_STEP_BIT
case 'Z': word_bit = WORD_Z; gc_block.values.xyz[Z_AXIS] = value; axis_words |= (1<<Z_AXIS); break;
#endif
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND);
}

Expand Down
Loading