Bug fix for certain motions. Re-org of includes.

- Critical bug fix for diagonal motions that continue on the same
direction or return in the exact opposite direction. This issue could
cause Grbl to crash intermittently due to a numerical round-off error.
Grbl versions prior to v0.9g shouldn’t have this issue.

- Reorganized all of the includes used by Grbl. Centralized it into a
single “grbl.h” include. This will help simplify the compiling and
uploading process through the Arduino IDE.

- Added an example .INO file for users to simply open and run when
compiling and uploading through the IDE. More to come later.
This commit is contained in:
Sonny Jeon 2015-02-10 08:25:09 -07:00
parent 23c1e154aa
commit 3b468f602b
22 changed files with 77 additions and 144 deletions

View File

@ -32,7 +32,6 @@
#ifndef config_h
#define config_h
#include "system.h"
// Default settings. Used when resetting EEPROM. Change to desired name in defaults.h

View File

@ -18,10 +18,7 @@
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include "system.h"
#include "coolant_control.h"
#include "protocol.h"
#include "gcode.h"
#include "grbl.h"
void coolant_init()

22
examples/Grbl/Grbl.ino Normal file
View File

@ -0,0 +1,22 @@
#include <config.h>
#include <coolant_control.h>
#include <cpu_map.h>
#include <defaults.h>
#include <eeprom.h>
#include <gcode.h>
#include <grbl.h>
#include <limits.h>
#include <motion_control.h>
#include <nuts_bolts.h>
#include <planner.h>
#include <print.h>
#include <probe.h>
#include <protocol.h>
#include <report.h>
#include <serial.h>
#include <settings.h>
#include <spindle_control.h>
#include <stepper.h>
#include <system.h>
#include <src/main.h>

10
gcode.c
View File

@ -24,15 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "settings.h"
#include "protocol.h"
#include "gcode.h"
#include "motion_control.h"
#include "spindle_control.h"
#include "coolant_control.h"
#include "probe.h"
#include "report.h"
#include "grbl.h"
// NOTE: Max line number is defined by the g-code standard to be 99999. It seems to be an
// arbitrary value, and some GUIs may require more. So we increased it based on a max safe

28
grbl.h
View File

@ -25,25 +25,41 @@
#ifndef grbl_h
#define grbl_h
// All of the Grbl system include files.
#define GRBL_VERSION "0.9h"
#define GRBL_VERSION_BUILD "20150210"
// Define standard libraries used by Grbl.
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include <math.h>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
// Define the Grbl system include files.
#include "config.h"
#include "coolant_control.h"
#include "cpu_map.h"
#include "nuts_bolts.h"
#include "settings.h"
#include "system.h"
#include "defaults.h"
#include "cpu_map.h"
#include "coolant_control.h"
#include "eeprom.h"
#include "gcode.h"
#include "limits.h"
#include "motion_control.h"
#include "nuts_bolts.h"
#include "planner.h"
#include "print.h"
#include "probe.h"
#include "protocol.h"
#include "report.h"
#include "serial.h"
#include "settings.h"
#include "spindle_control.h"
#include "stepper.h"
#include "system.h"
#endif

View File

@ -24,14 +24,8 @@
Copyright (c) 2012 Sungeun K. Jeon
*/
#include "system.h"
#include "settings.h"
#include "protocol.h"
#include "planner.h"
#include "stepper.h"
#include "motion_control.h"
#include "limits.h"
#include "report.h"
#include "grbl.h"
// Homing axis search distance multiplier. Computed by this value times the axis max travel.
#define HOMING_AXIS_SEARCH_SCALAR 1.5 // Must be > 1 to ensure limit switch will be engaged.

14
main.c
View File

@ -24,19 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "serial.h"
#include "settings.h"
#include "protocol.h"
#include "gcode.h"
#include "planner.h"
#include "stepper.h"
#include "spindle_control.h"
#include "coolant_control.h"
#include "motion_control.h"
#include "limits.h"
#include "probe.h"
#include "report.h"
#include "grbl.h"
// Declare system global variable structure

View File

@ -25,18 +25,7 @@
Copyright (c) 2011 Jens Geisler
*/
#include "system.h"
#include "settings.h"
#include "protocol.h"
#include "gcode.h"
#include "planner.h"
#include "stepper.h"
#include "motion_control.h"
#include "spindle_control.h"
#include "coolant_control.h"
#include "limits.h"
#include "probe.h"
#include "report.h"
#include "grbl.h"
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second

View File

@ -26,7 +26,7 @@
#ifndef motion_control_h
#define motion_control_h
#include "gcode.h"
#define HOMING_CYCLE_LINE_NUMBER -1

View File

@ -24,8 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "print.h"
#include "grbl.h"
#define MAX_INT_DIGITS 8 // Maximum number of digits in int32 (and float)

View File

