Skip to content

Schematic diagram for THC #855

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

Open
wants to merge 7 commits into
base: main
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ embedded/dist
.vscode/
.history/
*.pyc
.vs/
Debug/
Release/
*.vsarduino.h
__vm/
*.user
*.vcxproj
*.vcxproj.filters
*.suo
31 changes: 31 additions & 0 deletions Grbl_Esp32.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29306.81
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grbl_Esp32", "Grbl_Esp32.vcxproj", "{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x64.ActiveCfg = Debug|x64
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x64.Build.0 = Debug|x64
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x86.ActiveCfg = Debug|Win32
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x86.Build.0 = Debug|Win32
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x64.ActiveCfg = Release|x64
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x64.Build.0 = Release|x64
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x86.ActiveCfg = Release|Win32
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EEC94F4B-059C-4596-94B8-1C4C9CE5E0DD}
EndGlobalSection
EndGlobal
176 changes: 176 additions & 0 deletions Grbl_Esp32/Custom/torchHeightControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
torchHeightControl.cpp
Part of Grbl_ESP32

copyright (c) 2018 - Bart Dring This file was modified for use on the ESP32
CPU. Do not use this with Grbl for atMega328P

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.

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 Grbl. If not, see <http://www.gnu.org/licenses/>.

--------------------------------------------------------------

This contains all the special features required for "Plasma Torch Height Control"
This Torch Height Control Custom File Was Created By: William Curry
*/
// This file is enabled by defining: CUSTOM_CODE_FILENAME "Custom/torchHeightControl.cpp"
// in Machines/6_pack_thc.h, thus causing this file to be included
// from ../custom_code.cpp
static TaskHandle_t THCSyncTaskHandle = 0;
static TaskHandle_t THCVoltageTaskHandle = 0;
unsigned long THCCounter = 0; //For debugging only
unsigned long lastDebugPrintTimeMillis; //For debugging only, last time debug info was printed
bool alwaysPrintWhenTHCRunning = true;
unsigned long arcOnTime; //milliseconds at which plasma arc was turned on
//Be careful with this next setting becuase if you send to many steps to stepper.cpp per iteration it may overrun how many steps the machine can do per milliseond at slower x/y speeds
int numberStepsPerIteration = 1;//How many steps we want to send to the stepper.cpp for each iteration of THC this will be an adjustable setting in the future %%%%%%%%%%
bool thcRunning;
int thcIterationMs = 20;
int directionDownPinState = 1;
int directionUpPinState = 0;
float thcPinVoltage;
float torchVoltage;
float torchVoltageFiltered; ///Current filtered value used for THC routine
float voltageSetpoint;
int voltageInt;
int currentDirectionState; ////get state of direction pin
bool directionDifference;
int thcZStep;
int thcDirDown;
// Function // Step Z Down Voltage too high
void thcStepZDown(){
if ((thc_debug_setting->get()||alwaysPrintWhenTHCRunning) && ((millis() - lastDebugPrintTimeMillis) > thc_debugprint_millis->get()) )
{
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Setpoint = %4.1f THC Voltage = %4.1f Moving Z Down", voltageSetpoint, torchVoltageFiltered);
lastDebugPrintTimeMillis = millis();
}
thcZStep = numberStepsPerIteration; // set the number of steps per iteration of THC so stepper.cpp can execute the steps
thcDirDown = 1; //Set the step direction so stepper.cpp knows which way to step
}

// Function // Step Z Up Voltage too Low
void thcStepZUp(){
if ((thc_debug_setting->get()||alwaysPrintWhenTHCRunning) && ((millis() - lastDebugPrintTimeMillis) > thc_debugprint_millis->get()) )
{
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Setpoint = %4.1f THC Voltage = %4.1f Moving Z Up", voltageSetpoint, torchVoltageFiltered);
lastDebugPrintTimeMillis = millis();
}
thcZStep = numberStepsPerIteration; // set the number of steps per iteration of THC so stepper.cpp can execute the steps
thcDirDown = 0; //Set the step direction so stepper.cpp knows which way to step
}

