Skip to content
Closed
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
4 changes: 1 addition & 3 deletions RabbitGRBL/src/Backlash/BacklashManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
along with Rabbit GRBL. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../Grbl.h"
#include "BacklashManager.h"

#define DIR_POSITIVE 0
#define DIR_NEGATIVE 1
#define DIR_NEUTRAL 2

// Private (Statics)
float BacklashManager::fPreviousTargets[MAX_N_AXIS] = {0.0};
uint8_t BacklashManager::fAxisDirections[MAX_N_AXIS] = {DIR_NEUTRAL};

/**
* Initialize the Backlash Manager
* This method is called from grbl_init (Grbl.cpp)
Expand Down
12 changes: 6 additions & 6 deletions RabbitGRBL/src/Backlash/BacklashManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
class BacklashManager
{
public:
static void Initialize();
static void CompensateBacklash(float *target, plan_line_data_t *pl_data);
void Initialize();
void CompensateBacklash(float *target, plan_line_data_t *pl_data);

static void ResetTargets();
static void SynchPositionWhileUsingProbe();
void ResetTargets();
void SynchPositionWhileUsingProbe();

private:
static float fPreviousTargets[];
static uint8_t fAxisDirections[];
float fPreviousTargets[MAX_N_AXIS];
uint8_t fAxisDirections[MAX_N_AXIS];
};
51 changes: 51 additions & 0 deletions RabbitGRBL/src/CNCMachine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
CNCMachine.cpp

Copyright (c) 2026 Nikolaos Siatras
Twitter: nsiatras
Github: https://github.com/nsiatras
Website: https://www.sourcerabbit.com

Rabbit GRBL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Rabbit GRBL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Rabbit GRBL. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Grbl.h"
#include "CNCMachine.h"

BacklashManager CNCMachine::fBacklashManager;
MotorsManager CNCMachine::fMotorsManager;
CoolantManager CNCMachine::fCoolantManager;
Probe CNCMachine::fProbe;

/**
* Initialize the CNC Machine
*/
void CNCMachine::Initialize()
{
CNCMachine::fBacklashManager.Initialize();
CNCMachine::fMotorsManager.Initialize();
CNCMachine::fCoolantManager.Initialize();
CNCMachine::fProbe.Initialize();
}

/**
* Reset the CNC Machine.
* (Re-Initialize managers etc.)
*/
void CNCMachine::Reset()
{
CNCMachine::fBacklashManager.ResetTargets();
CNCMachine::fCoolantManager.Initialize();
CNCMachine::fProbe.Initialize();
}
41 changes: 41 additions & 0 deletions RabbitGRBL/src/CNCMachine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
CNCMachine.h

Copyright (c) 2026 Nikolaos Siatras
Twitter: nsiatras
Github: https://github.com/nsiatras
Website: https://www.sourcerabbit.com

Rabbit GRBL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Rabbit GRBL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Rabbit GRBL. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "Grbl.h"
#include "Backlash/BacklashManager.h"
#include "Motors/MotorsManager.h"
#include "Coolant/CoolantManager.h"
#include "Probe/Probe.h"

class CNCMachine
{
public:
static BacklashManager fBacklashManager;
static MotorsManager fMotorsManager;
static CoolantManager fCoolantManager;
static Probe fProbe;

static void Initialize();
static void Reset();
};
33 changes: 13 additions & 20 deletions RabbitGRBL/src/Coolant/CoolantManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@ You should have received a copy of the GNU General Public License
along with Rabbit GRBL. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../Grbl.h"
#include "CoolantManager.h"

#define COOLANTS_COUNT 2

// Public (Statics)
Coolant CoolantManager::Mist_Coolant;
Coolant CoolantManager::Flood_Coolant;

// Private (Statics)
Coolant *CoolantManager::fCoolants[COOLANTS_COUNT];
bool CoolantManager::fInitialized = false;

