Skip to content

Commit

Permalink
Bug fix for certain motions. Re-org of includes.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
chamnit committed Feb 10, 2015
1 parent 23c1e15 commit 3b468f6
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 144 deletions.
1 change: 0 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions coolant_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 22 additions & 0 deletions examples/Grbl/Grbl.ino
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 9 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 2 additions & 8 deletions limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 1 addition & 13 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion motion_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#ifndef motion_control_h
#define motion_control_h
#include "gcode.h"


#define HOMING_CYCLE_LINE_NUMBER -1

Expand Down
3 changes: 1 addition & 2 deletions nuts_bolts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 13 additions & 12 deletions planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 1 addition & 9 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 1 addition & 10 deletions report.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 1 addition & 7 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions spindle_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 1 addition & 19 deletions system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3b468f6

Please sign in to comment.