void machine_init() {
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "Bill's THC Initialized");
// setup a task that will do torch height control
xTaskCreatePinnedToCore(THCSyncTask, // task
"THCSyncTask", // name for task
4096, // size of task stack
NULL, // parameters
1, // priority
&THCSyncTaskHandle,
0 // core
);
// setup a task that will filter the torch voltage
xTaskCreatePinnedToCore(THCVoltageTask, // task
"THCVoltageTask", // name for task
4096, // size of task stack
NULL, // parameters
1, // priority
&THCVoltageTaskHandle,
0 // core
);
}

// this task is the main THC loop
void THCSyncTask(void* pvParameters) {
TickType_t xthcWakeTime;
const TickType_t xTHCFrequency = (thc_iter_freq -> get()) + 1; // (ms)
xthcWakeTime = xTaskGetTickCount(); // Initialise the xthcWakeTime variable with the current time.
while (true) { // don't ever return from this or the task dies
//Get the state of the plasma cutter torch on relay
uint8_t plasmaState = coolant_get_state(); //Using the coolant flood output to turn on the plasma cutter
if(sys.suspend)
{
coolant_set_state(COOLANT_DISABLE); //Disable plasma if system state is suspended
}
if(plasmaState && (voltageSetpoint > 30) && !sys.suspend) //Plasma Has Been Turned On and the Voltage Setpoint is greater than 30 volts Start The THC Routine
{
if((millis()- arcOnTime) > (thc_arc_delay_time->get()))
{
thcRunning = true;
//digitalWrite(I2SO(24),HIGH);
//digitalWrite(I2SO(25),HIGH);
//digitalWrite(I2SO(26),HIGH);
//digitalWrite(I2SO(27),HIGH);
}
else
{
thcRunning = false;
}
}
else
{
arcOnTime = millis(); //Reset arc on delay timer
thcRunning = false;
thcZStep = 0; //Reset all the steps we sent to stepper.cpp
if (thc_debug_setting->get() && ((millis() - lastDebugPrintTimeMillis) > thc_debugprint_millis->get()) )
{
//grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Interation # %d", THCCounter);
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Voltage Filt = %4.1f", torchVoltageFiltered);
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Voltage Unfiltered = %4.1f", torchVoltage);
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Pin Voltage = %3.2f", thcPinVoltage);
grbl_msg_sendf(CLIENT_ALL, MSG_LEVEL_INFO, "THC Voltage Setting = %4.1f", voltageSetpoint);
lastDebugPrintTimeMillis = millis();
}
//digitalWrite(I2SO(24),LOW);
//digitalWrite(I2SO(25),LOW);
//digitalWrite(I2SO(26),LOW);
//digitalWrite(I2SO(27),LOW);
}

if((torchVoltageFiltered > voltageSetpoint) && thcRunning) //Voltage is too high and were running THC step Z down
{
thcStepZDown();
}
else if((torchVoltageFiltered < voltageSetpoint)&& thcRunning) //Voltage is too low and were running THC step Z up
{
thcStepZUp();
}

THCCounter ++;
voltageSetpoint = (thc_voltage_setting -> get());

vTaskDelayUntil(&xthcWakeTime, thc_iter_freq -> get() + 1); //Adding +1 so the loop doesn't crash if set to 0
}
}