/**
* Initialize the Coolant Manager
*/
void CoolantManager::Initialize()
{
if (CoolantManager::fInitialized)
if (fInitialized)
{
// If the CoolantManager has already been initialized then just turn all coolants off.
// This case might happened after the user send a reset command to the controller.
Expand All @@ -49,28 +42,28 @@ void CoolantManager::Initialize()
// Initialize Mist (M7)
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef COOLANT_MIST_PIN
CoolantManager::Mist_Coolant.Initialize(COOLANT_MIST_PIN, INVERT_COOLANT_MIST_PIN, settings_coolant_mist_start_delay);
Mist_Coolant.Initialize(COOLANT_MIST_PIN, INVERT_COOLANT_MIST_PIN, settings_coolant_mist_start_delay);
// MessageSender::SendMessage(EMessageLevel::Info, "Mist coolant on pin %s", pinName(COOLANT_MIST_PIN).c_str());
#else
CoolantManager::Mist_Coolant.Initialize(0, true);
Mist_Coolant.Initialize(0, true);
#endif
CoolantManager::fCoolants[0] = &CoolantManager::Mist_Coolant;
fCoolants[0] = &Mist_Coolant;

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Initialize Flood (M8)
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef COOLANT_FLOOD_PIN
CoolantManager::Flood_Coolant.Initialize(COOLANT_FLOOD_PIN, INVERT_COOLANT_FLOOD_PIN, settings_coolant_flood_start_delay);
Flood_Coolant.Initialize(COOLANT_FLOOD_PIN, INVERT_COOLANT_FLOOD_PIN, settings_coolant_flood_start_delay);
// MessageSender::SendMessage(EMessageLevel::Info, "Flood coolant on pin %s", pinName(COOLANT_FLOOD_PIN).c_str());
#else
CoolantManager::Flood_Coolant.Initialize(0, true);
Flood_Coolant.Initialize(0, true);
#endif
CoolantManager::fCoolants[1] = &CoolantManager::Flood_Coolant;
fCoolants[1] = &Flood_Coolant;

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Finally mark the CoolantManager as Initialized !
CoolantManager::fInitialized = true;
fInitialized = true;
}

/**
Expand All @@ -80,7 +73,7 @@ void CoolantManager::TurnAllCoolantsOff()
{
for (int i = 0; i < COOLANTS_COUNT; i++)
{
CoolantManager::fCoolants[i]->TurnOff();
fCoolants[i]->TurnOff();
}

sys.report_ovr_counter = 0; // Set to report change immediately
Expand All @@ -91,8 +84,8 @@ void CoolantManager::TurnAllCoolantsOff()
*/
void CoolantManager::setCoolantState(CoolantState state)
{
CoolantManager::Mist_Coolant.setState(state.Mist == 1);
CoolantManager::Flood_Coolant.setState(state.Flood == 1);
Mist_Coolant.setState(state.Mist == 1);
Flood_Coolant.setState(state.Flood == 1);
sys.report_ovr_counter = 0; // Set to report change immediately
}

Expand All @@ -103,7 +96,7 @@ bool CoolantManager::AreAllCoolantsOff()
{
for (int i = 0; i < COOLANTS_COUNT; i++)
{
if (CoolantManager::fCoolants[i]->isOn())
if (fCoolants[i]->isOn())
{
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions RabbitGRBL/src/Coolant/CoolantManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
class CoolantManager
{
public:
static Coolant Mist_Coolant;
static Coolant Flood_Coolant;
Coolant Mist_Coolant;
Coolant Flood_Coolant;

static void Initialize();
static void TurnAllCoolantsOff();
static void setCoolantState(CoolantState state);
void Initialize();
void TurnAllCoolantsOff();
void setCoolantState(CoolantState state);

static bool AreAllCoolantsOff();
bool AreAllCoolantsOff();

private:
static bool fInitialized;
static Coolant *fCoolants[];
bool fInitialized;
Coolant *fCoolants[2];
};
8 changes: 4 additions & 4 deletions RabbitGRBL/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,20 +2212,20 @@ EError gc_execute_line(char *line)
gc_state.modal.coolant.Mist = 1;
protocol_buffer_synchronize();
// Ask Mist Coolant to TurnOn
CoolantManager::Mist_Coolant.TurnOn();
CNCMachine::fCoolantManager.Mist_Coolant.TurnOn();
break;

case GCodeCoolant::M8:
gc_state.modal.coolant.Flood = 1;
protocol_buffer_synchronize();
// Ask Flood Coolant to TurnOn
CoolantManager::Flood_Coolant.TurnOn();
CNCMachine::fCoolantManager.Flood_Coolant.TurnOn();
break;

case GCodeCoolant::M9:
gc_state.modal.coolant = {};
// Turn all Collants off
CoolantManager::TurnAllCoolantsOff();
CNCMachine::fCoolantManager.TurnAllCoolantsOff();
break;
}
pl_data->coolant = gc_state.modal.coolant; // Set state for planner use.
Expand Down Expand Up @@ -2510,7 +2510,7 @@ EError gc_execute_line(char *line)
coords[gc_state.modal.coord_select]->get(gc_state.coord_system);
system_flag_wco_change(); // Set to refresh immediately just in case something altered.
fSpindle->setState(SpindleState::Disable, 0);
CoolantManager::TurnAllCoolantsOff();
CNCMachine::fCoolantManager.TurnAllCoolantsOff();
}
MessageSender::SendFeedbackMessage(EFeedbackMessage::ProgramEnd);
#ifdef USE_M30
Expand Down
13 changes: 4 additions & 9 deletions RabbitGRBL/src/Grbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

void grbl_init()
{
client_init(); // Setup serial baud rate and interrupts
client_init(); // Setup serial baud rate and interrupts

settings_init(); // Load Grbl settings from non-volatile storage
stepper_init(); // Configure stepper pins and interrupt timers
system_ini(); // Configure pinout pins and pin-change interrupt (Renamed due to conflict with esp32 files)
BacklashManager::Initialize();
MotorsManager::Initialize();
CNCMachine::Initialize();
memset(sys_position, 0, sizeof(sys_position)); // Clear machine position.
machine_init(); // weak definition in Grbl.cpp does nothing

Expand Down Expand Up @@ -69,7 +68,7 @@ static void reset_variables()
sys.spindle_speed_ovr = SpindleSpeedOverride::Default; // Set to 100%
memset(sys_probe_position, 0, sizeof(sys_probe_position)); // Clear probe position.

Probe::setSystemProbeState(false);
CNCMachine::fProbe.setSystemProbeState(false);

sys_rt_exec_state.value = 0;
sys_rt_exec_accessory_override.value = 0;
Expand All @@ -85,15 +84,13 @@ static void reset_variables()
client_reset_read_buffer();
gc_init(); // Set g-code parser to default state
fSpindle->Stop();
CoolantManager::Initialize();
limits_init();
Probe::Initialize();
plan_reset(); // Clear block buffer and planner variables
st_reset(); // Clear stepper subsystem variables

// Sync cleared gcode and planner positions to current system position.
plan_sync_position();
BacklashManager::ResetTargets();
CNCMachine::fBacklashManager.ResetTargets();
gc_sync_position();
report_init_message();
}
Expand All @@ -108,5 +105,3 @@ void run_once()
}

void __attribute__((weak)) machine_init() {}


9 changes: 5 additions & 4 deletions RabbitGRBL/src/Grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,27 @@ const char *const GRBL_VERSION = "1.1h";
#include "Diagnostics/Errors/ErrorsManager.h"
#include "Diagnostics/Alarms/AlarmsManager.h"

#include "Probe/Probe.h"

#include "System.h"
#include "GCode.h"
#include "Planner.h"
#include "Limits.h"
#include "Backlash/BacklashManager.h"

#include "MotionControl.h"
#include "Protocol.h"
#include "Serial.h"
#include "MessageSender/MessageSender.h"
#include "Report.h"
#include "Pins.h"
#include "Spindles/Spindle.h"
#include "Motors/MotorsManager.h"

#include "Stepper.h"
#include "Jog.h"
#include "InputBuffer/InputBuffer.h"
#include "Settings.h"
#include "SettingsDefinitions.h"
#include "Coolant/CoolantManager.h"

#include "CNCMachine.h"
#include "UserOutputs/UserOutputs.h"
#include <Wire.h>

Expand Down
6 changes: 3 additions & 3 deletions RabbitGRBL/src/Limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void limits_go_home(uint8_t cycle_mask)
// Put motors on axes listed in cycle_mask in homing mode and
// replace cycle_mask with the list of motors that are ready for homing.
// Motors with non standard homing can home during motors_set_homing_mode(...)
cycle_mask = MotorsManager::SetHomingMode(cycle_mask, true); // tell motors homing is about to start
cycle_mask = CNCMachine::fMotorsManager.SetHomingMode(cycle_mask, true); // tell motors homing is about to start

// see if any motors are left
if (cycle_mask == 0)
Expand Down Expand Up @@ -240,7 +240,7 @@ void limits_go_home(uint8_t cycle_mask)

if (sys_rt_exec_alarm != EAlarm::None)
{
MotorsManager::SetHomingMode(cycle_mask, false); // tell motors homing is done...failed
CNCMachine::fMotorsManager.SetHomingMode(cycle_mask, false); // tell motors homing is done...failed
MessageSender::SendMessage(EMessageLevel::Debug, "Homing fail");
mc_reset(); // Stop motors, if they are running.
protocol_execute_realtime();
Expand Down Expand Up @@ -300,7 +300,7 @@ void limits_go_home(uint8_t cycle_mask)
}
}
sys.step_control = {}; // Return step control to normal operation.
MotorsManager::SetHomingMode(cycle_mask, false); // tell motors homing is done
CNCMachine::fMotorsManager.SetHomingMode(cycle_mask, false); // tell motors homing is done
}

uint8_t limit_pins[MAX_N_AXIS][2] = {{X_LIMIT_PIN, X2_LIMIT_PIN}, {Y_LIMIT_PIN, Y2_LIMIT_PIN}, {Z_LIMIT_PIN, Z2_LIMIT_PIN}, {A_LIMIT_PIN, A2_LIMIT_PIN}, {B_LIMIT_PIN, B2_LIMIT_PIN}, {C_LIMIT_PIN, C2_LIMIT_PIN}};
Expand Down
Loading