@ -25,12 +25,7 @@
Copyright (c) 2011 Jens Geisler
*/
#include "system.h"
#include "planner.h"
#include "protocol.h"
#include "stepper.h"
#include "settings.h"
#include "grbl.h"
#define SOME_LARGE_VALUE 1.0E+38 // Used by rapids and acceleration maximization calculations. Just needs
// to be larger than any feasible (mm/min)^2 or mm/sec^2 value.
@ -388,13 +383,19 @@ uint8_t plan_check_full_buffer()
change the overall maximum entry speed conditions of all blocks.
*/
// NOTE: Computed without any expensive trig, sin() or acos(), by trig half angle identity of cos(theta).
junction_cos_theta = min(junction_cos_theta, 1.0); // Check for numerical round-off.
float sin_theta_d2 = sqrt(0.5*(1.0-junction_cos_theta)); // Trig half angle identity. Always positive.
if (junction_cos_theta > 0.99) {
// For a 0 degree acute junction, just set minimum junction speed.
block->max_junction_speed_sqr = MINIMUM_JUNCTION_SPEED*MINIMUM_JUNCTION_SPEED;
} else {
junction_cos_theta = max(junction_cos_theta,-0.99); // Check for numerical round-off to avoid divide by zero.
float sin_theta_d2 = sqrt(0.5*(1.0-junction_cos_theta)); // Trig half angle identity. Always positive.
// TODO: Technically, the acceleration used in calculation needs to be limited by the minimum of the
// two junctions. However, this shouldn't be a significant problem except in extreme circumstances.
block->max_junction_speed_sqr = max( MINIMUM_JUNCTION_SPEED*MINIMUM_JUNCTION_SPEED,
(block->acceleration * settings.junction_deviation * sin_theta_d2)/(1.0-sin_theta_d2) );
// TODO: Technically, the acceleration used in calculation needs to be limited by the minimum of the
// two junctions. However, this shouldn't be a significant problem except in extreme circumstances.
block->max_junction_speed_sqr = max( MINIMUM_JUNCTION_SPEED*MINIMUM_JUNCTION_SPEED,
(block->acceleration * settings.junction_deviation * sin_theta_d2)/(1.0-sin_theta_d2) );
}
}
// Store block nominal speed

View File

@ -24,9 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "serial.h"
#include "settings.h"
#include "grbl.h"
void printString(const char *s)

View File

@ -18,9 +18,8 @@
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include "system.h"
#include "settings.h"
#include "probe.h"
#include "grbl.h"
// Inverts the probe pin state depending on user settings and probing cycle mode.
uint8_t probe_invert_mask;

View File

@ -24,15 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "serial.h"
#include "settings.h"
#include "protocol.h"
#include "gcode.h"
#include "planner.h"
#include "stepper.h"
#include "motion_control.h"
#include "report.h"
#include "grbl.h"
static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated.

View File

@ -26,16 +26,7 @@
methods to accomodate their needs.
*/
#include "system.h"
#include "report.h"
#include "print.h"
#include "settings.h"
#include "gcode.h"
#include "coolant_control.h"
#include "planner.h"
#include "spindle_control.h"
#include "stepper.h"
#include "serial.h"
#include "grbl.h"
// Handles the primary confirmation protocol response for streaming interfaces and human-feedback.

View File

@ -24,11 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include <avr/interrupt.h>
#include "system.h"
#include "serial.h"
#include "motion_control.h"
#include "protocol.h"
#include "grbl.h"
uint8_t serial_rx_buffer[RX_BUFFER_SIZE];

View File

@ -24,13 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "settings.h"
#include "eeprom.h"
#include "protocol.h"
#include "report.h"
#include "limits.h"
#include "stepper.h"
#include "grbl.h"
settings_t settings;

View File

@ -27,9 +27,8 @@
#ifndef settings_h
#define settings_h
#include "grbl.h"
#define GRBL_VERSION "0.9h"
#define GRBL_VERSION_BUILD "20150204"
// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
// when firmware is upgraded. Always stored in byte 0 of eeprom

View File

@ -24,10 +24,7 @@
Copyright (c) 2012 Sungeun K. Jeon
*/
#include "system.h"
#include "spindle_control.h"
#include "protocol.h"
#include "gcode.h"
#include "grbl.h"
void spindle_init()

View File

@ -24,12 +24,7 @@
Copyright (c) 2011-2012 Sungeun K. Jeon
*/
#include "system.h"
#include "nuts_bolts.h"
#include "stepper.h"
#include "settings.h"
#include "planner.h"
#include "probe.h"
#include "grbl.h"
// Some useful constants.

View File

@ -18,14 +18,7 @@
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include "system.h"
#include "settings.h"
#include "protocol.h"
#include "gcode.h"
#include "motion_control.h"
#include "stepper.h"
#include "report.h"
#include "print.h"
#include "grbl.h"
void system_init()

View File

@ -21,25 +21,7 @@
#ifndef system_h
#define system_h
// Define system header files and standard libraries used by Grbl
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include <math.h>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
// Define Grbl configuration and shared header files
#include "config.h"
#include "defaults.h"
#include "cpu_map.h"
#include "nuts_bolts.h"
#include "grbl.h"
// Define system executor bit map. Used internally by realtime protocol as realtime command flags,
// which notifies the main program to execute the specified realtime command asynchronously.