// this task is THC Voltage Filtering Loop
void THCVoltageTask(void* pvParameters) {
TickType_t xLastVoltageWakeTime;
const TickType_t xTHCVoltageFrequency = 2; // (ms)
xLastVoltageWakeTime = xTaskGetTickCount(); // Initialise the xLastVoltageWakeTime variable with the current time.
while (true) {// don't ever return from this or the task dies
voltageInt = analogRead(THC_VOLTAGE_PIN);
thcPinVoltage = voltageInt * (3.3 / 4095); //0-3.3 volts at torch input pin
torchVoltage = (thcPinVoltage*(VOLTAGE_DIVIDER_R1+VOLTAGE_DIVIDER_R2))/VOLTAGE_DIVIDER_R2;//0-207 volts for R1 = 470K R2 = 7.6K
if(thcRunning) ///If the Main THC Loop is running Start filtering the voltage
{
torchVoltageFiltered = torchVoltageFiltered * (thc_voltage_filter_value -> get()) + torchVoltage * (1-(thc_voltage_filter_value -> get())); //Rough filter for voltage input
}
else
{
torchVoltageFiltered = torchVoltage;
}
vTaskDelayUntil(&xLastVoltageWakeTime, xTHCVoltageFrequency + 1);
}
}
8 changes: 4 additions & 4 deletions Grbl_Esp32/Machines/6_pack_stepstick_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
#define Y_LIMIT_PIN GPIO_NUM_32
#define Z_LIMIT_PIN GPIO_NUM_35
#define A_LIMIT_PIN GPIO_NUM_34
#define B_LIMIT_PIN GPIO_NUM_39
#define C_LIMIT_PIN GPIO_NUM_36
//#define B_LIMIT_PIN GPIO_NUM_39
//#define C_LIMIT_PIN GPIO_NUM_36

#define PROBE_PIN GPIO_NUM_25

Expand Down Expand Up @@ -117,13 +117,13 @@
#define COOLANT_FLOOD_PIN I2SO(27)
*/

/*

// RS485 In socket #3
#define SPINDLE_TYPE SPINDLE_TYPE_HUANYANG // only one spindle at a time
#define HUANYANG_TXD_PIN GPIO_NUM_26
#define HUANYANG_RTS_PIN GPIO_NUM_4
#define HUANYANG_RXD_PIN GPIO_NUM_16
*/



// === Default settings
Expand Down
132 changes: 132 additions & 0 deletions Grbl_Esp32/Machines/6_pack_thc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
6_pack_thc.h

Covers all V1 versions V1p0, V1p1, etc

Part of Grbl_ESP32
Pin assignments for the ESP32 I2S 6-axis board
2018 - Bart Dring
2020 - Mitch Bradley
2020 - Michiyasu Odaki
2020 - William Curry - Plasma Torch Height Control
Grbl_ESP32 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.
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 Grbl_ESP32. If not, see <http://www.gnu.org/licenses/>.
This 6-Pack Torch Height Control Custom File Was Created By: William Curry
*/
#define MACHINE_NAME "6 Pack Controller with Plasma Torch Height Control"
#define CUSTOM_CODE_FILENAME "Custom/torchHeightControl.cpp"//define the torch height control custom code file
// tells grbl we have some special functions to call
#define USE_MACHINE_INIT
#ifdef N_AXIS
#undef N_AXIS
#endif
#define N_AXIS 3
//Enable the SD Card
#ifndef ENABLE_SD_CARD
#define ENABLE_SD_CARD
#endif
/// THC Settings, these can be displayed in G Code Sender by Typing $S to show strings or $+ to show numbers like shown below
#define SHOW_EXTENDED_SETTINGS
#define DEFAULT_THC_DEBUG 0 //$300=1// Boolean //If true this will print torch height debug information out
#define DEFAULT_THC_DEBUG_PRINT_MILLIS 5000 //$301=1000//milliseconds // debug print time in milliseconds
#define DEFAULT_THC_TARGET_VOLTAGE 0 //$302=0// Volts // default target voltage (a real value would be 100 volts) this must be greater than 30 volts for THC to run
#define DEFAULT_THC_ARC_DELAY_TIME 750 //$303=750//milliseconds // Time for Arc to Start before running THC
#define DEFAULT_THC_VOLTAGE_FILTER_VALUE 0.98 //$304=0.98//ND// Torch Voltage Filter Time Constant
#define DEFAULT_THC_ITER_FREQ 5 //$305=5//milliseconds// Torch Height Control Time Between Calls, this will directly effect ...
// ... the rate at which the Z axis moves. A higher muber means the Z axis will move slower since THC is called less often

// === Special Features
///Define Torch Height Control
#define torchHeightControl //Used in stepper.cpp
/// I2S (steppers & other output-only pins)
#define USE_I2S_OUT
// Define USE_I2S_OUT_STREAM if buffering is used.
// (there will be a delay between the specified I/O operation and the actual I/O execution)
#define USE_I2S_OUT_STREAM
#undef USE_RMT_STEPS
#define STEP_PULSE_DELAY 10 //Mircoseconds to delay between setting direction pin and setting step pin high
//#define USE_STEPSTICK //Bill comment makes sure MS1,2,3 !reset and !sleep are set
/* #ifdef ENABLE_WIFI
#undef ENABLE_WIFI ///Turn off wifi since this blocks the ADC Channel 2 Pins from Reading in Voltage Which is needed for THC
#endif */

#define I2S_OUT_BCK GPIO_NUM_22
#define I2S_OUT_WS GPIO_NUM_17
#define I2S_OUT_DATA GPIO_NUM_21

/// Axis Data
#define USE_GANGED_AXES // allow two motors on an axis

#define STEPPER_Z_MS3 I2SO(3) // Z_CS
#define STEPPER_Y_MS3 I2SO(6) // Y_CS
#define STEPPER_X_MS3 I2SO(11) // X_CS
#define STEPPER_Y2_MS3 I2SO(14) // Y2/A_CS
//#define STEPPER_B_MS3 I2SO(19) // B_CS
//#define STEPPER_C_MS3 I2SO(22) // C_CS
#define STEPPER_RESET GPIO_NUM_19
//Terminal 1
#define Z_DISABLE_PIN I2SO(0)
#define Z_DIRECTION_PIN I2SO(1)
#define Z_STEP_PIN I2SO(2)

//Y Is a Ganged Motor
#define Y_AXIS_SQUARING
//Terminal 2
#define Y_DIRECTION_PIN I2SO(4)
#define Y_STEP_PIN I2SO(5)
#define Y_DISABLE_PIN I2SO(7)
//Terminal 4
#define Y2_DIRECTION_PIN I2SO(12) //Motor A Dir
#define Y2_STEP_PIN I2SO(13) //Motor A Step
#define Y2_DISABLE_PIN I2SO(15) //Motor A Disable

///Terminal 3
#define X_DISABLE_PIN I2SO(8)
#define X_DIRECTION_PIN I2SO(9)
#define X_STEP_PIN I2SO(10)
/* Bill Comment out these axis'

#define B_DISABLE_PIN I2SO(16)
#define B_DIRECTION_PIN I2SO(17)
#define B_STEP_PIN I2SO(18)

#define C_DIRECTION_PIN I2SO(20)
#define C_STEP_PIN I2SO(21)
#define C_DISABLE_PIN I2SO(23)
*/
/// CNC Modules
///CNC Module #1 THC Voltage
#define THC_VOLTAGE_PIN GPIO_NUM_32

///Resistance Values needed to determine arc voltage i.e. Vout = (Vs*R2)/(R1+R2)
#define VOLTAGE_DIVIDER_R1 470 ///470K Ohms
#define VOLTAGE_DIVIDER_R2 7.6 ///7.6K Ohms

//CNC Module # 2 Opto Isolated
#define X_LIMIT_PIN GPIO_NUM_2
#define Y_LIMIT_PIN GPIO_NUM_25
#define Z_LIMIT_PIN GPIO_NUM_39
#define PROBE_PIN GPIO_NUM_36

///CNC Module # 3 Spindle Relay
#define SPINDLE_TYPE SPINDLE_TYPE_RELAY
#define SPINDLE_OUTPUT_PIN GPIO_NUM_26
//#define COOLANT_MIST_PIN GPIO_NUM_26
///CNC Module # 4 Plasma Torch Relay AKA Coolant Flood Pin
#define COOLANT_FLOOD_PIN GPIO_NUM_14

///CNC Module # 5 Empty

///Torch Height Control Custom Functions
void THCSyncTask(void* pvParameters); //Task called for Torch height controlled thats defined in torchHeightControl.cpp
void THCVoltageTask(void* pvParameters); //Task called for Torch height controlled thats defined in torchHeightControl.cpp
// === Default settings
#define DEFAULT_STEP_PULSE_MICROSECONDS I2S_OUT_USEC_PER_PULSE
Loading