diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a76408b1..1fe10483 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,18 +1,17 @@ { - "configurations": [ - { - "name": "Mac", - "compileCommands": "${workspaceFolder}/g2core/compile_commands.json", - "compilerPath": "${workspaceFolder}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/arm-none-eabi-gcc", - "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "gcc-x64", - "browse": { - "path": [ - "${workspaceFolder}" - ] - } - } - ], - "version": 4 + "configurations": [ + { + "name": "Mac", + "compileCommands": "${workspaceFolder}/g2core/compile_commands.json", + "compilerPath": "${workspaceFolder}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/arm-none-eabi-gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64", + "browse": { + "path": ["${workspaceFolder}"] + }, + "configurationProvider": "ms-vscode.makefile-tools" + } + ], + "version": 4 } diff --git a/.vscode/launch.json b/.vscode/launch.json index 6cfb1b6d..188bab16 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,12 +14,12 @@ "device": "ATSAMS70N19", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N19.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=fourcable" }, @@ -33,12 +33,12 @@ "device": "ATSAMS70N20", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N20B.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=r7 Debug" }, @@ -52,12 +52,12 @@ "device": "ATSAM3X8E", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sam3x/ATSAM3X8E.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=MiniMillgShield Debug" }, @@ -71,12 +71,12 @@ "device": "ATSAM3X8E", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sam3x/ATSAM3X8E.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=ShapeokoDualY" }, @@ -90,12 +90,12 @@ "device": "ATSAM3X8E", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sam3x/ATSAM3X8E.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=MiniMillv9 Debug" }, @@ -105,16 +105,16 @@ "request": "launch", "servertype": "jlink", "cwd": "${workspaceRoot}/g2core/", - "executable": "./bin/MiniMill-gquintic-d/g2core.elf", + "executable": "./bin/MiniMill-gquintic-g/g2core.elf", "device": "ATSAMS70N19", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N19.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=MiniMill Debug" }, @@ -128,16 +128,16 @@ "device": "ATSAMS70N20", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N20B.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "swoConfig": { "enabled": true, - "source":"probe", + "source": "probe", "swoFrequency": 8000000, "decoders": [ { @@ -198,12 +198,12 @@ "device": "ATSAMS70N20", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N20B.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=MiniMill Debug" }, @@ -217,12 +217,12 @@ "device": "ATSAMS70N19", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N19.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=CheapoLaser Debug" }, @@ -235,13 +235,13 @@ "executable": "./bin/OthermillPro-g2v9k/g2core.elf", "device": "ATSAM3X8E", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sam3x/ATSAM3X8E.svd", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=OthermillPro Debug" }, @@ -255,12 +255,12 @@ "device": "ATSAMS70N20", "svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sams70/ATSAMS70N20B.svd", "interface": "swd", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "osx": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-12.2r1/bin/" }, "linux": { - "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/" + "armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-12.2r1/bin/" }, "preLaunchTask": "Build CONFIG=AxiDrawv3-quint Debug" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e5106ce6..a44c0e66 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -309,6 +309,17 @@ "fileLocation": ["relative", "${workspaceRoot}/g2core"] } }, + { + "label": "Build CONFIG=r7-v9k Production", + "type": "process", + "command": "make", + "args": ["CONFIG=r7-v9k", "VERBOSE=2", "COLOR=0", "RECORD=1"], + "group": "build", + "problemMatcher": { + "base": "$gcc", + "fileLocation": ["relative", "${workspaceRoot}/g2core"] + } + }, { "label": "Clean CONFIG=r7", "type": "process", @@ -320,6 +331,17 @@ "fileLocation": ["relative", "${workspaceRoot}/g2core"] } }, + { + "label": "Clean CONFIG=r7-v9k", + "type": "process", + "command": "make", + "args": ["CONFIG=r7-v9k", "clean"], + "group": "build", + "problemMatcher": { + "base": "$gcc", + "fileLocation": ["relative", "${workspaceRoot}/g2core"] + } + }, { "label": "Build CONFIG=CheapoLaser Debug", "type": "process", diff --git a/Motate b/Motate index 20a2e13d..ce658549 160000 --- a/Motate +++ b/Motate @@ -1 +1 @@ -Subproject commit 20a2e13d70c036f62f7973f16c1c2dd2b22e982b +Subproject commit ce6585499db1d282c1b93296c9c3c7b0603dc63d diff --git a/README.md b/README.md index a715122b..143a04d0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ g2core -[![Build Status](https://travis-ci.org/synthetos/g2.svg?branch=edge)](https://travis-ci.org/synthetos/g2) [![Issues in Ready](https://badge.waffle.io/synthetos/g2.svg?label=ready&title=Ready)](http://waffle.io/synthetos/g2) [![Issues in Progress](https://badge.waffle.io/synthetos/g2.svg?label=in%20progress&title=In%20Progress)](http://waffle.io/synthetos/g2) +[![Build Status](https://travis-ci.org/synthetos/g2.svg?branch=edge)](https://travis-ci.org/synthetos/g2) # What it is diff --git a/g2core/Makefile b/g2core/Makefile index c2b2558b..3f4c6b37 100644 --- a/g2core/Makefile +++ b/g2core/Makefile @@ -65,8 +65,7 @@ endif # DEVICE_DEFINES += DEBUG=1 IN_DEBUGGER=1 DEBUG_SEMIHOSTING=1 #endif -TOOLS_VERSION = 7u2 -# TOOLS_VERSION = 9m +TOOLS_VERSION = 12.2r1 # Now invoke the Motate compile system include $(MOTATE_PATH)/Motate.mk diff --git a/g2core/board/ArduinoDue/board_gpio.cpp b/g2core/board/ArduinoDue/board_gpio.cpp index b43baca3..55db86ae 100644 --- a/g2core/board/ArduinoDue/board_gpio.cpp +++ b/g2core/board/ArduinoDue/board_gpio.cpp @@ -87,50 +87,6 @@ gpioDigitalOutputPin> dout gpioDigitalInput* const d_in[] = {&din1, &din2, &din3, &din4, &din5, &din6, &din7, &din8, &din9}; gpioDigitalOutput* const d_out[] = {&dout1, &dout2, &dout3, &dout4, &dout5, &dout6, &dout7, &dout8, &dout9, &dout10, &dout11, &dout12, &dout13}; -// not yet used -gpioAnalogInput* a_in[] = {}; -// gpioAnalogOutput* a_out[A_OUT_CHANNELS]; - -#if HAS_PRESSURE -Motate::SPIChipSelectPin pressure_cs{}; -// BME280 pressure_sensor{spiBus, pressure_cs}; -TruStabilitySSC pressure_sensor{spiBus, - pressure_cs, - /*min_output:*/ 1638, // 10% of 2^12 - /*max_output:*/ 14745, // 90% of 2^12 - /*min_value:*/ 0.0, // 0psi - /*max_value:*/ 15.0, // 15psi - PressureUnits::PSI}; -#endif - -/************************************************************************************ - **** CODE ************************************************************************** - ************************************************************************************/ - -// Register a SysTick event to call start_sampling every temperature_sample_freq ms -const int16_t ain_sample_freq = 2; -int16_t ain_sample_counter = ain_sample_freq; -Motate::SysTickEvent ain_tick_event{ - [] { - if (!--ain_sample_counter) { - ai1.startSampling(); - ai2.startSampling(); - ai3.startSampling(); - ai4.startSampling(); - - #if HAS_PRESSURE - pressure_sensor.startSampling(); // has a timeout built in to prevent over-calling - #endif - - ain_sample_counter = ain_sample_freq; - } - }, - nullptr -}; - -/* - * gpio_reset() - reset inputs and outputs (no initialization) - */ void outputs_reset(void) { @@ -140,3 +96,4 @@ void outputs_reset(void) { void inputs_reset(void) { // nothing to do } +//https://drive.google.com/file/d/1SAU-vpRx9YbPC1ikLeY-4K2qexnzPPKU/view?usp=sharing \ No newline at end of file diff --git a/g2core/board/G2v9/board_gpio.h b/g2core/board/G2v9/board_gpio.h index 18ffc5e7..3106409c 100644 --- a/g2core/board/G2v9/board_gpio.h +++ b/g2core/board/G2v9/board_gpio.h @@ -37,64 +37,54 @@ */ //--- change as required for board and switch hardware ---// -#define D_IN_CHANNELS 10 // v9 // number of digital inputs supported -#define D_OUT_CHANNELS 13 // number of digital outputs supported -#define A_IN_CHANNELS 0 // number of analog inputs supported -#define A_OUT_CHANNELS 0 // number of analog outputs supported +#define D_IN_CHANNELS 10 // v9 // number of digital inputs supported +#define D_OUT_CHANNELS 13 // number of digital outputs supported +#define A_IN_CHANNELS 0 // number of analog inputs supported +#define A_OUT_CHANNELS 0 // number of analog outputs supported -#define INPUT_LOCKOUT_MS 10 // milliseconds to go dead after input firing - -// Setup spindle and coolant pin assignments -#define SPINDLE_ENABLE_OUTPUT_NUMBER 1 -#define SPINDLE_DIRECTION_OUTPUT_NUMBER 2 -#define SPINDLE_PWM_NUMBER 3 -#define MIST_ENABLE_OUTPUT_NUMBER 4 - -#define FLOOD_ENABLE_OUTPUT_NUMBER 0 -#define SECONDARY_PWM_OUTPUT_NUMBER 0 +#define INPUT_LOCKOUT_MS 10 // milliseconds to go dead after input firing /* * The GPIO objects themselves - this must match up with board_gpio.cpp! */ -extern gpioDigitalInput* const d_in[D_IN_CHANNELS]; -extern gpioDigitalOutput* const d_out[D_OUT_CHANNELS]; +extern gpioDigitalInput* const d_in[D_IN_CHANNELS]; +extern gpioDigitalOutput* const d_out[D_OUT_CHANNELS]; // extern gpioAnalogInput* a_in[A_IN_CHANNELS]; // extern gpioAnalogOutput* a_out[A_OUT_CHANNELS]; // prepare the objects as externs (for config_app to not bloat) using Motate::IRQPin; -using Motate::PWMOutputPin; using Motate::PWMLikeOutputPin; -template +using Motate::PWMOutputPin; +template using OutputType = typename std::conditional, PWMLikeOutputPin>::type; -extern gpioDigitalInputPin> din1; -extern gpioDigitalInputPin> din2; -extern gpioDigitalInputPin> din3; -extern gpioDigitalInputPin> din4; -extern gpioDigitalInputPin> din5; -extern gpioDigitalInputPin> din6; -extern gpioDigitalInputPin> din7; -extern gpioDigitalInputPin> din8; -extern gpioDigitalInputPin> din9; +extern gpioDigitalInputPin> din1; +extern gpioDigitalInputPin> din2; +extern gpioDigitalInputPin> din3; +extern gpioDigitalInputPin> din4; +extern gpioDigitalInputPin> din5; +extern gpioDigitalInputPin> din6; +extern gpioDigitalInputPin> din7; +extern gpioDigitalInputPin> din8; +extern gpioDigitalInputPin> din9; extern gpioDigitalInputPin> din10; // extern gpioDigitalInputPin> din11; // extern gpioDigitalInputPin> din12; -extern gpioDigitalOutputPin> dout1; -extern gpioDigitalOutputPin> dout2; -extern gpioDigitalOutputPin> dout3; -extern gpioDigitalOutputPin> dout4; -extern gpioDigitalOutputPin> dout5; -extern gpioDigitalOutputPin> dout6; -extern gpioDigitalOutputPin> dout7; -extern gpioDigitalOutputPin> dout8; -extern gpioDigitalOutputPin> dout9; +extern gpioDigitalOutputPin> dout1; +extern gpioDigitalOutputPin> dout2; +extern gpioDigitalOutputPin> dout3; +extern gpioDigitalOutputPin> dout4; +extern gpioDigitalOutputPin> dout5; +extern gpioDigitalOutputPin> dout6; +extern gpioDigitalOutputPin> dout7; +extern gpioDigitalOutputPin> dout8; +extern gpioDigitalOutputPin> dout9; extern gpioDigitalOutputPin> dout10; extern gpioDigitalOutputPin> dout11; extern gpioDigitalOutputPin> dout12; extern gpioDigitalOutputPin> dout13; - -#endif // End of include guard: BOARD_GPIO_H_ONCE +#endif // End of include guard: BOARD_GPIO_H_ONCE diff --git a/g2core/boards.mk b/g2core/boards.mk index 96a4f764..3326067c 100644 --- a/g2core/boards.mk +++ b/g2core/boards.mk @@ -258,6 +258,13 @@ ifeq ("$(CONFIG)","r7") SETTINGS_FILE="settings_smw3d_r7.h" endif +ifeq ("$(CONFIG)","r7-v9k") + ifeq ("$(BOARD)","NONE") + BOARD=g2v9k + endif + SETTINGS_FILE="settings_smw3d_r7_v9k.h" +endif + ########## # Synthetos Pendulum v2 config: diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp index d344805f..446c612d 100644 --- a/g2core/canonical_machine.cpp +++ b/g2core/canonical_machine.cpp @@ -86,54 +86,54 @@ * and have no buffer. */ -#include "g2core.h" // #1 -#include "config.h" // #2 -#include "gcode.h" // #3 #include "canonical_machine.h" -#include "hardware.h" -#include "controller.h" -#include "json_parser.h" -#include "text_parser.h" -#include "settings.h" +#include "config.h" // #2 +#include "controller.h" +#include "coolant.h" +#include "encoder.h" +#include "g2core.h" // #1 +#include "gcode.h" // #3 +#include "gpio.h" +#include "hardware.h" +#include "json_parser.h" +#include "kinematics.h" // for forward kinematics in cm_cycle_start #include "plan_arc.h" #include "planner.h" -#include "stepper.h" -#include "encoder.h" -#include "spindle.h" -#include "coolant.h" #include "pwm.h" #include "report.h" -#include "gpio.h" -#include "temperature.h" -#include "hardware.h" -#include "util.h" #include "settings.h" -#include "xio.h" // for serial queue flush -#include "kinematics.h" // for forward kinematics in cm_cycle_start +#include "spindle.h" +#include "stepper.h" +#include "temperature.h" +#include "text_parser.h" +#include "util.h" +#include "xio.h" // for serial queue flush /**************************************************************************************** **** CM GLOBALS & STRUCTURE ALLOCATIONS ************************************************ ****************************************************************************************/ -cmMachine_t *cm; // pointer to active canonical machine -cmMachine_t cm1; // canonical machine primary machine -cmMachine_t cm2; // canonical machine secondary machine -cmToolTable_t tt; // global tool table +cmMachine_t *cm; // pointer to active canonical machine +cmMachine_t cm1; // canonical machine primary machine +cmMachine_t cm2; // canonical machine secondary machine +cmToolTable_t tt; // global tool table /**************************************************************************************** **** GENERIC STATIC FUNCTIONS AND VARIABLES ******************************************** ****************************************************************************************/ -static int8_t _axis(const nvObj_t *nv); // return axis number from token/group in nv +static int8_t _axis(const nvObj_t *nv); // return axis number from token/group in nv /* * _hold_input_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputHandler _hold_input_handler { +gpioDigitalInputHandler _hold_input_handler{ [](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { - if (edge != INPUT_EDGE_LEADING) { return false; } + if (edge != INPUT_EDGE_LEADING) { + return false; + } // any action = d_in[triggering_pin_number]->getAction(); // if (action == INPUT_ACTION_STOP) { @@ -145,79 +145,86 @@ gpioDigitalInputHandler _hold_input_handler { cm_request_feedhold(FEEDHOLD_TYPE_HOLD, FEEDHOLD_EXIT_STOP); - return false; // allow others to see this notice + return false; // allow others to see this notice }, - 5, // priority - nullptr // next - nullptr to start with + 5, // priority + nullptr // next - nullptr to start with }; /* * _halt_input_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputHandler _halt_input_handler { +gpioDigitalInputHandler _halt_input_handler{ [](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { - if (edge != INPUT_EDGE_LEADING) { return false; } + if (edge != INPUT_EDGE_LEADING) { + return false; + } - cm_halt(); // hard stop, including spindle, coolant and heaters + cm_halt(); // hard stop, including spindle, coolant and heaters - return false; // allow others to see this notice + return false; // allow others to see this notice }, - 5, // priority - nullptr // next - nullptr to start with + 5, // priority + nullptr // next - nullptr to start with }; - /* * _alarm_input_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputHandler _alarm_input_handler { +gpioDigitalInputHandler _alarm_input_handler{ [](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { - if (edge != INPUT_EDGE_LEADING) { return false; } + if (edge != INPUT_EDGE_LEADING) { + return false; + } char msg[10]; sprintf(msg, "input %d", triggering_pin_number); cm_alarm(STAT_ALARM, msg); - return false; // allow others to see this notice + return false; // allow others to see this notice }, - 5, // priority - nullptr // next - nullptr to start with + 5, // priority + nullptr // next - nullptr to start with }; /* * _panic_input_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputHandler _panic_input_handler { +gpioDigitalInputHandler _panic_input_handler{ [](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { - if (edge != INPUT_EDGE_LEADING) { return false; } + if (edge != INPUT_EDGE_LEADING) { + return false; + } char msg[10]; sprintf(msg, "input %d", triggering_pin_number); cm_panic(STAT_PANIC, msg); - return false; // allow others to see this notice + return false; // allow others to see this notice }, - 5, // priority - nullptr // next - nullptr to start with + 5, // priority + nullptr // next - nullptr to start with }; /* * _reset_input_handler - a gpioDigitalInputHandler to capture pin change events * Will be registered at init */ -gpioDigitalInputHandler _reset_input_handler { +gpioDigitalInputHandler _reset_input_handler{ [](const bool state, const inputEdgeFlag edge, const uint8_t triggering_pin_number) { - if (edge != INPUT_EDGE_LEADING) { return false; } + if (edge != INPUT_EDGE_LEADING) { + return false; + } hw_hard_reset(); - return false; // this likely won't be seen, but just in case... + return false; // this likely won't be seen, but just in case... }, - 5, // priority - nullptr // next - nullptr to start with + 5, // priority + nullptr // next - nullptr to start with }; /**************************************************************************************** @@ -234,15 +241,14 @@ gpioDigitalInputHandler _reset_input_handler { * canonical_machine_reset_rotation() */ -void canonical_machine_inits() -{ +void canonical_machine_inits() { planner_init(&mp1, &mr1, mp1_queue, PLANNER_QUEUE_SIZE); planner_init(&mp2, &mr2, mp2_queue, SECONDARY_QUEUE_SIZE); - canonical_machine_init(&cm1, &mp1); // primary canonical machine - canonical_machine_init(&cm2, &mp2); // secondary canonical machine - cm = &cm1; // set global canonical machine pointer to primary machine - mp = &mp1; // set global pointer to the primary planner - mr = &mr1; // and primary runtime + canonical_machine_init(&cm1, &mp1); // primary canonical machine + canonical_machine_init(&cm2, &mp2); // secondary canonical machine + cm = &cm1; // set global canonical machine pointer to primary machine + mp = &mp1; // set global pointer to the primary planner + mr = &mr1; // and primary runtime din_handlers[INPUT_ACTION_STOP].registerHandler(&_hold_input_handler); din_handlers[INPUT_ACTION_FAST_STOP].registerHandler(&_hold_input_handler); @@ -252,34 +258,32 @@ void canonical_machine_inits() din_handlers[INPUT_ACTION_RESET].registerHandler(&_reset_input_handler); } -void canonical_machine_init(cmMachine_t *_cm, void *_mp) -{ +void canonical_machine_init(cmMachine_t *_cm, void *_mp) { // Note cm* was assignd in main() // If you can assume all memory has been zeroed by a hard reset you don't need this code: - memset(_cm, 0, sizeof(cmMachine_t)); // do not reset canonicalMachine once it's been initialized - memset(&_cm->gm, 0, sizeof(GCodeState_t)); // clear all values, pointers and status + memset(_cm, 0, sizeof(cmMachine_t)); // do not reset canonicalMachine once it's been initialized + memset(&_cm->gm, 0, sizeof(GCodeState_t)); // clear all values, pointers and status - canonical_machine_init_assertions(_cm); // establish assertions - cm_arc_init(_cm); // setup arcs. Note: spindle and coolant inits are independent - _cm->mp = _mp; // point to associated planner - _cm->am = MODEL; // setup initial Gcode model pointer + canonical_machine_init_assertions(_cm); // establish assertions + cm_arc_init(_cm); // setup arcs. Note: spindle and coolant inits are independent + _cm->mp = _mp; // point to associated planner + _cm->am = MODEL; // setup initial Gcode model pointer } // *** Note: Run canonical_machine_init and profile initializations beforehand *** -void canonical_machine_reset(cmMachine_t *_cm) -{ +void canonical_machine_reset(cmMachine_t *_cm) { // reset canonical machine assertions canonical_machine_init_assertions(_cm); // set canonical machine gcode defaults cm_set_units_mode(cm->default_units_mode); - cm_set_coord_system(cm->default_coord_system); // NB: queues a block to the planner with the coordinates + cm_set_coord_system(cm->default_coord_system); // NB: queues a block to the planner with the coordinates cm_select_plane(cm->default_select_plane); cm_set_path_control(MODEL, cm->default_path_control); cm_set_distance_mode(cm->default_distance_mode); - cm_set_arc_distance_mode(INCREMENTAL_DISTANCE_MODE); // always the default - cm_set_feed_rate_mode(UNITS_PER_MINUTE_MODE); // always the default - cm_reset_overrides(); // set overrides to initial conditions + cm_set_arc_distance_mode(INCREMENTAL_DISTANCE_MODE); // always the default + cm_set_feed_rate_mode(UNITS_PER_MINUTE_MODE); // always the default + cm_reset_overrides(); // set overrides to initial conditions // NOTE: Should unhome axes here _cm->homing_state = HOMING_NOT_HOMED; @@ -288,27 +292,26 @@ void canonical_machine_reset(cmMachine_t *_cm) _cm->queue_flush_state = QUEUE_FLUSH_OFF; _cm->cycle_start_state = CYCLE_START_OFF; _cm->job_kill_state = JOB_KILL_OFF; - _cm->limit_requested = 0; // resets switch closures that occurred during initialization + _cm->limit_requested = 0; // resets switch closures that occurred during initialization // set initial state and signal that the machine is ready for action _cm->cycle_type = CYCLE_NONE; _cm->motion_state = MOTION_STOP; _cm->hold_state = FEEDHOLD_OFF; _cm->gmx.block_delete_switch = true; - _cm->gm.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE; // never start in a motion mode + _cm->gm.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE; // never start in a motion mode _cm->machine_state = MACHINE_READY; - cm_operation_init(); // reset operations runner + cm_operation_init(); // reset operations runner canonical_machine_reset_rotation(_cm); - memset(&_cm->probe_state, 0, sizeof(cmProbeState)*PROBES_STORED); - memset(&_cm->probe_results, 0, sizeof(float)*PROBES_STORED*AXES); + memset(&_cm->probe_state, 0, sizeof(cmProbeState) * PROBES_STORED); + memset(&_cm->probe_results, 0, sizeof(float) * PROBES_STORED * AXES); } void canonical_machine_reset_rotation(cmMachine_t *_cm) { - // Make it an identity matrix for no rotation - memset(&_cm->rotation_matrix, 0, sizeof(float)*3*3); + memset(&_cm->rotation_matrix, 0, sizeof(float) * 3 * 3); _cm->rotation_matrix[0][0] = 1.0; _cm->rotation_matrix[1][1] = 1.0; _cm->rotation_matrix[2][2] = 1.0; @@ -323,8 +326,7 @@ void canonical_machine_reset_rotation(cmMachine_t *_cm) { * canonical_machine_test_assertions() - test assertions, return error code if violation exists */ -void canonical_machine_init_assertions(cmMachine_t *_cm) -{ +void canonical_machine_init_assertions(cmMachine_t *_cm) { _cm->magic_start = MAGICNUM; _cm->magic_end = MAGICNUM; _cm->gmx.magic_start = MAGICNUM; @@ -333,12 +335,10 @@ void canonical_machine_init_assertions(cmMachine_t *_cm) _cm->arc.magic_end = MAGICNUM; } -stat_t canonical_machine_test_assertions(cmMachine_t *_cm) -{ - if ((BAD_MAGIC(_cm->magic_start)) || (BAD_MAGIC(_cm->magic_end)) || - (BAD_MAGIC(_cm->gmx.magic_start)) || (BAD_MAGIC(_cm->gmx.magic_end)) || - (BAD_MAGIC(_cm->arc.magic_start)) || (BAD_MAGIC(_cm->arc.magic_end))) { - return(cm_panic(STAT_CANONICAL_MACHINE_ASSERTION_FAILURE, "canonical_machine_test_assertions()")); +stat_t canonical_machine_test_assertions(cmMachine_t *_cm) { + if ((BAD_MAGIC(_cm->magic_start)) || (BAD_MAGIC(_cm->magic_end)) || (BAD_MAGIC(_cm->gmx.magic_start)) || + (BAD_MAGIC(_cm->gmx.magic_end)) || (BAD_MAGIC(_cm->arc.magic_start)) || (BAD_MAGIC(_cm->arc.magic_end))) { + return (cm_panic(STAT_CANONICAL_MACHINE_ASSERTION_FAILURE, "canonical_machine_test_assertions()")); } return (STAT_OK); } @@ -349,8 +349,7 @@ stat_t canonical_machine_test_assertions(cmMachine_t *_cm) /* * cm_set_motion_state() - adjusts active model pointer as well */ -void cm_set_motion_state(const cmMotionState motion_state) -{ +void cm_set_motion_state(const cmMotionState motion_state) { cm->motion_state = motion_state; ACTIVE_MODEL = ((motion_state == MOTION_STOP) ? MODEL : RUNTIME); } @@ -363,34 +362,51 @@ void cm_set_motion_state(const cmMotionState motion_state) * cm_get_homing_state() * cm_get_probe_state() */ -cmMachineState cm_get_machine_state() { return cm->machine_state;} -cmCycleType cm_get_cycle_type() { return cm->cycle_type;} -cmMotionState cm_get_motion_state() { return cm->motion_state;} -cmFeedholdState cm_get_hold_state() { return cm->hold_state;} -cmHomingState cm_get_homing_state() { return cm->homing_state;} -cmProbeState cm_get_probe_state() { return cm->probe_state[0];} +cmMachineState cm_get_machine_state() { return cm->machine_state; } +cmCycleType cm_get_cycle_type() { return cm->cycle_type; } +cmMotionState cm_get_motion_state() { return cm->motion_state; } +cmFeedholdState cm_get_hold_state() { return cm->hold_state; } +cmHomingState cm_get_homing_state() { return cm->homing_state; } +cmProbeState cm_get_probe_state() { return cm->probe_state[0]; } /* * cm_get_combined_state() - combines raw states into something a user might want to see */ -cmCombinedState cm_get_combined_state(cmMachine_t *_cm) -{ - switch(_cm->machine_state) { +cmCombinedState cm_get_combined_state(cmMachine_t *_cm) { + switch (_cm->machine_state) { case MACHINE_INITIALIZING: case MACHINE_READY: case MACHINE_ALARM: case MACHINE_PROGRAM_STOP: - case MACHINE_PROGRAM_END: { return ((cmCombinedState)_cm->machine_state); } - case MACHINE_INTERLOCK: { return (COMBINED_INTERLOCK); } - case MACHINE_SHUTDOWN: { return (COMBINED_SHUTDOWN); } - case MACHINE_PANIC: { return (COMBINED_PANIC); } + case MACHINE_PROGRAM_END: { + return ((cmCombinedState)_cm->machine_state); + } + case MACHINE_INTERLOCK: { + return (COMBINED_INTERLOCK); + } + case MACHINE_SHUTDOWN: { + return (COMBINED_SHUTDOWN); + } + case MACHINE_PANIC: { + return (COMBINED_PANIC); + } case MACHINE_CYCLE: { - switch(_cm->cycle_type) { - case CYCLE_NONE: { break; } // CYCLE_NONE cannot ever get here - case CYCLE_MACHINING: { return (_cm->hold_state == FEEDHOLD_OFF ? COMBINED_RUN : COMBINED_HOLD); } - case CYCLE_HOMING: { return (COMBINED_HOMING); } - case CYCLE_PROBE: { return (COMBINED_PROBE); } - case CYCLE_JOG: { return (COMBINED_JOG); } + switch (_cm->cycle_type) { + case CYCLE_NONE: { + break; + } // CYCLE_NONE cannot ever get here + case CYCLE_MACHINING: { + return (_cm->hold_state == FEEDHOLD_OFF ? COMBINED_RUN : COMBINED_HOLD); + } + case CYCLE_HOMING: { + return (COMBINED_HOMING); + } + case CYCLE_PROBE: { + return (COMBINED_PROBE); + } + case CYCLE_JOG: { + return (COMBINED_JOG); + } } } } @@ -407,44 +423,38 @@ cmCombinedState cm_get_combined_state(cmMachine_t *_cm) * ACTIVE_MODEL cm->am // active model pointer is maintained by state management */ -uint32_t cm_get_linenum(const GCodeState_t *gcode_state) { return gcode_state->linenum;} -cmMotionMode cm_get_motion_mode(const GCodeState_t *gcode_state) { return gcode_state->motion_mode;} -uint8_t cm_get_coord_system(const GCodeState_t *gcode_state) { return gcode_state->coord_system;} -uint8_t cm_get_units_mode(const GCodeState_t *gcode_state) { return gcode_state->units_mode;} -uint8_t cm_get_select_plane(const GCodeState_t *gcode_state) { return gcode_state->select_plane;} -uint8_t cm_get_path_control(const GCodeState_t *gcode_state) { return gcode_state->path_control;} -uint8_t cm_get_distance_mode(const GCodeState_t *gcode_state) { return gcode_state->distance_mode;} -uint8_t cm_get_arc_distance_mode(const GCodeState_t *gcode_state) { return gcode_state->arc_distance_mode;} -uint8_t cm_get_feed_rate_mode(const GCodeState_t *gcode_state) { return gcode_state->feed_rate_mode;} -uint8_t cm_get_tool(const GCodeState_t *gcode_state) { return gcode_state->tool;} -uint8_t cm_get_block_delete_switch() { return cm->gmx.block_delete_switch;} -uint8_t cm_get_runtime_busy() { return (mp_get_runtime_busy());} -float cm_get_feed_rate(const GCodeState_t *gcode_state) { return gcode_state->feed_rate;} +uint32_t cm_get_linenum(const GCodeState_t *gcode_state) { return gcode_state->linenum; } +cmMotionMode cm_get_motion_mode(const GCodeState_t *gcode_state) { return gcode_state->motion_mode; } +uint8_t cm_get_coord_system(const GCodeState_t *gcode_state) { return gcode_state->coord_system; } +uint8_t cm_get_units_mode(const GCodeState_t *gcode_state) { return gcode_state->units_mode; } +uint8_t cm_get_select_plane(const GCodeState_t *gcode_state) { return gcode_state->select_plane; } +uint8_t cm_get_path_control(const GCodeState_t *gcode_state) { return gcode_state->path_control; } +uint8_t cm_get_distance_mode(const GCodeState_t *gcode_state) { return gcode_state->distance_mode; } +uint8_t cm_get_arc_distance_mode(const GCodeState_t *gcode_state) { return gcode_state->arc_distance_mode; } +uint8_t cm_get_feed_rate_mode(const GCodeState_t *gcode_state) { return gcode_state->feed_rate_mode; } +uint8_t cm_get_tool(const GCodeState_t *gcode_state) { return gcode_state->tool; } +uint8_t cm_get_block_delete_switch() { return cm->gmx.block_delete_switch; } +uint8_t cm_get_runtime_busy() { return (mp_get_runtime_busy()); } +float cm_get_feed_rate(const GCodeState_t *gcode_state) { return gcode_state->feed_rate; } -void cm_set_motion_mode(GCodeState_t *gcode_state, const uint8_t motion_mode) -{ +void cm_set_motion_mode(GCodeState_t *gcode_state, const uint8_t motion_mode) { gcode_state->motion_mode = (cmMotionMode)motion_mode; } -void cm_set_tool_number(GCodeState_t *gcode_state, const uint8_t tool) -{ - gcode_state->tool = tool; -} +void cm_set_tool_number(GCodeState_t *gcode_state, const uint8_t tool) { gcode_state->tool = tool; } -void cm_set_absolute_override(GCodeState_t *gcode_state, const uint8_t absolute_override) -{ +void cm_set_absolute_override(GCodeState_t *gcode_state, const uint8_t absolute_override) { gcode_state->absolute_override = (cmAbsoluteOverride)absolute_override; - cm_set_display_offsets(MODEL); // must reset offsets if you change absolute override + cm_set_display_offsets(MODEL); // must reset offsets if you change absolute override } -void cm_set_model_linenum(int32_t linenum) -{ +void cm_set_model_linenum(int32_t linenum) { if ((linenum < 0) || (linenum > MAX_LINENUM)) { linenum = 0; rpt_exception(STAT_INPUT_VALUE_RANGE_ERROR, "line number > 2B or negative; set to zero"); } - cm->gm.linenum = linenum; // you must first set the model line number, - nv_add_object((const char *)"n"); // then add the line number to the nv list + cm->gm.linenum = linenum; // you must first set the model line number, + nv_add_object((const char *)"n"); // then add the line number to the nv list } /* @@ -452,7 +462,7 @@ void cm_set_model_linenum(int32_t linenum) */ stat_t cm_check_linenum() { - if (cm->gmx.last_line_number+1 != cm->gm.linenum) { + if (cm->gmx.last_line_number + 1 != cm->gm.linenum) { debug_trap("line number out of sequence"); return STAT_LINE_NUMBER_OUT_OF_SEQUENCE; } @@ -518,8 +528,7 @@ stat_t cm_check_linenum() { * move will run in absolute coordinates and POS will display using no offsets. */ -float cm_get_combined_offset(const uint8_t axis) -{ +float cm_get_combined_offset(const uint8_t axis) { if (cm->gm.absolute_override >= ABSOLUTE_OVERRIDE_ON_DISPLAY_WITH_OFFSETS) { return (0); } @@ -530,15 +539,12 @@ float cm_get_combined_offset(const uint8_t axis) return (offset); } -float cm_get_display_offset(const GCodeState_t *gcode_state, const uint8_t axis) -{ +float cm_get_display_offset(const GCodeState_t *gcode_state, const uint8_t axis) { return (gcode_state->display_offset[axis]); } -void cm_set_display_offsets(GCodeState_t *gcode_state) -{ +void cm_set_display_offsets(GCodeState_t *gcode_state) { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - // if absolute override is on for G53 so position should be displayed with no offsets if (cm->gm.absolute_override == ABSOLUTE_OVERRIDE_ON_DISPLAY_WITH_NO_OFFSETS) { gcode_state->display_offset[axis] = 0; @@ -546,8 +552,7 @@ void cm_set_display_offsets(GCodeState_t *gcode_state) // all other cases: position should be displayed with currently active offsets else { - gcode_state->display_offset[axis] = cm->coord_offset[cm->gm.coord_system][axis] + - cm->tool_offset[axis]; + gcode_state->display_offset[axis] = cm->coord_offset[cm->gm.coord_system][axis] + cm->tool_offset[axis]; if (cm->gmx.g92_offset_enable == true) { gcode_state->display_offset[axis] += cm->gmx.g92_offset[axis]; } @@ -567,8 +572,7 @@ void cm_set_display_offsets(GCodeState_t *gcode_state) * ... that means in prevailing units (mm/inch) and with all offsets applied */ -float cm_get_display_position(const GCodeState_t *gcode_state, const uint8_t axis) -{ +float cm_get_display_position(const GCodeState_t *gcode_state, const uint8_t axis) { float position; if (gcode_state == MODEL) { @@ -576,7 +580,7 @@ float cm_get_display_position(const GCodeState_t *gcode_state, const uint8_t axi } else { position = mp_get_runtime_display_position(axis); } - if (axis <= LAST_LINEAR_AXIS) { // linears + if (axis <= LAST_LINEAR_AXIS) { // linears if (gcode_state->units_mode == INCHES) { position /= MM_PER_INCH; } @@ -590,8 +594,7 @@ float cm_get_display_position(const GCodeState_t *gcode_state, const uint8_t axi * ... machine position is always returned in mm mode. No units conversion is performed */ -float cm_get_absolute_position(const GCodeState_t *gcode_state, const uint8_t axis) -{ +float cm_get_absolute_position(const GCodeState_t *gcode_state, const uint8_t axis) { if (gcode_state == MODEL) { return (cm->gmx.position[axis]); } @@ -615,9 +618,8 @@ float cm_get_absolute_position(const GCodeState_t *gcode_state, const uint8_t ax * point. */ -void cm_update_model_position() -{ - copy_vector(cm->gmx.position, cm->gm.target); // would be mr->gm.target if from runtime +void cm_update_model_position() { + copy_vector(cm->gmx.position, cm->gm.target); // would be mr->gm.target if from runtime } /**************************************************************************************** @@ -627,21 +629,20 @@ void cm_update_model_position() * are quiescent. */ -stat_t cm_deferred_write_callback() -{ +stat_t cm_deferred_write_callback() { if ((cm->cycle_type == CYCLE_NONE) && (cm->deferred_write_flag == true)) { cm->deferred_write_flag = false; nvObj_t nv; - for (uint8_t i=1; i<=COORDS; i++) { - for (uint8_t j=0; jcoord_offset[i][j]; - nv_persist(&nv); // Note: nv_persist() only writes values that have changed + nv_persist(&nv); // Note: nv_persist() only writes values that have changed } } } @@ -655,39 +656,30 @@ stat_t cm_deferred_write_callback() * For set_tram there MUST be three valid probes stored. */ -stat_t cm_get_tram(nvObj_t *nv) -{ - nv->value_int = true; // believe it or not, the compiler likes this form best - most efficient code +stat_t cm_get_tram(nvObj_t *nv) { + nv->value_int = true; // believe it or not, the compiler likes this form best - most efficient code - if (fp_NOT_ZERO(cm->rotation_z_offset) || - fp_NOT_ZERO(cm->rotation_matrix[0][1]) || - fp_NOT_ZERO(cm->rotation_matrix[0][2]) || - fp_NOT_ZERO(cm->rotation_matrix[1][0]) || - fp_NOT_ZERO(cm->rotation_matrix[1][2]) || - fp_NOT_ZERO(cm->rotation_matrix[2][0]) || - fp_NOT_ZERO(cm->rotation_matrix[2][1]) || - fp_NE(1.0, cm->rotation_matrix[0][0]) || - fp_NE(1.0, cm->rotation_matrix[1][1]) || - fp_NE(1.0, cm->rotation_matrix[2][2])) - { + if (fp_NOT_ZERO(cm->rotation_z_offset) || fp_NOT_ZERO(cm->rotation_matrix[0][1]) || + fp_NOT_ZERO(cm->rotation_matrix[0][2]) || fp_NOT_ZERO(cm->rotation_matrix[1][0]) || + fp_NOT_ZERO(cm->rotation_matrix[1][2]) || fp_NOT_ZERO(cm->rotation_matrix[2][0]) || + fp_NOT_ZERO(cm->rotation_matrix[2][1]) || fp_NE(1.0, cm->rotation_matrix[0][0]) || + fp_NE(1.0, cm->rotation_matrix[1][1]) || fp_NE(1.0, cm->rotation_matrix[2][2])) { nv->value_int = false; } nv->valuetype = TYPE_BOOLEAN; return (STAT_OK); } -stat_t cm_set_tram(nvObj_t *nv) -{ - if (!nv->value_int) { // if false, reset the matrix and return +stat_t cm_set_tram(nvObj_t *nv) { + if (!nv->value_int) { // if false, reset the matrix and return canonical_machine_reset_rotation(cm); return (STAT_OK); } // check to make sure we have three valid probes in a row - if (!((cm->probe_state[0] == PROBE_SUCCEEDED) && - (cm->probe_state[1] == PROBE_SUCCEEDED) && + if (!((cm->probe_state[0] == PROBE_SUCCEEDED) && (cm->probe_state[1] == PROBE_SUCCEEDED) && (cm->probe_state[2] == PROBE_SUCCEEDED))) { - return (STAT_COMMAND_NOT_ACCEPTED); // do not have 3 valid probes + return (STAT_COMMAND_NOT_ACCEPTED); // do not have 3 valid probes } // Step 1: Get the normal of the plane formed by the three probes. Naming: @@ -705,13 +697,13 @@ stat_t cm_set_tram(nvObj_t *nv) // Step 1b: compute the combined magnitude // since sqrt(a)*sqrt(b) = sqrt(a*b), we can save a sqrt in making the unit normal - float combined_magnitude_inv = 1.0/sqrt((d0_x*d0_x + d0_y*d0_y + d0_z*d0_z) * - (d2_x*d2_x + d2_y*d2_y + d2_z*d2_z)); + float combined_magnitude_inv = + 1.0 / sqrt((d0_x * d0_x + d0_y * d0_y + d0_z * d0_z) * (d2_x * d2_x + d2_y * d2_y + d2_z * d2_z)); // Step 1c: compute the cross product and normalize - float n_x = (d0_z*d2_y - d0_y*d2_z) * combined_magnitude_inv; - float n_y = (d0_x*d2_z - d0_z*d2_x) * combined_magnitude_inv; - float n_z = (d0_y*d2_x - d0_x*d2_y) * combined_magnitude_inv; + float n_x = (d0_z * d2_y - d0_y * d2_z) * combined_magnitude_inv; + float n_y = (d0_x * d2_z - d0_z * d2_x) * combined_magnitude_inv; + float n_z = (d0_y * d2_x - d0_x * d2_y) * combined_magnitude_inv; // Step 1d: flip the normal if it's negative if (n_z < 0.0) { @@ -721,12 +713,12 @@ stat_t cm_set_tram(nvObj_t *nv) } // Step 2: make the quaternion for the rotation to {0,0,1} - float p = sqrt(n_x*n_x + n_y*n_y + n_z*n_z); - float m = sqrt(2.0)*sqrt(p*(p+n_z)); + float p = sqrt(n_x * n_x + n_y * n_y + n_z * n_z); + float m = sqrt(2.0) * sqrt(p * (p + n_z)); float q_w = (n_z + p) / m; float q_x = -n_y / m; float q_y = n_x / m; - //float q_z = 0; // already optimized out + // float q_z = 0; // already optimized out // Step 3: compute the rotation matrix float q_wx_2 = q_w * q_x * 2.0; @@ -756,9 +748,8 @@ stat_t cm_set_tram(nvObj_t *nv) cm->rotation_matrix[2][2] = 1 - q_xx_2 - q_yy_2; // Step 4: compute the z-offset - cm->rotation_z_offset = (n_x*cm->probe_results[1][0] + - n_y*cm->probe_results[1][1]) / - n_z + cm->probe_results[1][2]; + cm->rotation_z_offset = + (n_x * cm->probe_results[1][0] + n_y * cm->probe_results[1][1]) / n_z + cm->probe_results[1][2]; return (STAT_OK); } @@ -767,19 +758,16 @@ stat_t cm_set_tram(nvObj_t *nv) * cm_get_nxt_line() - JSON query to get the next expected line number */ -stat_t cm_set_nxln(nvObj_t *nv) -{ - if (nv->valuetype == TYPE_INTEGER || nv->valuetype == TYPE_FLOAT) - { +stat_t cm_set_nxln(nvObj_t *nv) { + if (nv->valuetype == TYPE_INTEGER || nv->valuetype == TYPE_FLOAT) { cm->gmx.last_line_number = nv->value_int - 1; return (STAT_OK); } return (STAT_INPUT_VALUE_RANGE_ERROR); } -stat_t cm_get_nxln(nvObj_t *nv) -{ - nv->value_int = cm->gmx.last_line_number+1; +stat_t cm_get_nxln(nvObj_t *nv) { + nv->value_int = cm->gmx.last_line_number + 1; nv->valuetype = TYPE_INTEGER; return (STAT_OK); } @@ -808,17 +796,15 @@ stat_t cm_get_nxln(nvObj_t *nv) // registers we moved this block into its own function so that we get a fresh stack push // ALDEN: This shows up in avr-gcc 4.7.0 and avr-libc 1.8.0 -static float _calc_ABC(const uint8_t axis, const float target[]) -{ +static float _calc_ABC(const uint8_t axis, const float target[]) { if ((cm->a[axis].axis_mode == AXIS_STANDARD) || (cm->a[axis].axis_mode == AXIS_INHIBITED)) { - return(target[axis]); // no mm conversion - it's in degrees + return (target[axis]); // no mm conversion - it's in degrees } // radius mode return (_to_millimeters(target[axis]) * 360.0 / (2 * M_PI * cm->a[axis].radius)); } -void cm_set_model_target(const float target[], const bool flags[]) -{ +void cm_set_model_target(const float target[], const bool flags[]) { uint8_t axis; float tmp = 0; @@ -826,9 +812,9 @@ void cm_set_model_target(const float target[], const bool flags[]) copy_vector(cm->gm.target, cm->gmx.position); // process linear axes (XYZUVW) first - for (axis=AXIS_X; axis<=LAST_LINEAR_AXIS; axis++) { + for (axis = AXIS_X; axis <= LAST_LINEAR_AXIS; axis++) { if (!flags[axis] || cm->a[axis].axis_mode == AXIS_DISABLED) { - continue; // skip axis if not flagged for update or its disabled + continue; // skip axis if not flagged for update or its disabled } else if ((cm->a[axis].axis_mode == AXIS_STANDARD) || (cm->a[axis].axis_mode == AXIS_INHIBITED)) { if (cm->gm.distance_mode == ABSOLUTE_DISTANCE_MODE) { cm->gm.target[axis] = cm_get_combined_offset(axis) + _to_millimeters(target[axis]); @@ -839,9 +825,9 @@ void cm_set_model_target(const float target[], const bool flags[]) } } // FYI: The ABC loop below relies on the XYZUVW loop having been run first - for (axis=AXIS_A; axis<=AXIS_C; axis++) { + for (axis = AXIS_A; axis <= AXIS_C; axis++) { if (!flags[axis] || cm->a[axis].axis_mode == AXIS_DISABLED) { - continue; // skip axis if not flagged for update or its disabled + continue; // skip axis if not flagged for update or its disabled } else { tmp = _calc_ABC(axis, target); } @@ -852,22 +838,19 @@ void cm_set_model_target(const float target[], const bool flags[]) if (mst.marlin_flavor && (cm->a[axis].axis_mode == AXIS_RADIUS)) { if ((cm->gm.distance_mode == INCREMENTAL_DISTANCE_MODE) || (mst.extruder_mode == EXTRUDER_MOVES_RELATIVE)) { cm->gm.target[axis] += tmp; - } - else { // if (cm.gmx.extruder_mode == EXTRUDER_MOVES_NORMAL) + } else { // if (cm.gmx.extruder_mode == EXTRUDER_MOVES_NORMAL) cm->gm.target[axis] = tmp + cm_get_combined_offset(axis); } // TODO - volumetric filament conversion -// else { -// cm->gm.target[axis] += tmp * cm.gmx.volume_to_filament_length[axis-3]; -// } - } - else -#endif // MARLIN_COMPAT_ENABLED + // else { + // cm->gm.target[axis] += tmp * cm.gmx.volume_to_filament_length[axis-3]; + // } + } else +#endif // MARLIN_COMPAT_ENABLED - if (cm->gm.distance_mode == ABSOLUTE_DISTANCE_MODE) { - cm->gm.target[axis] = tmp + cm_get_combined_offset(axis); // sacidu93's fix to Issue #22 - } - else { + if (cm->gm.distance_mode == ABSOLUTE_DISTANCE_MODE) { + cm->gm.target[axis] = tmp + cm_get_combined_offset(axis); // sacidu93's fix to Issue #22 + } else { cm->gm.target[axis] += tmp; } cm->return_flags[axis] = true; @@ -890,27 +873,33 @@ void cm_set_model_target(const float target[], const bool flags[]) bool cm_get_soft_limits() { return (cm->soft_limit_enable); } void cm_set_soft_limits(bool enable) { cm->soft_limit_enable = enable; } -static stat_t _finalize_soft_limits(const stat_t status) -{ - cm->gm.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE; // cancel motion - copy_vector(cm->gm.target, cm->gmx.position); // reset model target - return (cm_alarm(status, "soft_limits")); // throw an alarm +static stat_t _finalize_soft_limits(const stat_t status) { + cm->gm.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE; // cancel motion + copy_vector(cm->gm.target, cm->gmx.position); // reset model target + return (cm_alarm(status, "soft_limits")); // throw an alarm } -stat_t cm_test_soft_limits(const float target[]) -{ +stat_t cm_test_soft_limits(const float target[]) { if (cm->soft_limit_enable == true) { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - if (cm->homed[axis] != true) { continue; } // skip axis if not homed - if (fp_EQ(cm->a[axis].travel_min, cm->a[axis].travel_max)) { continue; } // skip axis if identical - if (fabs(cm->a[axis].travel_min) > DISABLE_SOFT_LIMIT) { continue; } // skip min test if disabled - if (fabs(cm->a[axis].travel_max) > DISABLE_SOFT_LIMIT) { continue; } // skip max test if disabled + if (cm->homed[axis] != true) { + continue; + } // skip axis if not homed + if (fp_EQ(cm->a[axis].travel_min, cm->a[axis].travel_max)) { + continue; + } // skip axis if identical + if (fabs(cm->a[axis].travel_min) > DISABLE_SOFT_LIMIT) { + continue; + } // skip min test if disabled + if (fabs(cm->a[axis].travel_max) > DISABLE_SOFT_LIMIT) { + continue; + } // skip max test if disabled if (target[axis] < cm->a[axis].travel_min) { - return (_finalize_soft_limits(STAT_SOFT_LIMIT_EXCEEDED_XMIN + 2*axis)); + return (_finalize_soft_limits(STAT_SOFT_LIMIT_EXCEEDED_XMIN + 2 * axis)); } if (target[axis] > cm->a[axis].travel_max) { - return (_finalize_soft_limits(STAT_SOFT_LIMIT_EXCEEDED_XMAX + 2*axis)); + return (_finalize_soft_limits(STAT_SOFT_LIMIT_EXCEEDED_XMAX + 2 * axis)); } } } @@ -939,27 +928,23 @@ stat_t cm_test_soft_limits(const float target[]) * These functions assume input validation occurred upstream, most likely in gcode parser. */ -stat_t cm_select_plane(const uint8_t plane) -{ +stat_t cm_select_plane(const uint8_t plane) { cm->gm.select_plane = (cmCanonicalPlane)plane; return (STAT_OK); } -stat_t cm_set_units_mode(const uint8_t mode) -{ - cm->gm.units_mode = (cmUnitsMode)mode; // 0 = inches, 1 = mm. - return(STAT_OK); -} - -stat_t cm_set_distance_mode(const uint8_t mode) -{ - cm->gm.distance_mode = (cmDistanceMode)mode; // 0 = absolute mode, 1 = incremental +stat_t cm_set_units_mode(const uint8_t mode) { + cm->gm.units_mode = (cmUnitsMode)mode; // 0 = inches, 1 = mm. return (STAT_OK); } -stat_t cm_set_arc_distance_mode(const uint8_t mode) -{ - cm->gm.arc_distance_mode = (cmDistanceMode)mode; // 0 = absolute mode, 1 = incremental +stat_t cm_set_distance_mode(const uint8_t mode) { + cm->gm.distance_mode = (cmDistanceMode)mode; // 0 = absolute mode, 1 = incremental + return (STAT_OK); +} + +stat_t cm_set_arc_distance_mode(const uint8_t mode) { + cm->gm.arc_distance_mode = (cmDistanceMode)mode; // 0 = absolute mode, 1 = incremental return (STAT_OK); } @@ -972,10 +957,8 @@ stat_t cm_set_arc_distance_mode(const uint8_t mode) * It also does resets the display offsets to reflect the new values. */ -stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, - const uint8_t L_word, const bool L_flag, - const float offset[], const bool flag[]) -{ +stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, const uint8_t L_word, const bool L_flag, + const float offset[], const bool flag[]) { if (!L_flag) { return (STAT_L_WORD_IS_MISSING); } @@ -983,7 +966,7 @@ stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, if ((L_word == 2) || (L_word == 20)) { // coordinate system offset command if ((P_word < G54) || (P_word > COORD_SYSTEM_MAX)) { - return (STAT_P_WORD_IS_INVALID); // you can't set G53 + return (STAT_P_WORD_IS_INVALID); // you can't set G53 } for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { @@ -991,33 +974,29 @@ stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, cm->coord_offset[P_word][axis] = _to_millimeters(offset[axis]); } else { // Should L20 take into account G92 offsets? - cm->coord_offset[P_word][axis] = cm->gmx.position[axis] - - _to_millimeters(offset[axis]) - - cm->tool_offset[axis]; + cm->coord_offset[P_word][axis] = + cm->gmx.position[axis] - _to_millimeters(offset[axis]) - cm->tool_offset[axis]; } - cm->deferred_write_flag = true; // persist offsets once machining cycle is over + cm->deferred_write_flag = true; // persist offsets once machining cycle is over } } - } - else if ((L_word == 1) || (L_word == 10)) { - if ((P_word < 1) || (P_word > TOOLS)) { // tool table offset command. L11 not supported atm. + } else if ((L_word == 1) || (L_word == 10)) { + if ((P_word < 1) || (P_word > TOOLS)) { // tool table offset command. L11 not supported atm. return (STAT_P_WORD_IS_INVALID); } for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { if (L_word == 1) { tt.tt_offset[P_word][axis] = _to_millimeters(offset[axis]); - } else { // L10 should also take into account G92 offset - tt.tt_offset[P_word][axis] = - cm->gmx.position[axis] - _to_millimeters(offset[axis]) - - cm->coord_offset[cm->gm.coord_system][axis] - - (cm->gmx.g92_offset[axis] * cm->gmx.g92_offset_enable); + } else { // L10 should also take into account G92 offset + tt.tt_offset[P_word][axis] = cm->gmx.position[axis] - _to_millimeters(offset[axis]) - + cm->coord_offset[cm->gm.coord_system][axis] - + (cm->gmx.g92_offset[axis] * cm->gmx.g92_offset_enable); } - cm->deferred_write_flag = true; // persist offsets once machining cycle is over + cm->deferred_write_flag = true; // persist offsets once machining cycle is over } } - } - else { + } else { return (STAT_L_WORD_IS_INVALID); } cm_set_display_offsets(MODEL); @@ -1032,14 +1011,13 @@ stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, * cm_set_coord_system() - G54-G59 */ -stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, const bool apply_additional) -{ +stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, const bool apply_additional) { uint8_t tool; if (H_flag) { if (H_word > TOOLS) { return (STAT_H_WORD_IS_INVALID); } - if (H_word == 0) { // interpret H0 as "current tool", just like no H at all. + if (H_word == 0) { // interpret H0 as "current tool", just like no H at all. tool = cm->gm.tool; } else { tool = H_word; @@ -1051,28 +1029,27 @@ stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, const bool appl for (uint8_t axis = AXIS_X; axis < AXES; axis++) { cm->tool_offset[axis] += tt.tt_offset[tool][axis]; } - } else { + } else { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { cm->tool_offset[axis] = tt.tt_offset[tool][axis]; } } - cm_set_display_offsets(MODEL); // display new offsets in the model right now + cm_set_display_offsets(MODEL); // display new offsets in the model right now return (STAT_OK); } -stat_t cm_cancel_tl_offset() -{ +stat_t cm_cancel_tl_offset() { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { cm->tool_offset[axis] = 0; } - cm_set_display_offsets(MODEL); // display new offsets in the model right now - return (STAT_OK); + cm_set_display_offsets(MODEL); // display new offsets in the model right now + return (STAT_OK); } stat_t cm_set_coord_system(const uint8_t coord_system) // set coordinate system sync'd with planner { cm->gm.coord_system = (cmCoordSystem)coord_system; - cm_set_display_offsets(MODEL); // must reset display offsets if you change coordinate system + cm_set_display_offsets(MODEL); // must reset display offsets if you change coordinate system return (STAT_OK); } @@ -1098,8 +1075,7 @@ stat_t cm_set_coord_system(const uint8_t coord_system) // set coordinate system * TODO: Turn this into a queued command so it executes from the planner */ -void cm_set_position_by_axis(const uint8_t axis, const float position) -{ +void cm_set_position_by_axis(const uint8_t axis, const float position) { cm->gmx.position[axis] = position; cm->gm.target[axis] = position; mp_set_planner_position(axis, position); @@ -1107,8 +1083,7 @@ void cm_set_position_by_axis(const uint8_t axis, const float position) mp_set_steps_to_runtime_position(); } -void cm_reset_position_to_absolute_position(cmMachine_t *_cm) -{ +void cm_reset_position_to_absolute_position(cmMachine_t *_cm) { mpPlanner_t *_mp = (mpPlanner_t *)_cm->mp; for (uint8_t axis = AXIS_X; axis < AXES; axis++) { cm_set_position_by_axis(axis, mp_get_runtime_absolute_position(_mp->mr, axis)); @@ -1128,28 +1103,27 @@ void cm_reset_position_to_absolute_position(cmMachine_t *_cm) * as homed. */ -static void _exec_absolute_origin(float *value, bool *flag) -{ +static void _exec_absolute_origin(float *value, bool *flag) { for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { mp_set_runtime_position(axis, value[axis]); - cm->homed[axis] = true; // G28.3 is not considered homed until you get here + cm->homed[axis] = true; // G28.3 is not considered homed until you get here } } mp_set_steps_to_runtime_position(); } - -stat_t cm_set_absolute_origin(const float origin[], bool flag[]) -{ +// BUG - flag needs copied!!! +stat_t cm_set_absolute_origin(const float origin[], bool flag[]) { float value[AXES]; for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { -// REMOVED value[axis] = cm->offset[cm->gm.coord_system][axis] + _to_millimeters(origin[axis]); // G2 Issue #26 - value[axis] = _to_millimeters(origin[axis]); // replaced the above - cm->gmx.position[axis] = value[axis]; // set model position - cm->gm.target[axis] = value[axis]; // reset model target - mp_set_planner_position(axis, value[axis]); // set mm position + // REMOVED value[axis] = cm->offset[cm->gm.coord_system][axis] + _to_millimeters(origin[axis]); // G2 + // Issue #26 + value[axis] = _to_millimeters(origin[axis]); // replaced the above + cm->gmx.position[axis] = value[axis]; // set model position + cm->gm.target[axis] = value[axis]; // reset model target + mp_set_planner_position(axis, value[axis]); // set mm position } } mp_queue_command(_exec_absolute_origin, value, flag); @@ -1166,16 +1140,13 @@ stat_t cm_set_absolute_origin(const float origin[], bool flag[]) * http://linuxcnc.org/docs/html/gcode/gcode.html#sec:G92-G92.1-G92.2-G92.3 */ -stat_t cm_set_g92_offsets(const float offset[], const bool flag[]) -{ +stat_t cm_set_g92_offsets(const float offset[], const bool flag[]) { // set offsets in the Gcode model extended context cm->gmx.g92_offset_enable = true; for (uint8_t axis = AXIS_X; axis < AXES; axis++) { if (flag[axis]) { - cm->gmx.g92_offset[axis] = cm->gmx.position[axis] - - cm->coord_offset[cm->gm.coord_system][axis] - - cm->tool_offset[axis] - - _to_millimeters(offset[axis]); + cm->gmx.g92_offset[axis] = cm->gmx.position[axis] - cm->coord_offset[cm->gm.coord_system][axis] - + cm->tool_offset[axis] - _to_millimeters(offset[axis]); } } // now pass the offset to the callback - setting the coordinate system also applies the offsets @@ -1183,8 +1154,7 @@ stat_t cm_set_g92_offsets(const float offset[], const bool flag[]) return (STAT_OK); } -stat_t cm_reset_g92_offsets() -{ +stat_t cm_reset_g92_offsets() { cm->gmx.g92_offset_enable = false; for (uint8_t axis = AXIS_X; axis < AXES; axis++) { cm->gmx.g92_offset[axis] = 0; @@ -1193,15 +1163,13 @@ stat_t cm_reset_g92_offsets() return (STAT_OK); } -stat_t cm_suspend_g92_offsets() -{ +stat_t cm_suspend_g92_offsets() { cm->gmx.g92_offset_enable = false; cm_set_display_offsets(MODEL); return (STAT_OK); } -stat_t cm_resume_g92_offsets() -{ +stat_t cm_resume_g92_offsets() { cm->gmx.g92_offset_enable = true; cm_set_display_offsets(MODEL); return (STAT_OK); @@ -1214,11 +1182,10 @@ stat_t cm_resume_g92_offsets() * cm_straight_traverse() - G0 linear rapid */ -stat_t cm_straight_traverse(const float *target, const bool *flags, const cmMotionProfile motion_profile) -{ +stat_t cm_straight_traverse(const float *target, const bool *flags, const cmMotionProfile motion_profile) { cm->gm.motion_mode = MOTION_MODE_STRAIGHT_TRAVERSE; #ifdef TRAVERSE_AT_HIGH_JERK - cm->gm.motion_profile = PROFILE_FAST; // override to make all traverses use high jerk + cm->gm.motion_profile = PROFILE_FAST; // override to make all traverses use high jerk #else cm->gm.motion_profile = motion_profile; #endif @@ -1229,18 +1196,19 @@ stat_t cm_straight_traverse(const float *target, const bool *flags, const cmMoti flags[AXIS_U] | flags[AXIS_V] | flags[AXIS_W] | #endif flags[AXIS_A] | flags[AXIS_B] | flags[AXIS_C])) { - return(STAT_OK); + return (STAT_OK); } cm_set_model_target(target, flags); - ritorno (cm_test_soft_limits(cm->gm.target)); // test soft limits; exit if thrown + ritorno(cm_test_soft_limits(cm->gm.target)); // test soft limits; exit if thrown cm_set_display_offsets(MODEL); // capture the fully resolved offsets to the state - cm_cycle_start(); // required here for homing & other cycles + cm_cycle_start(); // required here for homing & other cycles stat_t status = mp_aline(MODEL); // send the move to the planner - cm_update_model_position(); // update gmx.position to ready for next incoming move + cm_update_model_position(); // update gmx.position to ready for next incoming move if (status == STAT_MINIMUM_LENGTH_MOVE) { - if (!mp_has_runnable_buffer(mp)) { // handle condition where zero-length move is last or only move - cm_cycle_end(); // ...otherwise cycle will not end properly + if (!mp_has_runnable_buffer(mp) && + !st_runtime_isbusy()) { // handle condition where zero-length move is last or only move + cm_cycle_end(); // ...otherwise cycle will not end properly } status = STAT_OK; } @@ -1255,57 +1223,55 @@ stat_t cm_straight_traverse(const float *target, const bool *flags, const cmMoti * _goto_stored_position() - helper */ -stat_t _goto_stored_position(const float stored_position[], // always in mm - const float intermediate_target[], // in current units (G20/G21) - const bool flags[]) // all false if no intermediate move +stat_t _goto_stored_position(const float stored_position[], // always in mm + const float intermediate_target[], // in current units (G20/G21) + const bool flags[]) // all false if no intermediate move { // Go through intermediate point if one is provided - while (mp_planner_is_full(mp)); // Make sure you have available buffers + while (mp_planner_is_full(mp)) + ; // Make sure you have available buffers ritorno(cm_straight_traverse(intermediate_target, flags, PROFILE_NORMAL)); // w/no action if no axis flags // If G20 adjust stored position (always in mm) to inches so traverse will be correct - float target[AXES]; // make a local stored position as it may be modified + float target[AXES]; // make a local stored position as it may be modified copy_vector(target, stored_position); if (cm->gm.units_mode == INCHES) { - for (uint8_t i=0; igmx.g28_position, cm->gmx.position); // in MM and machine coordinates +stat_t cm_set_g28_position(void) { + copy_vector(cm->gmx.g28_position, cm->gmx.position); // in MM and machine coordinates return (STAT_OK); } -stat_t cm_goto_g28_position(const float target[], const bool flags[]) -{ +stat_t cm_goto_g28_position(const float target[], const bool flags[]) { return (_goto_stored_position(cm->gmx.g28_position, target, flags)); } -stat_t cm_set_g30_position(void) -{ - copy_vector(cm->gmx.g30_position, cm->gmx.position); // in MM and machine coordinates +stat_t cm_set_g30_position(void) { + copy_vector(cm->gmx.g30_position, cm->gmx.position); // in MM and machine coordinates return (STAT_OK); } -stat_t cm_goto_g30_position(const float target[], const bool flags[]) -{ +stat_t cm_goto_g30_position(const float target[], const bool flags[]) { return (_goto_stored_position(cm->gmx.g30_position, target, flags)); } @@ -1318,13 +1284,12 @@ stat_t cm_goto_g30_position(const float target[], const bool flags[]) * Normalize feed rate to mm/min or to minutes if in inverse time mode */ -stat_t cm_set_feed_rate(const float feed_rate) -{ +stat_t cm_set_feed_rate(const float feed_rate) { if (cm->gm.feed_rate_mode == INVERSE_TIME_MODE) { if (fp_ZERO(feed_rate)) { return (STAT_FEEDRATE_NOT_SPECIFIED); } - cm->gm.feed_rate = 1/feed_rate; // normalize to minutes (NB: active for this gcode block only) + cm->gm.feed_rate = 1 / feed_rate; // normalize to minutes (NB: active for this gcode block only) } else { cm->gm.feed_rate = _to_millimeters(feed_rate); } @@ -1339,8 +1304,7 @@ stat_t cm_set_feed_rate(const float feed_rate) * UNITS_PER_REVOLUTION_MODE // G95 (unimplemented) */ -stat_t cm_set_feed_rate_mode(const uint8_t mode) -{ +stat_t cm_set_feed_rate_mode(const uint8_t mode) { cm->gm.feed_rate_mode = (cmFeedRateMode)mode; return (STAT_OK); } @@ -1349,8 +1313,7 @@ stat_t cm_set_feed_rate_mode(const uint8_t mode) * cm_set_path_control() - G61, G61.1, G64 */ -stat_t cm_set_path_control(GCodeState_t *gcode_state, const uint8_t mode) -{ +stat_t cm_set_path_control(GCodeState_t *gcode_state, const uint8_t mode) { gcode_state->path_control = (cmPathControl)mode; return (STAT_OK); } @@ -1365,8 +1328,7 @@ stat_t cm_set_path_control(GCodeState_t *gcode_state, const uint8_t mode) /**************************************************************************************** * cm_dwell() - G4, P parameter (seconds) */ -stat_t cm_dwell(const float seconds) -{ +stat_t cm_dwell(const float seconds) { cm->gm.P_word = seconds; mp_dwell(seconds); return (STAT_OK); @@ -1376,8 +1338,7 @@ stat_t cm_dwell(const float seconds) * cm_straight_feed() - G1 */ -stat_t cm_straight_feed(const float *target, const bool *flags, const cmMotionProfile motion_profile) -{ +stat_t cm_straight_feed(const float *target, const bool *flags, const cmMotionProfile motion_profile) { // trap zero feed rate condition if (fp_ZERO(cm->gm.feed_rate)) { return (STAT_FEEDRATE_NOT_SPECIFIED); @@ -1390,19 +1351,20 @@ stat_t cm_straight_feed(const float *target, const bool *flags, const cmMotionPr flags[AXIS_U] | flags[AXIS_V] | flags[AXIS_W] | #endif flags[AXIS_A] | flags[AXIS_B] | flags[AXIS_C])) { - return(STAT_OK); + return (STAT_OK); } cm_set_model_target(target, flags); - ritorno (cm_test_soft_limits(cm->gm.target)); // test soft limits; exit if thrown + ritorno(cm_test_soft_limits(cm->gm.target)); // test soft limits; exit if thrown cm_set_display_offsets(MODEL); // capture the fully resolved offsets to the state - cm_cycle_start(); // required for homing & other cycles + cm_cycle_start(); // required for homing & other cycles stat_t status = mp_aline(MODEL); // send the move to the planner - cm_update_model_position(); // <-- ONLY safe because we don't care about status... + cm_update_model_position(); // <-- ONLY safe because we don't care about status... if (status == STAT_MINIMUM_LENGTH_MOVE) { - if (!mp_has_runnable_buffer(mp)) { // handle condition where zero-length move is last or only move - cm_cycle_end(); // ...otherwise cycle will not end properly + if (!mp_has_runnable_buffer(mp) && + !st_runtime_isbusy()) { // handle condition where zero-length move is last or only move + cm_cycle_end(); // ...otherwise cycle will not end properly } status = STAT_OK; } @@ -1427,31 +1389,25 @@ stat_t cm_straight_feed(const float *target, const bool *flags, const cmMotionPr * Note: These functions don't actually do anything for now, and there's a bug * where T and M in different blocks don't work correctly */ -static void _exec_select_tool(float *value, bool *flag) -{ - cm->gm.tool_select = (uint8_t)value[0]; -} +static void _exec_select_tool(float *value, bool *flag) { cm->gm.tool_select = (uint8_t)value[0]; } -stat_t cm_select_tool(const uint8_t tool_select) -{ +stat_t cm_select_tool(const uint8_t tool_select) { if (tool_select > TOOLS) { return (STAT_T_WORD_IS_INVALID); } - float value[] = { (float)tool_select }; + float value[] = {(float)tool_select}; mp_queue_command(_exec_select_tool, value, nullptr); return (STAT_OK); } -static void _exec_change_tool(float *value, bool *flag) -{ +static void _exec_change_tool(float *value, bool *flag) { cm->gm.tool = cm->gm.tool_select; spindle_set_toolhead(toolhead_for_tool(cm->gm.tool)); // TODO - change tool offsets and update display offsets } -stat_t cm_change_tool(const uint8_t tool_change) -{ +stat_t cm_change_tool(const uint8_t tool_change) { mp_queue_command(_exec_change_tool, nullptr, nullptr); return (STAT_OK); } @@ -1465,9 +1421,8 @@ stat_t cm_change_tool(const uint8_t tool_change) * cm_message() - queue a RAM string as a message in the response (unconditionally) */ -void cm_message(const char *message) -{ - nv_add_string((const char *)"msg", message); // add message to the response object +void cm_message(const char *message) { + nv_add_string((const char *)"msg", message); // add message to the response object } /**************************************************************************************** @@ -1478,8 +1433,7 @@ void cm_message(const char *message) * cm_reset_overrides() - reset manual feedrate and spindle overrides to initial conditions */ -void cm_reset_overrides() -{ +void cm_reset_overrides() { cm->gmx.m48_enable = true; cm->gmx.mfo_enable = true; // feed rate overrides cm->gmx.mfo_factor = 1.0; @@ -1509,11 +1463,11 @@ void cm_reset_overrides() * ENABLE ENABLE disable no action, no state change * ENABLE ENABLE ENABLE no action, no state change */ -stat_t cm_m48_enable(uint8_t enable) // M48, M49 +stat_t cm_m48_enable(uint8_t enable) // M48, M49 { // handle changes to feed override given new state of m48/m49 - cm->gmx.m48_enable = enable; // update state + cm->gmx.m48_enable = enable; // update state return (STAT_OK); } @@ -1669,27 +1623,26 @@ stat_t cm_m48_enable(uint8_t enable) // M48, M49 * 10. Turn off all heaters and fans */ -static void _exec_program_finalize(float* value, bool* flag) { +static void _exec_program_finalize(float *value, bool *flag) { // perform the following resets if it's a program END - if (cm->machine_state == MACHINE_PROGRAM_END) { - spindle_stop(); // immediate M5 - coolant_control_immediate(COOLANT_OFF,COOLANT_BOTH);// immediate M9 - temperature_reset(); // turn off all heaters and fans + if (flag != nullptr) { + spindle_stop(); // immediate M5 + coolant_control_immediate(COOLANT_OFF, COOLANT_BOTH); // immediate M9 + temperature_reset(); // turn off all heaters and fans + cm_reset_overrides(); // enable G48, reset feed rate, traverse and spindle overrides } - sr_request_status_report(SR_REQUEST_IMMEDIATE); // request a final and full status report (not filtered) + sr_request_status_report(SR_REQUEST_IMMEDIATE); // request a final and full status report (not filtered) } -static void _exec_program_stop_end(cmMachineState machine_state) -{ - // WARNING: We must not queue more than four things here, or we'll use up all the spare queue slots and crash the system - // The good news is we shouldn't need to queue much +static void _exec_program_stop_end(cmMachineState machine_state) { + // WARNING: We must not queue more than four things here, or we'll use up all the spare queue slots and crash the + // system The good news is we shouldn't need to queue much // If we are already out of cycle, then adjust the machine state - if ((cm->cycle_type == CYCLE_NONE) && // cm->cycle_type == CYCLE_MACHINING || - (cm->machine_state != MACHINE_ALARM) && - (cm->machine_state != MACHINE_SHUTDOWN)) { - cm->machine_state = machine_state; // don't update macs/cycs if we're in the middle of a canned cycle, + if ((cm->cycle_type == CYCLE_NONE) && // cm->cycle_type == CYCLE_MACHINING || + (cm->machine_state != MACHINE_ALARM) && (cm->machine_state != MACHINE_SHUTDOWN)) { + cm->machine_state = machine_state; // don't update macs/cycs if we're in the middle of a canned cycle, } // reset the rest of the states @@ -1698,63 +1651,52 @@ static void _exec_program_stop_end(cmMachineState machine_state) // perform the following resets if it's a program END if (machine_state == MACHINE_PROGRAM_END) { - cm_suspend_g92_offsets(); // G92.2 - as per NIST - cm_set_coord_system(cm->default_coord_system); // reset to default coordinate system - cm_select_plane(cm->default_select_plane); // reset to default arc plane - cm_set_distance_mode(cm->default_distance_mode); // reset to default distance mode - cm_set_arc_distance_mode(INCREMENTAL_DISTANCE_MODE);// always the default - cm_set_feed_rate_mode(UNITS_PER_MINUTE_MODE); // G94 - cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE); // NIST specifies G1 (MOTION_MODE_STRAIGHT_FEED), but we cancel motion mode. Safer. - cm_reset_overrides(); // enable G48, reset feed rate, traverse and spindle overrides + cm_suspend_g92_offsets(); // G92.2 - as per NIST + cm_set_coord_system(cm->default_coord_system); // reset to default coordinate system + cm_select_plane(cm->default_select_plane); // reset to default arc plane + cm_set_distance_mode(cm->default_distance_mode); // reset to default distance mode + cm_set_arc_distance_mode(INCREMENTAL_DISTANCE_MODE); // always the default + cm_set_feed_rate_mode(UNITS_PER_MINUTE_MODE); // G94 + cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE); // NIST specifies G1 (MOTION_MODE_STRAIGHT_FEED), + // but we cancel motion mode. Safer. // the rest will be queued and executed in _exec_program_finalize() } - cm_set_motion_state(MOTION_STOP); // also changes active model back to MODEL + cm_set_motion_state(MOTION_STOP); // also changes active model back to MODEL mp_queue_command(_exec_program_finalize, nullptr, nullptr); } // Will start a cycle regardless of whether the planner has moves or not -void cm_cycle_start() -{ - if (cm->cycle_type == CYCLE_NONE) { // don't (re)start homing, probe or other canned cycles +void cm_cycle_start() { + if (cm->cycle_type == CYCLE_NONE) { // don't (re)start homing, probe or other canned cycles cm->cycle_type = CYCLE_MACHINING; cm->machine_state = MACHINE_CYCLE; - qr_init_queue_report(); // clear queue reporting buffer counts// + qr_init_queue_report(); // clear queue reporting buffer counts// } } -void cm_cycle_end() { +void cm_cycle_end(bool from_command /* = false*/) { if (cm->cycle_type == CYCLE_MACHINING) { - // _exec_program_stop_end(MACHINE_PROGRAM_STOP); - - cm->machine_state = MACHINE_PROGRAM_STOP; + cm->machine_state = from_command ? MACHINE_PROGRAM_END : MACHINE_PROGRAM_STOP; cm->cycle_type = CYCLE_NONE; cm_set_motion_state(MOTION_STOP); + + sr_request_status_report(SR_REQUEST_IMMEDIATE); // request a final and full status report (not filtered) } } -void cm_canned_cycle_end() -{ +void cm_canned_cycle_end() { cm->cycle_type = CYCLE_NONE; _exec_program_stop_end(MACHINE_PROGRAM_STOP); } -void cm_program_stop() -{ - _exec_program_stop_end(MACHINE_PROGRAM_STOP); -} +void cm_program_stop() { _exec_program_stop_end(MACHINE_PROGRAM_STOP); } -void cm_optional_program_stop() -{ - _exec_program_stop_end(MACHINE_PROGRAM_STOP); -} +void cm_optional_program_stop() { _exec_program_stop_end(MACHINE_PROGRAM_STOP); } -void cm_program_end() -{ - _exec_program_stop_end(MACHINE_PROGRAM_END); -} +void cm_program_end() { _exec_program_stop_end(MACHINE_PROGRAM_END); } /**************************************************************************************** **** Additional Functions ************************************************************** @@ -1763,34 +1705,24 @@ void cm_program_end() * cm_json_command() - M100 * cm_json_wait() - M102 */ -stat_t cm_json_command(char *json_string) -{ - return mp_json_command(json_string); -} +stat_t cm_json_command(char *json_string) { return mp_json_command(json_string); } /* * cm_json_command_immediate() - M100.1 */ -stat_t cm_json_command_immediate(char *json_string) -{ - return mp_json_command_immediate(json_string); -} +stat_t cm_json_command_immediate(char *json_string) { return mp_json_command_immediate(json_string); } /* * cm_json_wait() - M102 */ -stat_t cm_json_wait(char *json_string) -{ - return mp_json_wait(json_string); -} +stat_t cm_json_wait(char *json_string) { return mp_json_wait(json_string); } /**************************************************************************************** * cm_run_home() - run homing sequence */ -stat_t cm_run_home(nvObj_t *nv) -{ - if (nv->value_int) { // if true +stat_t cm_run_home(nvObj_t *nv) { + if (nv->value_int) { // if true float axes[] = INIT_AXES_ONES; bool flags[] = INIT_AXES_TRUE; cm_homing_cycle_start(axes, flags); @@ -1805,13 +1737,9 @@ stat_t cm_run_home(nvObj_t *nv) * cm_run_jog() */ -float cm_get_jogging_dest(void) -{ - return cm->jogging_dest; -} +float cm_get_jogging_dest(void) { return cm->jogging_dest; } -stat_t cm_run_jog(nvObj_t *nv) -{ +stat_t cm_run_jog(nvObj_t *nv) { set_float(nv, cm->jogging_dest); cm_jogging_cycle_start(_axis(nv)); return (STAT_OK); @@ -1835,10 +1763,10 @@ stat_t cm_run_jog(nvObj_t *nv) * cm_get_axis_char() - return ASCII char for internal axis number provided */ -static int8_t _coord(nvObj_t *nv) // extract coordinate system from 3rd character +static int8_t _coord(nvObj_t *nv) // extract coordinate system from 3rd character { - char *ptr = ((*nv->group == 0) ? &nv->token[1] : &nv->group[1]); // skip past the 'g' to the number - return (std::max ((atoi(ptr)-53), -1)); // return G54-G59 as 0-5, error as -1 + char *ptr = ((*nv->group == 0) ? &nv->token[1] : &nv->group[1]); // skip past the 'g' to the number + return (std::max((atoi(ptr) - 53), -1)); // return G54-G59 as 0-5, error as -1 } /* _axis() @@ -1858,8 +1786,7 @@ static int8_t _coord(nvObj_t *nv) // extract coordinate system from 3rd charac * such as 'coph' But it should not be called in these cases in any event. */ -static int8_t _axis(const nvObj_t *nv) -{ +static int8_t _axis(const nvObj_t *nv) { auto &cfgTmp = cfgArray[nv->index]; // // test if this is a SYS parameter (global), in which case there will be no axis @@ -1881,17 +1808,16 @@ static int8_t _axis(const nvObj_t *nv) #else char axes[] = {"xyzabc"}; #endif - if ((ptr = strchr(axes, c)) == NULL) { // not NULL indicates a prefixed axis - c = *(cfgTmp.token + strlen(cfgTmp.token) -1); // get the last character - if ((ptr = strchr(axes, c)) == NULL) { // test for a postfixed axis + if ((ptr = strchr(axes, c)) == NULL) { // not NULL indicates a prefixed axis + c = *(cfgTmp.token + strlen(cfgTmp.token) - 1); // get the last character + if ((ptr = strchr(axes, c)) == NULL) { // test for a postfixed axis return (AXIS_TYPE_UNDEFINED); } } return (ptr - axes); } -cmAxisType cm_get_axis_type(const nvObj_t *nv) -{ +cmAxisType cm_get_axis_type(const nvObj_t *nv) { int8_t axis = _axis(nv); if (axis <= AXIS_TYPE_UNDEFINED) { return ((cmAxisType)axis); @@ -1902,7 +1828,7 @@ cmAxisType cm_get_axis_type(const nvObj_t *nv) return (AXIS_TYPE_LINEAR); } -char cm_get_axis_char(const int8_t axis) // Uses internal axis numbering +char cm_get_axis_char(const int8_t axis) // Uses internal axis numbering { #if (AXES == 9) char axis_char[] = "XYZUVWABC"; @@ -1950,23 +1876,23 @@ char cm_get_axis_char(const int8_t axis) // Uses internal axis numbering // Strings for text mode displays: -static const char msg_units0[] = " in"; // used by generic print functions +static const char msg_units0[] = " in"; // used by generic print functions static const char msg_units1[] = " mm"; static const char msg_units2[] = " deg"; -static const char *const msg_units[] = { msg_units0, msg_units1, msg_units2 }; +static const char *const msg_units[] = {msg_units0, msg_units1, msg_units2}; #define DEGREE_INDEX 2 static const char msg_am00[] = "[disabled]"; static const char msg_am01[] = "[standard]"; static const char msg_am02[] = "[inhibited]"; static const char msg_am03[] = "[radius]"; -static const char *const msg_am[] = { msg_am00, msg_am01, msg_am02, msg_am03}; +static const char *const msg_am[] = {msg_am00, msg_am01, msg_am02, msg_am03}; static const char msg_g20[] = "G20 - inches mode"; static const char msg_g21[] = "G21 - millimeter mode"; -static const char *const msg_unit[] = { msg_g20, msg_g21 }; +static const char *const msg_unit[] = {msg_g20, msg_g21}; -static const char msg_stat0[] = "Initializing"; // combined state (stat) uses this array +static const char msg_stat0[] = "Initializing"; // combined state (stat) uses this array static const char msg_stat1[] = "Ready"; static const char msg_stat2[] = "Alarm"; static const char msg_stat3[] = "Stop"; @@ -1980,10 +1906,8 @@ static const char msg_stat10[] = "Jog"; static const char msg_stat11[] = "Interlock"; static const char msg_stat12[] = "Shutdown"; static const char msg_stat13[] = "Panic"; -static const char *const msg_stat[] = { msg_stat0, msg_stat1, msg_stat2, msg_stat3, - msg_stat4, msg_stat5, msg_stat6, msg_stat7, - msg_stat8, msg_stat9, msg_stat10, msg_stat11, - msg_stat12, msg_stat13 }; +static const char *const msg_stat[] = {msg_stat0, msg_stat1, msg_stat2, msg_stat3, msg_stat4, msg_stat5, msg_stat6, + msg_stat7, msg_stat8, msg_stat9, msg_stat10, msg_stat11, msg_stat12, msg_stat13}; static const char msg_macs0[] = "Initializing"; static const char msg_macs1[] = "Ready"; @@ -1994,22 +1918,21 @@ static const char msg_macs5[] = "Cycle"; static const char msg_macs6[] = "Interlock"; static const char msg_macs7[] = "SHUTDOWN"; static const char msg_macs8[] = "PANIC"; -static const char *const msg_macs[] = { msg_macs0, msg_macs1, msg_macs2, msg_macs3, - msg_macs4, msg_macs5, msg_macs6, msg_macs7, - msg_macs8 }; +static const char *const msg_macs[] = {msg_macs0, msg_macs1, msg_macs2, msg_macs3, msg_macs4, + msg_macs5, msg_macs6, msg_macs7, msg_macs8}; static const char msg_cycs0[] = "Off"; static const char msg_cycs1[] = "Machining"; static const char msg_cycs2[] = "Homing"; static const char msg_cycs3[] = "Probe"; static const char msg_cycs4[] = "Jog"; -static const char *const msg_cycs[] = { msg_cycs0, msg_cycs1, msg_cycs2, msg_cycs3, msg_cycs4 }; +static const char *const msg_cycs[] = {msg_cycs0, msg_cycs1, msg_cycs2, msg_cycs3, msg_cycs4}; static const char msg_mots0[] = "Stop"; static const char msg_mots1[] = "Planning"; static const char msg_mots2[] = "Run"; static const char msg_mots3[] = "Hold"; -static const char *const msg_mots[] = { msg_mots0, msg_mots1, msg_mots2, msg_mots3 }; +static const char *const msg_mots[] = {msg_mots0, msg_mots1, msg_mots2, msg_mots3}; static const char msg_hold0[] = "Off"; static const char msg_hold1[] = "Requested"; @@ -2024,19 +1947,18 @@ static const char msg_hold9[] = "Hold Actions Complete"; static const char msg_hold10[] = "Holding"; static const char msg_hold11[] = "Hold Exit Actions Pending"; static const char msg_hold12[] = "Hold Exit Actions Complete"; -static const char *const msg_hold[] = { msg_hold0, msg_hold1, msg_hold2, msg_hold3, msg_hold4, - msg_hold5, msg_hold6, msg_hold7, msg_hold8, msg_hold9, - msg_hold10, msg_hold11, msg_hold12 }; +static const char *const msg_hold[] = {msg_hold0, msg_hold1, msg_hold2, msg_hold3, msg_hold4, msg_hold5, msg_hold6, + msg_hold7, msg_hold8, msg_hold9, msg_hold10, msg_hold11, msg_hold12}; static const char msg_home0[] = "Not Homed"; static const char msg_home1[] = "Homed"; static const char msg_home2[] = "Homing"; -static const char *const msg_home[] = { msg_home0, msg_home1, msg_home2 }; +static const char *const msg_home[] = {msg_home0, msg_home1, msg_home2}; static const char msg_probe0[] = "Probe Failed"; static const char msg_probe1[] = "Probe Succeeded"; static const char msg_probe2[] = "Probe Waiting"; -static const char *const msg_probe[] = { msg_probe0, msg_probe1, msg_probe2 }; +static const char *const msg_probe[] = {msg_probe0, msg_probe1, msg_probe2}; static const char msg_g53[] = "G53 - machine coordinate system"; static const char msg_g54[] = "G54 - coordinate system 1"; @@ -2045,37 +1967,37 @@ static const char msg_g56[] = "G56 - coordinate system 3"; static const char msg_g57[] = "G57 - coordinate system 4"; static const char msg_g58[] = "G58 - coordinate system 5"; static const char msg_g59[] = "G59 - coordinate system 6"; -static const char *const msg_coor[] = { msg_g53, msg_g54, msg_g55, msg_g56, msg_g57, msg_g58, msg_g59 }; +static const char *const msg_coor[] = {msg_g53, msg_g54, msg_g55, msg_g56, msg_g57, msg_g58, msg_g59}; static const char msg_g00[] = "G0 - linear traverse"; static const char msg_g01[] = "G1 - linear feed"; static const char msg_g02[] = "G2 - clockwise arc feed"; static const char msg_g03[] = "G3 - counter clockwise arc feed"; static const char msg_g80[] = "G80 - cancel motion mode (none active)"; -static const char *const msg_momo[] = { msg_g00, msg_g01, msg_g02, msg_g03, msg_g80 }; +static const char *const msg_momo[] = {msg_g00, msg_g01, msg_g02, msg_g03, msg_g80}; static const char msg_g17[] = "G17 - XY plane"; static const char msg_g18[] = "G18 - XZ plane"; static const char msg_g19[] = "G19 - YZ plane"; -static const char *const msg_plan[] = { msg_g17, msg_g18, msg_g19 }; +static const char *const msg_plan[] = {msg_g17, msg_g18, msg_g19}; static const char msg_g61[] = "G61 - exact path mode"; static const char msg_g6a[] = "G61.1 - exact stop mode"; static const char msg_g64[] = "G64 - continuous mode"; -static const char *const msg_path[] = { msg_g61, msg_g6a, msg_g64 }; +static const char *const msg_path[] = {msg_g61, msg_g6a, msg_g64}; static const char msg_g90[] = "G90 - absolute distance mode"; static const char msg_g91[] = "G91 - incremental distance mode"; -static const char *const msg_dist[] = { msg_g90, msg_g91 }; +static const char *const msg_dist[] = {msg_g90, msg_g91}; static const char msg_g901[] = "G90.1 - absolute distance mode"; static const char msg_g911[] = "G91.1 - incremental distance mode (default mode)"; -static const char *const msg_admo[] = { msg_g901, msg_g911 }; +static const char *const msg_admo[] = {msg_g901, msg_g911}; static const char msg_g93[] = "G93 - inverse time mode"; static const char msg_g94[] = "G94 - units-per-minute mode (i.e. feedrate mode)"; static const char msg_g95[] = "G95 - units-per-revolution mode"; -static const char *const msg_frmo[] = { msg_g93, msg_g94, msg_g95 }; +static const char *const msg_frmo[] = {msg_g93, msg_g94, msg_g95}; #else @@ -2096,38 +2018,36 @@ static const char *const msg_frmo[] = { msg_g93, msg_g94, msg_g95 }; #define msg_frmo NULL #define msg_am NULL -#endif // __TEXT_MODE +#endif // __TEXT_MODE //_get_msg_helper() - add the string for the enum to the nv, but leave it as a TYPE_INTEGER -stat_t _get_msg_helper(nvObj_t *nv, const char *const msg_array[], int32_t value) -{ +stat_t _get_msg_helper(nvObj_t *nv, const char *const msg_array[], int32_t value) { nv->value_int = value; nv->valuetype = TYPE_INTEGER; - return(nv_copy_string(nv, (const char *)GET_TEXT_ITEM(msg_array, value))); + return (nv_copy_string(nv, (const char *)GET_TEXT_ITEM(msg_array, value))); } -stat_t cm_get_stat(nvObj_t *nv) { return(_get_msg_helper(nv, msg_stat, cm_get_combined_state(&cm1)));} -stat_t cm_get_stat2(nvObj_t *nv){ return(_get_msg_helper(nv, msg_stat, cm_get_combined_state(&cm2)));} -stat_t cm_get_macs(nvObj_t *nv) { return(_get_msg_helper(nv, msg_macs, cm_get_machine_state()));} -stat_t cm_get_cycs(nvObj_t *nv) { return(_get_msg_helper(nv, msg_cycs, cm_get_cycle_type()));} -stat_t cm_get_mots(nvObj_t *nv) { return(_get_msg_helper(nv, msg_mots, cm_get_motion_state()));} -stat_t cm_get_hold(nvObj_t *nv) { return(_get_msg_helper(nv, msg_hold, cm_get_hold_state()));} +stat_t cm_get_stat(nvObj_t *nv) { return (_get_msg_helper(nv, msg_stat, cm_get_combined_state(&cm1))); } +stat_t cm_get_stat2(nvObj_t *nv) { return (_get_msg_helper(nv, msg_stat, cm_get_combined_state(&cm2))); } +stat_t cm_get_macs(nvObj_t *nv) { return (_get_msg_helper(nv, msg_macs, cm_get_machine_state())); } +stat_t cm_get_cycs(nvObj_t *nv) { return (_get_msg_helper(nv, msg_cycs, cm_get_cycle_type())); } +stat_t cm_get_mots(nvObj_t *nv) { return (_get_msg_helper(nv, msg_mots, cm_get_motion_state())); } +stat_t cm_get_hold(nvObj_t *nv) { return (_get_msg_helper(nv, msg_hold, cm_get_hold_state())); } -stat_t cm_get_unit(nvObj_t *nv) { return(_get_msg_helper(nv, msg_unit, cm_get_units_mode(ACTIVE_MODEL)));} -stat_t cm_get_coor(nvObj_t *nv) { return(_get_msg_helper(nv, msg_coor, cm_get_coord_system(ACTIVE_MODEL)));} -stat_t cm_get_momo(nvObj_t *nv) { return(_get_msg_helper(nv, msg_momo, cm_get_motion_mode(ACTIVE_MODEL)));} -stat_t cm_get_plan(nvObj_t *nv) { return(_get_msg_helper(nv, msg_plan, cm_get_select_plane(ACTIVE_MODEL)));} -stat_t cm_get_path(nvObj_t *nv) { return(_get_msg_helper(nv, msg_path, cm_get_path_control(ACTIVE_MODEL)));} -stat_t cm_get_dist(nvObj_t *nv) { return(_get_msg_helper(nv, msg_dist, cm_get_distance_mode(ACTIVE_MODEL)));} -stat_t cm_get_admo(nvObj_t *nv) { return(_get_msg_helper(nv, msg_admo, cm_get_arc_distance_mode(ACTIVE_MODEL)));} -stat_t cm_get_frmo(nvObj_t *nv) { return(_get_msg_helper(nv, msg_frmo, cm_get_feed_rate_mode(ACTIVE_MODEL)));} +stat_t cm_get_unit(nvObj_t *nv) { return (_get_msg_helper(nv, msg_unit, cm_get_units_mode(ACTIVE_MODEL))); } +stat_t cm_get_coor(nvObj_t *nv) { return (_get_msg_helper(nv, msg_coor, cm_get_coord_system(ACTIVE_MODEL))); } +stat_t cm_get_momo(nvObj_t *nv) { return (_get_msg_helper(nv, msg_momo, cm_get_motion_mode(ACTIVE_MODEL))); } +stat_t cm_get_plan(nvObj_t *nv) { return (_get_msg_helper(nv, msg_plan, cm_get_select_plane(ACTIVE_MODEL))); } +stat_t cm_get_path(nvObj_t *nv) { return (_get_msg_helper(nv, msg_path, cm_get_path_control(ACTIVE_MODEL))); } +stat_t cm_get_dist(nvObj_t *nv) { return (_get_msg_helper(nv, msg_dist, cm_get_distance_mode(ACTIVE_MODEL))); } +stat_t cm_get_admo(nvObj_t *nv) { return (_get_msg_helper(nv, msg_admo, cm_get_arc_distance_mode(ACTIVE_MODEL))); } +stat_t cm_get_frmo(nvObj_t *nv) { return (_get_msg_helper(nv, msg_frmo, cm_get_feed_rate_mode(ACTIVE_MODEL))); } -stat_t cm_get_toolv(nvObj_t *nv) { return(get_integer(nv, cm_get_tool(ACTIVE_MODEL))); } -stat_t cm_get_mline(nvObj_t *nv) { return(get_integer(nv, cm_get_linenum(MODEL))); } -stat_t cm_get_line(nvObj_t *nv) { return(get_integer(nv, cm_get_linenum(ACTIVE_MODEL))); } +stat_t cm_get_toolv(nvObj_t *nv) { return (get_integer(nv, cm_get_tool(ACTIVE_MODEL))); } +stat_t cm_get_mline(nvObj_t *nv) { return (get_integer(nv, cm_get_linenum(MODEL))); } +stat_t cm_get_line(nvObj_t *nv) { return (get_integer(nv, cm_get_linenum(ACTIVE_MODEL))); } -stat_t cm_get_vel(nvObj_t *nv) -{ +stat_t cm_get_vel(nvObj_t *nv) { if (cm_get_motion_state() == MOTION_STOP) { nv->value_flt = 0; } else { @@ -2142,44 +2062,42 @@ stat_t cm_get_vel(nvObj_t *nv) } stat_t cm_get_feed(nvObj_t *nv) { return (get_float(nv, cm_get_feed_rate(ACTIVE_MODEL))); } -stat_t cm_get_pos(nvObj_t *nv) { return (get_float(nv, cm_get_display_position(ACTIVE_MODEL, _axis(nv)))); } -stat_t cm_get_mpo(nvObj_t *nv) { return (get_float(nv, cm_get_absolute_position(ACTIVE_MODEL, _axis(nv)))); } -stat_t cm_get_ofs(nvObj_t *nv) { return (get_float(nv, cm_get_display_offset(ACTIVE_MODEL, _axis(nv)))); } +stat_t cm_get_pos(nvObj_t *nv) { return (get_float(nv, cm_get_display_position(ACTIVE_MODEL, _axis(nv)))); } +stat_t cm_get_mpo(nvObj_t *nv) { return (get_float(nv, cm_get_absolute_position(ACTIVE_MODEL, _axis(nv)))); } +stat_t cm_get_ofs(nvObj_t *nv) { return (get_float(nv, cm_get_display_offset(ACTIVE_MODEL, _axis(nv)))); } -stat_t cm_get_home(nvObj_t *nv) { return(_get_msg_helper(nv, msg_home, cm_get_homing_state())); } +stat_t cm_get_home(nvObj_t *nv) { return (_get_msg_helper(nv, msg_home, cm_get_homing_state())); } stat_t cm_set_home(nvObj_t *nv) { return (set_integer(nv, ((uint8_t &)(cm->homing_state)), false, true)); } -stat_t cm_get_hom(nvObj_t *nv) { return (get_integer(nv, cm->homed[_axis(nv)])); } +stat_t cm_get_hom(nvObj_t *nv) { return (get_integer(nv, cm->homed[_axis(nv)])); } -stat_t cm_get_prob(nvObj_t *nv) { return(_get_msg_helper(nv, msg_probe, cm_get_probe_state())); } -stat_t cm_get_prb(nvObj_t *nv) { return (get_float(nv, cm->probe_results[0][_axis(nv)])); } +stat_t cm_get_prob(nvObj_t *nv) { return (_get_msg_helper(nv, msg_probe, cm_get_probe_state())); } +stat_t cm_get_prb(nvObj_t *nv) { return (get_float(nv, cm->probe_results[0][_axis(nv)])); } stat_t cm_get_probe_input(nvObj_t *nv) { return (get_integer(nv, cm->probe_input)); } stat_t cm_set_probe_input(nvObj_t *nv) { return (set_integer(nv, cm->probe_input, 0, D_IN_CHANNELS)); } stat_t cm_get_coord(nvObj_t *nv) { return (get_float(nv, cm->coord_offset[_coord(nv)][_axis(nv)])); } stat_t cm_set_coord(nvObj_t *nv) { return (set_float(nv, cm->coord_offset[_coord(nv)][_axis(nv)])); } -stat_t cm_get_g92e(nvObj_t *nv) { return (get_integer(nv, cm->gmx.g92_offset_enable)); } -stat_t cm_get_g92(nvObj_t *nv) { return (get_float(nv, cm->gmx.g92_offset[_axis(nv)])); } -stat_t cm_get_g28(nvObj_t *nv) { return (get_float(nv, cm->gmx.g28_position[_axis(nv)])); } -stat_t cm_get_g30(nvObj_t *nv) { return (get_float(nv, cm->gmx.g30_position[_axis(nv)])); } +stat_t cm_get_g92e(nvObj_t *nv) { return (get_integer(nv, cm->gmx.g92_offset_enable)); } +stat_t cm_get_g92(nvObj_t *nv) { return (get_float(nv, cm->gmx.g92_offset[_axis(nv)])); } +stat_t cm_get_g28(nvObj_t *nv) { return (get_float(nv, cm->gmx.g28_position[_axis(nv)])); } +stat_t cm_get_g30(nvObj_t *nv) { return (get_float(nv, cm->gmx.g30_position[_axis(nv)])); } /***************************************************** **** TOOL TABLE AND OFFSET GET AND SET FUNCTIONS **** *****************************************************/ -static uint8_t _tool(nvObj_t *nv) -{ +static uint8_t _tool(nvObj_t *nv) { if (nv->group[0] != 0) { - return (atoi(&nv->group[2])); // ttNN is the group, axis is in the token + return (atoi(&nv->group[2])); // ttNN is the group, axis is in the token } - return (atoi(&nv->token[2])); // ttNNx is all in the token + return (atoi(&nv->token[2])); // ttNNx is all in the token } stat_t cm_get_tof(nvObj_t *nv) { return (get_float(nv, cm->tool_offset[_axis(nv)])); } stat_t cm_set_tof(nvObj_t *nv) { return (set_float(nv, cm->tool_offset[_axis(nv)])); } -stat_t cm_get_tt(nvObj_t *nv) -{ +stat_t cm_get_tt(nvObj_t *nv) { uint8_t toolnum = _tool(nv); if (toolnum > TOOLS) { return (STAT_INPUT_EXCEEDS_MAX_VALUE); @@ -2187,13 +2105,12 @@ stat_t cm_get_tt(nvObj_t *nv) return (get_float(nv, tt.tt_offset[toolnum][_axis(nv)])); } -stat_t cm_set_tt(nvObj_t *nv) -{ +stat_t cm_set_tt(nvObj_t *nv) { uint8_t toolnum = _tool(nv); if (toolnum > TOOLS) { return (STAT_INPUT_EXCEEDS_MAX_VALUE); } - return(set_float(nv, tt.tt_offset[toolnum][_axis(nv)])); + return (set_float(nv, tt.tt_offset[toolnum][_axis(nv)])); } /************************************ @@ -2208,14 +2125,13 @@ stat_t cm_set_tt(nvObj_t *nv) * cm_set_tm() - set axis travel max */ -stat_t cm_get_am(nvObj_t *nv) -{ +stat_t cm_get_am(nvObj_t *nv) { int8_t axis = _axis(nv); nv->value_int = cm->a[axis].axis_mode; - return(_get_msg_helper(nv, msg_am, nv->value_int)); + return (_get_msg_helper(nv, msg_am, nv->value_int)); } -stat_t cm_set_am(nvObj_t *nv) // axis mode +stat_t cm_set_am(nvObj_t *nv) // axis mode { if (cm_get_axis_type(nv) == AXIS_TYPE_LINEAR) { if (nv->value_int > AXIS_MODE_LINEAR_MAX) { @@ -2230,7 +2146,7 @@ stat_t cm_set_am(nvObj_t *nv) // axis mode } nv->valuetype = TYPE_INTEGER; cm->a[_axis(nv)].axis_mode = (cmAxisMode)nv->value_int; - return(STAT_OK); + return (STAT_OK); } stat_t cm_get_tn(nvObj_t *nv) { return (get_float(nv, cm->a[_axis(nv)].travel_min)); } @@ -2248,27 +2164,25 @@ float cm_get_axis_jerk(const uint8_t axis) { return (cm->a[axis].jerk_max); } // Precompute sqrt(3)/10 for the max_junction_accel. // See plan_line.cpp -> _calculate_junction_vmax() notes for details. -static const float _junction_accel_multiplier = sqrt(3.0)/10.0; +static const float _junction_accel_multiplier = sqrt(3.0) / 10.0; // Important note: Actual jerk is stored jerk * JERK_MULTIPLIER, and // Time Quanta is junction_integration_time / 1000. void _cm_recalc_junction_accel(const uint8_t axis) { float T = cm->junction_integration_time / 1000.0; - float T2 = T*T; + float T2 = T * T; cm->a[axis].max_junction_accel = _junction_accel_multiplier * T2 * (cm->a[axis].jerk_max * JERK_MULTIPLIER); cm->a[axis].high_junction_accel = _junction_accel_multiplier * T2 * (cm->a[axis].jerk_high * JERK_MULTIPLIER); } -void cm_set_axis_max_jerk(const uint8_t axis, const float jerk) -{ +void cm_set_axis_max_jerk(const uint8_t axis, const float jerk) { cm->a[axis].jerk_max = jerk; - _cm_recalc_junction_accel(axis); // Must recalculate the max_junction_accel now that the jerk has changed. + _cm_recalc_junction_accel(axis); // Must recalculate the max_junction_accel now that the jerk has changed. } -void cm_set_axis_high_jerk(const uint8_t axis, const float jerk) -{ +void cm_set_axis_high_jerk(const uint8_t axis, const float jerk) { cm->a[axis].jerk_high = jerk; - _cm_recalc_junction_accel(axis); // Must recalculate the max_junction_accel now that the jerk has changed. + _cm_recalc_junction_accel(axis); // Must recalculate the max_junction_accel now that the jerk has changed. } /**** Axis Velocity and Jerk Settings @@ -2292,39 +2206,35 @@ void cm_set_axis_high_jerk(const uint8_t axis, const float jerk) */ stat_t cm_get_vm(nvObj_t *nv) { return (get_float(nv, cm->a[_axis(nv)].velocity_max)); } -stat_t cm_set_vm(nvObj_t *nv) -{ +stat_t cm_set_vm(nvObj_t *nv) { uint8_t axis = _axis(nv); ritorno(set_float_range(nv, cm->a[axis].velocity_max, 0, MAX_LONG)); - cm->a[axis].recip_velocity_max = 1/nv->value_flt; - return(STAT_OK); + cm->a[axis].recip_velocity_max = 1 / nv->value_flt; + return (STAT_OK); } stat_t cm_get_fr(nvObj_t *nv) { return (get_float(nv, cm->a[_axis(nv)].feedrate_max)); } -stat_t cm_set_fr(nvObj_t *nv) -{ +stat_t cm_set_fr(nvObj_t *nv) { uint8_t axis = _axis(nv); ritorno(set_float_range(nv, cm->a[axis].feedrate_max, 0, MAX_LONG)); - cm->a[axis].recip_feedrate_max = 1/nv->value_flt; - return(STAT_OK); + cm->a[axis].recip_feedrate_max = 1 / nv->value_flt; + return (STAT_OK); } stat_t cm_get_jm(nvObj_t *nv) { return (get_float(nv, cm->a[_axis(nv)].jerk_max)); } -stat_t cm_set_jm(nvObj_t *nv) -{ +stat_t cm_set_jm(nvObj_t *nv) { uint8_t axis = _axis(nv); ritorno(set_float_range(nv, cm->a[axis].jerk_max, JERK_INPUT_MIN, JERK_INPUT_MAX)); cm_set_axis_max_jerk(axis, nv->value_flt); - return(STAT_OK); + return (STAT_OK); } stat_t cm_get_jh(nvObj_t *nv) { return (get_float(nv, cm->a[_axis(nv)].jerk_high)); } -stat_t cm_set_jh(nvObj_t *nv) -{ +stat_t cm_set_jh(nvObj_t *nv) { uint8_t axis = _axis(nv); ritorno(set_float_range(nv, cm->a[axis].jerk_high, JERK_INPUT_MIN, JERK_INPUT_MAX)); cm_set_axis_high_jerk(axis, nv->value_flt); - return(STAT_OK); + return (STAT_OK); } /**** Axis Homing Settings @@ -2371,55 +2281,64 @@ stat_t cm_set_zb(nvObj_t *nv) { return (set_float(nv, cm->a[_axis(nv)].zero_back * cm_set_mto() - set manual traverse override factor */ -stat_t cm_get_jt(nvObj_t *nv) { return(get_float(nv, cm->junction_integration_time)); } -stat_t cm_set_jt(nvObj_t *nv) -{ +stat_t cm_get_jt(nvObj_t *nv) { return (get_float(nv, cm->junction_integration_time)); } +stat_t cm_set_jt(nvObj_t *nv) { ritorno(set_float_range(nv, cm->junction_integration_time, JUNCTION_INTEGRATION_MIN, JUNCTION_INTEGRATION_MAX)); - for (uint8_t axis=0; axischordal_tolerance)); } -stat_t cm_set_ct(nvObj_t *nv) { return(set_float_range(nv, cm->chordal_tolerance, CHORDAL_TOLERANCE_MIN, 10000000)); } +stat_t cm_get_ct(nvObj_t *nv) { return (get_float(nv, cm->chordal_tolerance)); } +stat_t cm_set_ct(nvObj_t *nv) { return (set_float_range(nv, cm->chordal_tolerance, CHORDAL_TOLERANCE_MIN, 10000000)); } -stat_t cm_get_zl(nvObj_t *nv) { return(get_float(nv, cm->feedhold_z_lift)); } -stat_t cm_set_zl(nvObj_t *nv) { return(set_float(nv, cm->feedhold_z_lift)); } +stat_t cm_get_zl(nvObj_t *nv) { return (get_float(nv, cm->feedhold_z_lift)); } +stat_t cm_set_zl(nvObj_t *nv) { return (set_float(nv, cm->feedhold_z_lift)); } -stat_t cm_get_sl(nvObj_t *nv) { return(get_integer(nv, cm->soft_limit_enable)); } -stat_t cm_set_sl(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->soft_limit_enable, 0, 1)); } +stat_t cm_get_sl(nvObj_t *nv) { return (get_integer(nv, cm->soft_limit_enable)); } +stat_t cm_set_sl(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->soft_limit_enable, 0, 1)); } -stat_t cm_get_lim(nvObj_t *nv) { return(get_integer(nv, cm->limit_enable)); } -stat_t cm_set_lim(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->limit_enable, 0, 1)); } +stat_t cm_get_lim(nvObj_t *nv) { return (get_integer(nv, cm->limit_enable)); } +stat_t cm_set_lim(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->limit_enable, 0, 1)); } -stat_t cm_get_m48(nvObj_t *nv) { return(get_integer(nv, cm->gmx.m48_enable)); } -stat_t cm_set_m48(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->gmx.m48_enable, 0, 1)); } +stat_t cm_get_m48(nvObj_t *nv) { return (get_integer(nv, cm->gmx.m48_enable)); } +stat_t cm_set_m48(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->gmx.m48_enable, 0, 1)); } -stat_t cm_get_froe(nvObj_t *nv) { return(get_integer(nv, cm->gmx.mfo_enable)); } -stat_t cm_set_froe(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->gmx.mfo_enable, 0, 1)); } -stat_t cm_get_fro(nvObj_t *nv) { return(get_float(nv, cm->gmx.mfo_factor)); } -stat_t cm_set_fro(nvObj_t *nv) { return(set_float_range(nv, cm->gmx.mfo_factor, FEED_OVERRIDE_MIN, FEED_OVERRIDE_MAX)); } +stat_t cm_get_froe(nvObj_t *nv) { return (get_integer(nv, cm->gmx.mfo_enable)); } +stat_t cm_set_froe(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->gmx.mfo_enable, 0, 1)); } +stat_t cm_get_fro(nvObj_t *nv) { return (get_float(nv, cm->gmx.mfo_factor)); } +stat_t cm_set_fro(nvObj_t *nv) { + return (set_float_range(nv, cm->gmx.mfo_factor, FEED_OVERRIDE_MIN, FEED_OVERRIDE_MAX)); +} -stat_t cm_get_troe(nvObj_t *nv) { return(get_integer(nv, cm->gmx.mto_enable)); } -stat_t cm_set_troe(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->gmx.mto_enable, 0, 1)); } -stat_t cm_get_tro(nvObj_t *nv) { return(get_float(nv, cm->gmx.mto_factor)); } -stat_t cm_set_tro(nvObj_t *nv) { return(set_float_range(nv, cm->gmx.mto_factor, TRAVERSE_OVERRIDE_MIN, TRAVERSE_OVERRIDE_MAX)); } +stat_t cm_get_troe(nvObj_t *nv) { return (get_integer(nv, cm->gmx.mto_enable)); } +stat_t cm_set_troe(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->gmx.mto_enable, 0, 1)); } +stat_t cm_get_tro(nvObj_t *nv) { return (get_float(nv, cm->gmx.mto_factor)); } +stat_t cm_set_tro(nvObj_t *nv) { + return (set_float_range(nv, cm->gmx.mto_factor, TRAVERSE_OVERRIDE_MIN, TRAVERSE_OVERRIDE_MAX)); +} -stat_t cm_get_gpl(nvObj_t *nv) { return(get_integer(nv, cm->default_select_plane)); } -stat_t cm_set_gpl(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->default_select_plane, CANON_PLANE_XY, CANON_PLANE_YZ)); } +stat_t cm_get_gpl(nvObj_t *nv) { return (get_integer(nv, cm->default_select_plane)); } +stat_t cm_set_gpl(nvObj_t *nv) { + return (set_integer(nv, (uint8_t &)cm->default_select_plane, CANON_PLANE_XY, CANON_PLANE_YZ)); +} -stat_t cm_get_gun(nvObj_t *nv) { return(get_integer(nv, cm->default_units_mode)); } -stat_t cm_set_gun(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->default_units_mode, INCHES, MILLIMETERS)); } +stat_t cm_get_gun(nvObj_t *nv) { return (get_integer(nv, cm->default_units_mode)); } +stat_t cm_set_gun(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->default_units_mode, INCHES, MILLIMETERS)); } -stat_t cm_get_gco(nvObj_t *nv) { return(get_integer(nv, cm->default_coord_system)); } -stat_t cm_set_gco(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->default_coord_system, G54, G59)); } +stat_t cm_get_gco(nvObj_t *nv) { return (get_integer(nv, cm->default_coord_system)); } +stat_t cm_set_gco(nvObj_t *nv) { return (set_integer(nv, (uint8_t &)cm->default_coord_system, G54, G59)); } -stat_t cm_get_gpa(nvObj_t *nv) { return(get_integer(nv, cm->default_path_control)); } -stat_t cm_set_gpa(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->default_path_control, PATH_EXACT_PATH, PATH_CONTINUOUS)); } +stat_t cm_get_gpa(nvObj_t *nv) { return (get_integer(nv, cm->default_path_control)); } +stat_t cm_set_gpa(nvObj_t *nv) { + return (set_integer(nv, (uint8_t &)cm->default_path_control, PATH_EXACT_PATH, PATH_CONTINUOUS)); +} -stat_t cm_get_gdi(nvObj_t *nv) { return(get_integer(nv, cm->default_distance_mode)); } -stat_t cm_set_gdi(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->default_distance_mode, ABSOLUTE_DISTANCE_MODE, INCREMENTAL_DISTANCE_MODE)); } +stat_t cm_get_gdi(nvObj_t *nv) { return (get_integer(nv, cm->default_distance_mode)); } +stat_t cm_set_gdi(nvObj_t *nv) { + return (set_integer(nv, (uint8_t &)cm->default_distance_mode, ABSOLUTE_DISTANCE_MODE, INCREMENTAL_DISTANCE_MODE)); +} /*** Canonical Machine Global Settings Table Additions ***/ /* @@ -2435,12 +2354,12 @@ stat_t cm_set_gdi(nvObj_t *nv) { return(set_integer(nv, (uint8_t &)cm->default_d */ struct grouplessCfgItem_t { - const char * token; // token - stripped of group prefix (w/NUL termination) - uint8_t flags; // operations flags - see defines below - int8_t precision; // decimal precision for display (JSON) - fptrPrint print; // print binding: aka void (*print)(nvObj_t *nv); - fptrCmd get; // GET binding aka uint8_t (*get)(nvObj_t *nv) - fptrCmd set; // SET binding aka uint8_t (*set)(nvObj_t *nv) + const char *token; // token - stripped of group prefix (w/NUL termination) + uint8_t flags; // operations flags - see defines below + int8_t precision; // decimal precision for display (JSON) + fptrPrint print; // print binding: aka void (*print)(nvObj_t *nv); + fptrCmd get; // GET binding aka uint8_t (*get)(nvObj_t *nv) + fptrCmd set; // SET binding aka uint8_t (*set)(nvObj_t *nv) }; // class cfgSubtableFromGrouplessStaticArray : public configSubtable { @@ -2482,41 +2401,43 @@ struct grouplessCfgItem_t { // // } // }; // char cfgSubtableFromGrouplessStaticArray::tmpToken[TOKEN_LEN + 1]; -// cfgItem_t cfgSubtableFromGrouplessStaticArray::cfgTmp = {"", &tmpToken[0], _i0, 0, nullptr, nullptr, nullptr, nullptr, 0}; +// cfgItem_t cfgSubtableFromGrouplessStaticArray::cfgTmp = {"", &tmpToken[0], _i0, 0, nullptr, nullptr, nullptr, +// nullptr, 0}; constexpr cfgItem_t cm_config_items_1[] = { // dynamic model attributes for reporting purposes (up front for speed) - {"", "stat", _i0, 0, cm_print_stat, cm_get_stat, set_ro, nullptr, 0}, // combined machine state - {"", "stat2", _i0, 0, cm_print_stat, cm_get_stat2, set_ro, nullptr, 0}, // combined machine state - {"", "n", _ii, 0, cm_print_line, cm_get_mline, set_noop, nullptr, 0}, // Model line number - {"", "line", _ii, 0, cm_print_line, cm_get_line, set_ro, nullptr, 0}, // Active line number - model or runtime line number - {"", "vel", _f0, 2, cm_print_vel, cm_get_vel, set_ro, nullptr, 0}, // current velocity - {"", "feed", _f0, 2, cm_print_feed, cm_get_feed, set_ro, nullptr, 0}, // feed rate - {"", "macs", _i0, 0, cm_print_macs, cm_get_macs, set_ro, nullptr, 0}, // raw machine state - {"", "cycs", _i0, 0, cm_print_cycs, cm_get_cycs, set_ro, nullptr, 0}, // cycle state - {"", "mots", _i0, 0, cm_print_mots, cm_get_mots, set_ro, nullptr, 0}, // motion state - {"", "hold", _i0, 0, cm_print_hold, cm_get_hold, set_ro, nullptr, 0}, // feedhold state - {"", "unit", _i0, 0, cm_print_unit, cm_get_unit, set_ro, nullptr, 0}, // units mode - {"", "coor", _i0, 0, cm_print_coor, cm_get_coor, set_ro, nullptr, 0}, // coordinate system - {"", "momo", _i0, 0, cm_print_momo, cm_get_momo, set_ro, nullptr, 0}, // motion mode - {"", "plan", _i0, 0, cm_print_plan, cm_get_plan, set_ro, nullptr, 0}, // plane select - {"", "path", _i0, 0, cm_print_path, cm_get_path, set_ro, nullptr, 0}, // path control mode - {"", "dist", _i0, 0, cm_print_dist, cm_get_dist, set_ro, nullptr, 0}, // distance mode - {"", "admo", _i0, 0, cm_print_admo, cm_get_admo, set_ro, nullptr, 0}, // arc distance mode - {"", "frmo", _i0, 0, cm_print_frmo, cm_get_frmo, set_ro, nullptr, 0}, // feed rate mode - {"", "tool", _i0, 0, cm_print_tool, cm_get_toolv, set_ro, nullptr, 0}, // active tool - {"", "g92e", _i0, 0, cm_print_g92e, cm_get_g92e, set_ro, nullptr, 0}, // G92 enable state + {"", "stat", _i0, 0, cm_print_stat, cm_get_stat, set_ro, nullptr, 0}, // combined machine state + {"", "stat2", _i0, 0, cm_print_stat, cm_get_stat2, set_ro, nullptr, 0}, // combined machine state + {"", "n", _ii, 0, cm_print_line, cm_get_mline, set_noop, nullptr, 0}, // Model line number + {"", "line", _ii, 0, cm_print_line, cm_get_line, set_ro, nullptr, + 0}, // Active line number - model or runtime line number + {"", "vel", _f0, 2, cm_print_vel, cm_get_vel, set_ro, nullptr, 0}, // current velocity + {"", "feed", _f0, 2, cm_print_feed, cm_get_feed, set_ro, nullptr, 0}, // feed rate + {"", "macs", _i0, 0, cm_print_macs, cm_get_macs, set_ro, nullptr, 0}, // raw machine state + {"", "cycs", _i0, 0, cm_print_cycs, cm_get_cycs, set_ro, nullptr, 0}, // cycle state + {"", "mots", _i0, 0, cm_print_mots, cm_get_mots, set_ro, nullptr, 0}, // motion state + {"", "hold", _i0, 0, cm_print_hold, cm_get_hold, set_ro, nullptr, 0}, // feedhold state + {"", "unit", _i0, 0, cm_print_unit, cm_get_unit, set_ro, nullptr, 0}, // units mode + {"", "coor", _i0, 0, cm_print_coor, cm_get_coor, set_ro, nullptr, 0}, // coordinate system + {"", "momo", _i0, 0, cm_print_momo, cm_get_momo, set_ro, nullptr, 0}, // motion mode + {"", "plan", _i0, 0, cm_print_plan, cm_get_plan, set_ro, nullptr, 0}, // plane select + {"", "path", _i0, 0, cm_print_path, cm_get_path, set_ro, nullptr, 0}, // path control mode + {"", "dist", _i0, 0, cm_print_dist, cm_get_dist, set_ro, nullptr, 0}, // distance mode + {"", "admo", _i0, 0, cm_print_admo, cm_get_admo, set_ro, nullptr, 0}, // arc distance mode + {"", "frmo", _i0, 0, cm_print_frmo, cm_get_frmo, set_ro, nullptr, 0}, // feed rate mode + {"", "tool", _i0, 0, cm_print_tool, cm_get_toolv, set_ro, nullptr, 0}, // active tool + {"", "g92e", _i0, 0, cm_print_g92e, cm_get_g92e, set_ro, nullptr, 0}, // G92 enable state #ifdef TEMPORARY_HAS_LEDS - {"", "_leds", _i0, 0, tx_print_nul, _get_leds,_set_leds, nullptr, 0}, // TEMPORARY - change LEDs + {"", "_leds", _i0, 0, tx_print_nul, _get_leds, _set_leds, nullptr, 0}, // TEMPORARY - change LEDs #endif }; -const cfgSubtableFromStaticArray cm_config_1 {cm_config_items_1}; -const configSubtable * const getCmConfig_1() { return &cm_config_1; } +const cfgSubtableFromStaticArray cm_config_1{cm_config_items_1}; +const configSubtable *const getCmConfig_1() { return &cm_config_1; } class cfgSubtableFromTokenList : public configSubtable { const char *group_name; const size_t group_name_length; - const char * const * subkeys; // read it backward: "pointer to const pointers to const chars" + const char *const *subkeys; // read it backward: "pointer to const pointers to const chars" // const size_t subkeys_length; // hold on to a reloadable full cfgItem_t to setup and return @@ -2533,10 +2454,10 @@ class cfgSubtableFromTokenList : public configSubtable { group_name_length{group_length - 1}, // string lengths include the null subkeys{i}, // subkeys_length{subkey_count}, - cfgTmp{&new_group_name[0], tmpToken, new_flags, new_precision, new_print, new_get_fn, new_set_fn, nullptr, 0} - {}; + cfgTmp{&new_group_name[0], tmpToken, new_flags, new_precision, new_print, new_get_fn, + new_set_fn, nullptr, 0} {}; - const cfgItem_t * const get(std::size_t idx) const override { + const cfgItem_t *const get(std::size_t idx) const override { char *dst = tmpToken; // strcpy(dst, group_name); // strcpy(dst+group_name_length, subkeys[idx]); @@ -2547,13 +2468,13 @@ class cfgSubtableFromTokenList : public configSubtable { index_t find(const char *token) const override { std::size_t idx = 0; - if (*(token+group_name_length) == 0 || strncmp(token, group_name, group_name_length) != 0) { + if (*(token + group_name_length) == 0 || strncmp(token, group_name, group_name_length) != 0) { // wrong group or looking for just the group return NO_MATCH; } while (idx < length) { // groupname is incorporated into tokens - if (strcmp(subkeys[idx]+group_name_length, token+group_name_length) == 0) { + if (strcmp(subkeys[idx] + group_name_length, token + group_name_length) == 0) { return idx; } idx++; @@ -2565,11 +2486,12 @@ char cfgSubtableFromTokenList::tmpToken[TOKEN_LEN + 1]; // cfgItem_t cfgSubtableFromTokenList::cfgTmp = {nullptr, &tmpToken[0], _i0, 0, nullptr, nullptr, nullptr, nullptr, 0}; #if (AXES == 9) -const char * const mpo_axis_keys[] = {"mpox", "mpoy", "mpoz", "mpou", "mpov", "mpow", "mpoa", "mpob", "mpoc"}; +const char *const mpo_axis_keys[] = {"mpox", "mpoy", "mpoz", "mpou", "mpov", "mpow", "mpoa", "mpob", "mpoc"}; #else -const char * const mpo_axis_keys[] = {"mpox", "mpoy", "mpoz", "mpoa", "mpob", "mpoc"}; +const char *const mpo_axis_keys[] = {"mpox", "mpoy", "mpoz", "mpoa", "mpob", "mpoc"}; #endif -cfgSubtableFromTokenList mpo_config{"mpo", mpo_axis_keys, _f0, 5, cm_print_mpo, cm_get_mpo, set_ro}; // machine position +cfgSubtableFromTokenList mpo_config{"mpo", mpo_axis_keys, _f0, 5, + cm_print_mpo, cm_get_mpo, set_ro}; // machine position const configSubtable *const getMpoConfig_1() { return &mpo_config; } // constexpr cfgItem_t pos_config_items_1[] = { @@ -2585,9 +2507,9 @@ const configSubtable *const getMpoConfig_1() { return &mpo_config; } // }; // constexpr cfgSubtableFromStaticArray pos_config_1{pos_config_items_1}; #if (AXES == 9) -const char * const pos_axis_keys[] = {"posx", "posy", "posz", "posu", "posv", "posw", "posa", "posb", "posc"}; +const char *const pos_axis_keys[] = {"posx", "posy", "posz", "posu", "posv", "posw", "posa", "posb", "posc"}; #else -const char * const pos_axis_keys[] = {"posx", "posy", "posz", "posa", "posb", "posc"}; +const char *const pos_axis_keys[] = {"posx", "posy", "posz", "posa", "posb", "posc"}; #endif cfgSubtableFromTokenList pos_config_1{"pos", pos_axis_keys, _f0, 5, cm_print_pos, cm_get_pos, set_ro}; // work position const configSubtable *const getPosConfig_1() { return &pos_config_1; } @@ -2605,9 +2527,9 @@ const configSubtable *const getPosConfig_1() { return &pos_config_1; } // }; // constexpr cfgSubtableFromStaticArray ofs_config_1{ofs_config_items_1}; #if (AXES == 9) -const char * const ofs_axis_keys[] = {"ofsx", "ofsy", "ofsz", "ofsu", "ofsv", "ofsw", "ofsa", "ofsb", "ofsc"}; +const char *const ofs_axis_keys[] = {"ofsx", "ofsy", "ofsz", "ofsu", "ofsv", "ofsw", "ofsa", "ofsb", "ofsc"}; #else -const char * const ofs_axis_keys[] = {"ofsx", "ofsy", "ofsz", "ofsa", "ofsb", "ofsc"}; +const char *const ofs_axis_keys[] = {"ofsx", "ofsy", "ofsz", "ofsa", "ofsb", "ofsc"}; #endif cfgSubtableFromTokenList ofs_config_1{"ofs", ofs_axis_keys, _f0, 5, cm_print_ofs, cm_get_ofs, set_ro}; // work offsets const configSubtable *const getOfsConfig_1() { return &ofs_config_1; } @@ -2660,9 +2582,9 @@ const configSubtable *const getPrbConfig_1() { return &prb_config_1; } // }; // constexpr cfgSubtableFromStaticArray jog_config_1{jog_config_items_1}; #if (AXES == 9) -const char * const jog_axis_keys[] = {"jogx", "jogy", "jogz", "jogu", "jogv", "jogw", "joga", "jogb", "jogc"}; +const char *const jog_axis_keys[] = {"jogx", "jogy", "jogz", "jogu", "jogv", "jogw", "joga", "jogb", "jogc"}; #else -const char * const jog_axis_keys[] = {"jogx", "jogy", "jogz", "joga", "jogb", "jogc"}; +const char *const jog_axis_keys[] = {"jogx", "jogy", "jogz", "joga", "jogb", "jogc"}; #endif cfgSubtableFromTokenList jog_config_1{"jog", jog_axis_keys, _f0, 0, tx_print_nul, get_nul, cm_run_jog}; // job const configSubtable *const getJogConfig_1() { return &jog_config_1; } @@ -2800,8 +2722,8 @@ constexpr cfgItem_t axis_config_items_1[] = { {"c", "clb", _fipc, 5, cm_print_lb, cm_get_lb, cm_set_lb, nullptr, C_LATCH_BACKOFF}, {"c", "czb", _fipc, 5, cm_print_zb, cm_get_zb, cm_set_zb, nullptr, C_ZERO_BACKOFF}, }; -constexpr cfgSubtableFromStaticArray axis_config_1 {axis_config_items_1}; -const configSubtable * const getAxisConfig_1() { return &axis_config_1; } +constexpr cfgSubtableFromStaticArray axis_config_1{axis_config_items_1}; +const configSubtable *const getAxisConfig_1() { return &axis_config_1; } /*********************************************************************************** * Debugging Commands @@ -2810,8 +2732,7 @@ const configSubtable * const getAxisConfig_1() { return &axis_config_1; } * cm_dam() - dump active model */ -stat_t cm_dam(nvObj_t *nv) -{ +stat_t cm_dam(nvObj_t *nv) { xio_writeline("Active model:\n"); cm_print_vel(nv); cm_print_feed(nv); @@ -2843,16 +2764,16 @@ stat_t cm_dam(nvObj_t *nv) /* model state print functions */ -static const char fmt_vel[] = "Velocity:%17.3f%s/min\n"; +static const char fmt_vel[] = "Velocity:%17.3f%s/min\n"; static const char fmt_feed[] = "Feed rate:%16.3f%s/min\n"; static const char fmt_line[] = "Line number:%10lu\n"; -static const char fmt_stat[] = "Machine state: %s\n"; // combined machine state -static const char fmt_macs[] = "Raw machine state: %s\n"; // raw machine state +static const char fmt_stat[] = "Machine state: %s\n"; // combined machine state +static const char fmt_macs[] = "Raw machine state: %s\n"; // raw machine state static const char fmt_cycs[] = "Cycle state: %s\n"; static const char fmt_mots[] = "Motion state: %s\n"; static const char fmt_hold[] = "Feedhold state: %s\n"; static const char fmt_home[] = "Homing state: %s\n"; -static const char fmt_unit[] = "Units: %s\n"; // units mode as ASCII string +static const char fmt_unit[] = "Units: %s\n"; // units mode as ASCII string static const char fmt_coor[] = "Coordinate system: %s\n"; static const char fmt_momo[] = "Motion mode: %s\n"; static const char fmt_plan[] = "Plane: %s\n"; @@ -2863,25 +2784,25 @@ static const char fmt_frmo[] = "Feed rate mode: %s\n"; static const char fmt_tool[] = "Tool number %d\n"; static const char fmt_g92e[] = "G92 enabled %d\n"; -void cm_print_vel(nvObj_t *nv) { text_print_flt_units(nv, fmt_vel, GET_UNITS(ACTIVE_MODEL));} -void cm_print_feed(nvObj_t *nv) { text_print_flt_units(nv, fmt_feed, GET_UNITS(ACTIVE_MODEL));} -void cm_print_line(nvObj_t *nv) { text_print(nv, fmt_line);} // TYPE_INT -void cm_print_tool(nvObj_t *nv) { text_print(nv, fmt_tool);} // TYPE_INT -void cm_print_g92e(nvObj_t *nv) { text_print(nv, fmt_g92e);} // TYPE_INT -void cm_print_stat(nvObj_t *nv) { text_print_str(nv, fmt_stat);} // print all these as TYPE_STRING -void cm_print_macs(nvObj_t *nv) { text_print_str(nv, fmt_macs);} // See _get_msg_helper() for details -void cm_print_cycs(nvObj_t *nv) { text_print_str(nv, fmt_cycs);} -void cm_print_mots(nvObj_t *nv) { text_print_str(nv, fmt_mots);} -void cm_print_hold(nvObj_t *nv) { text_print_str(nv, fmt_hold);} -void cm_print_home(nvObj_t *nv) { text_print_str(nv, fmt_home);} -void cm_print_unit(nvObj_t *nv) { text_print_str(nv, fmt_unit);} -void cm_print_coor(nvObj_t *nv) { text_print_str(nv, fmt_coor);} -void cm_print_momo(nvObj_t *nv) { text_print_str(nv, fmt_momo);} -void cm_print_plan(nvObj_t *nv) { text_print_str(nv, fmt_plan);} -void cm_print_path(nvObj_t *nv) { text_print_str(nv, fmt_path);} -void cm_print_dist(nvObj_t *nv) { text_print_str(nv, fmt_dist);} -void cm_print_admo(nvObj_t *nv) { text_print_str(nv, fmt_admo);} -void cm_print_frmo(nvObj_t *nv) { text_print_str(nv, fmt_frmo);} +void cm_print_vel(nvObj_t *nv) { text_print_flt_units(nv, fmt_vel, GET_UNITS(ACTIVE_MODEL)); } +void cm_print_feed(nvObj_t *nv) { text_print_flt_units(nv, fmt_feed, GET_UNITS(ACTIVE_MODEL)); } +void cm_print_line(nvObj_t *nv) { text_print(nv, fmt_line); } // TYPE_INT +void cm_print_tool(nvObj_t *nv) { text_print(nv, fmt_tool); } // TYPE_INT +void cm_print_g92e(nvObj_t *nv) { text_print(nv, fmt_g92e); } // TYPE_INT +void cm_print_stat(nvObj_t *nv) { text_print_str(nv, fmt_stat); } // print all these as TYPE_STRING +void cm_print_macs(nvObj_t *nv) { text_print_str(nv, fmt_macs); } // See _get_msg_helper() for details +void cm_print_cycs(nvObj_t *nv) { text_print_str(nv, fmt_cycs); } +void cm_print_mots(nvObj_t *nv) { text_print_str(nv, fmt_mots); } +void cm_print_hold(nvObj_t *nv) { text_print_str(nv, fmt_hold); } +void cm_print_home(nvObj_t *nv) { text_print_str(nv, fmt_home); } +void cm_print_unit(nvObj_t *nv) { text_print_str(nv, fmt_unit); } +void cm_print_coor(nvObj_t *nv) { text_print_str(nv, fmt_coor); } +void cm_print_momo(nvObj_t *nv) { text_print_str(nv, fmt_momo); } +void cm_print_plan(nvObj_t *nv) { text_print_str(nv, fmt_plan); } +void cm_print_path(nvObj_t *nv) { text_print_str(nv, fmt_path); } +void cm_print_dist(nvObj_t *nv) { text_print_str(nv, fmt_dist); } +void cm_print_admo(nvObj_t *nv) { text_print_str(nv, fmt_admo); } +void cm_print_frmo(nvObj_t *nv) { text_print_str(nv, fmt_frmo); } static const char fmt_gpl[] = "[gpl] default gcode plane%10d [0=G17,1=G18,2=G19]\n"; static const char fmt_gun[] = "[gun] default gcode units mode%5d [0=G20,1=G21]\n"; @@ -2889,11 +2810,11 @@ static const char fmt_gco[] = "[gco] default gcode coord system%3d [1-6 (G54-G59 static const char fmt_gpa[] = "[gpa] default gcode path control%3d [0=G61,1=G61.1,2=G64]\n"; static const char fmt_gdi[] = "[gdi] default gcode distance mode%2d [0=G90,1=G91]\n"; -void cm_print_gpl(nvObj_t *nv) { text_print(nv, fmt_gpl);} // TYPE_INT -void cm_print_gun(nvObj_t *nv) { text_print(nv, fmt_gun);} // TYPE_INT -void cm_print_gco(nvObj_t *nv) { text_print(nv, fmt_gco);} // TYPE_INT -void cm_print_gpa(nvObj_t *nv) { text_print(nv, fmt_gpa);} // TYPE_INT -void cm_print_gdi(nvObj_t *nv) { text_print(nv, fmt_gdi);} // TYPE_INT +void cm_print_gpl(nvObj_t *nv) { text_print(nv, fmt_gpl); } // TYPE_INT +void cm_print_gun(nvObj_t *nv) { text_print(nv, fmt_gun); } // TYPE_INT +void cm_print_gco(nvObj_t *nv) { text_print(nv, fmt_gco); } // TYPE_INT +void cm_print_gpa(nvObj_t *nv) { text_print(nv, fmt_gpa); } // TYPE_INT +void cm_print_gdi(nvObj_t *nv) { text_print(nv, fmt_gdi); } // TYPE_INT /* system parameter print functions */ @@ -2901,31 +2822,31 @@ static const char fmt_jt[] = "[jt] junction integration time%7.2f\n"; static const char fmt_ct[] = "[ct] chordal tolerance%17.4f%s\n"; static const char fmt_zl[] = "[zl] Z lift on feedhold%16.3f%s\n"; static const char fmt_sl[] = "[sl] soft limit enable%12d [0=disable,1=enable]\n"; -static const char fmt_lim[] ="[lim] limit switch enable%10d [0=disable,1=enable]\n"; -static const char fmt_saf[] ="[saf] safety interlock enable%6d [0=disable,1=enable]\n"; +static const char fmt_lim[] = "[lim] limit switch enable%10d [0=disable,1=enable]\n"; +static const char fmt_saf[] = "[saf] safety interlock enable%6d [0=disable,1=enable]\n"; -void cm_print_jt(nvObj_t *nv) { text_print(nv, fmt_jt);} // TYPE FLOAT -void cm_print_ct(nvObj_t *nv) { text_print_flt_units(nv, fmt_ct, GET_UNITS(ACTIVE_MODEL));} -void cm_print_zl(nvObj_t *nv) { text_print_flt_units(nv, fmt_zl, GET_UNITS(ACTIVE_MODEL));} -void cm_print_sl(nvObj_t *nv) { text_print(nv, fmt_sl);} // TYPE_INT -void cm_print_lim(nvObj_t *nv){ text_print(nv, fmt_lim);} // TYPE_INT -void cm_print_saf(nvObj_t *nv){ text_print(nv, fmt_saf);} // TYPE_INT +void cm_print_jt(nvObj_t *nv) { text_print(nv, fmt_jt); } // TYPE FLOAT +void cm_print_ct(nvObj_t *nv) { text_print_flt_units(nv, fmt_ct, GET_UNITS(ACTIVE_MODEL)); } +void cm_print_zl(nvObj_t *nv) { text_print_flt_units(nv, fmt_zl, GET_UNITS(ACTIVE_MODEL)); } +void cm_print_sl(nvObj_t *nv) { text_print(nv, fmt_sl); } // TYPE_INT +void cm_print_lim(nvObj_t *nv) { text_print(nv, fmt_lim); } // TYPE_INT +void cm_print_saf(nvObj_t *nv) { text_print(nv, fmt_saf); } // TYPE_INT -static const char fmt_m48[] = "[m48] overrides enabled%12d [0=disable,1=enable]\n"; +static const char fmt_m48[] = "[m48] overrides enabled%12d [0=disable,1=enable]\n"; static const char fmt_froe[] = "[froe] feed override enable%8d [0=disable,1=enable]\n"; -static const char fmt_fro[] = "[fro] feedrate override%15.3f [0.05 < mfo < 2.00]\n"; +static const char fmt_fro[] = "[fro] feedrate override%15.3f [0.05 < mfo < 2.00]\n"; static const char fmt_troe[] = "[troe] traverse over enable%8d [0=disable,1=enable]\n"; -static const char fmt_tro[] = "[tro] traverse override%15.3f [0.05 < mto < 1.00]\n"; +static const char fmt_tro[] = "[tro] traverse override%15.3f [0.05 < mto < 1.00]\n"; static const char fmt_tram[] = "[tram] is coordinate space rotated to be tram %s\n"; static const char fmt_nxln[] = "[nxln] next line number %lu\n"; -void cm_print_m48(nvObj_t *nv) { text_print(nv, fmt_m48);} // TYPE_INT -void cm_print_froe(nvObj_t *nv) { text_print(nv, fmt_froe);} // TYPE INT -void cm_print_fro(nvObj_t *nv) { text_print(nv, fmt_fro);} // TYPE FLOAT -void cm_print_troe(nvObj_t *nv) { text_print(nv, fmt_troe);} // TYPE INT -void cm_print_tro(nvObj_t *nv) { text_print(nv, fmt_tro);} // TYPE FLOAT -void cm_print_tram(nvObj_t *nv) { text_print(nv, fmt_tram);}; // TYPE BOOL -void cm_print_nxln(nvObj_t *nv) { text_print(nv, fmt_nxln);}; // TYPE INT +void cm_print_m48(nvObj_t *nv) { text_print(nv, fmt_m48); } // TYPE_INT +void cm_print_froe(nvObj_t *nv) { text_print(nv, fmt_froe); } // TYPE INT +void cm_print_fro(nvObj_t *nv) { text_print(nv, fmt_fro); } // TYPE FLOAT +void cm_print_troe(nvObj_t *nv) { text_print(nv, fmt_troe); } // TYPE INT +void cm_print_tro(nvObj_t *nv) { text_print(nv, fmt_tro); } // TYPE FLOAT +void cm_print_tram(nvObj_t *nv) { text_print(nv, fmt_tram); }; // TYPE BOOL +void cm_print_nxln(nvObj_t *nv) { text_print(nv, fmt_nxln); }; // TYPE INT /* * axis print functions @@ -2976,14 +2897,12 @@ static const char fmt_ofs[] = "%c work offset:%12.3f%s\n"; static const char fmt_tof[] = "%c tool length offset:%12.3f%s\n"; static const char fmt_hom[] = "%c axis homing state:%2.0f\n"; -static void _print_axis_ui8(nvObj_t *nv, const char *format) -{ +static void _print_axis_ui8(nvObj_t *nv, const char *format) { sprintf(cs.out_buf, format, nv->group, nv->token, nv->group, nv->value_int); xio_writeline(cs.out_buf); } -static void _print_axis_flt(nvObj_t *nv, const char *format) -{ +static void _print_axis_flt(nvObj_t *nv, const char *format) { char *units; if (cm_get_axis_type(nv) == AXIS_TYPE_LINEAR) { units = (char *)GET_UNITS(MODEL); @@ -2994,8 +2913,7 @@ static void _print_axis_flt(nvObj_t *nv, const char *format) xio_writeline(cs.out_buf); } -static void _print_axis_coord_flt(nvObj_t *nv, const char *format) -{ +static void _print_axis_coord_flt(nvObj_t *nv, const char *format) { char *units; if (cm_get_axis_type(nv) == AXIS_TYPE_LINEAR) { units = (char *)GET_UNITS(MODEL); @@ -3006,52 +2924,52 @@ static void _print_axis_coord_flt(nvObj_t *nv, const char *format) xio_writeline(cs.out_buf); } -static void _print_pos(nvObj_t *nv, const char *format, uint8_t units) -{ +static void _print_pos(nvObj_t *nv, const char *format, uint8_t units) { char axes[] = {"XYZABC"}; uint8_t axis = _axis(nv); - if (axis >= AXIS_A) { units = DEGREES;} + if (axis >= AXIS_A) { + units = DEGREES; + } sprintf(cs.out_buf, format, axes[axis], nv->value_flt, GET_TEXT_ITEM(msg_units, units)); xio_writeline(cs.out_buf); } -static void _print_hom(nvObj_t *nv, const char *format) -{ +static void _print_hom(nvObj_t *nv, const char *format) { char axes[] = {"XYZABC"}; uint8_t axis = _axis(nv); sprintf(cs.out_buf, format, axes[axis], nv->value_int); xio_writeline(cs.out_buf); } -void cm_print_am(nvObj_t *nv) // print axis mode with enumeration string +void cm_print_am(nvObj_t *nv) // print axis mode with enumeration string { sprintf(cs.out_buf, fmt_Xam, nv->group, nv->token, nv->group, (int)nv->value_int, - GET_TEXT_ITEM(msg_am, nv->value_int)); + GET_TEXT_ITEM(msg_am, nv->value_int)); xio_writeline(cs.out_buf); } -void cm_print_fr(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xfr);} -void cm_print_vm(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xvm);} -void cm_print_tm(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xtm);} -void cm_print_tn(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xtn);} -void cm_print_jm(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xjm);} -void cm_print_jh(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xjh);} -void cm_print_ra(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xra);} +void cm_print_fr(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xfr); } +void cm_print_vm(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xvm); } +void cm_print_tm(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xtm); } +void cm_print_tn(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xtn); } +void cm_print_jm(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xjm); } +void cm_print_jh(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xjh); } +void cm_print_ra(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xra); } -void cm_print_hi(nvObj_t *nv) { _print_axis_ui8(nv, fmt_Xhi);} -void cm_print_hd(nvObj_t *nv) { _print_axis_ui8(nv, fmt_Xhd);} -void cm_print_sv(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xsv);} -void cm_print_lv(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xlv);} -void cm_print_lb(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xlb);} -void cm_print_zb(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xzb);} +void cm_print_hi(nvObj_t *nv) { _print_axis_ui8(nv, fmt_Xhi); } +void cm_print_hd(nvObj_t *nv) { _print_axis_ui8(nv, fmt_Xhd); } +void cm_print_sv(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xsv); } +void cm_print_lv(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xlv); } +void cm_print_lb(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xlb); } +void cm_print_zb(nvObj_t *nv) { _print_axis_flt(nv, fmt_Xzb); } -void cm_print_cofs(nvObj_t *nv) { _print_axis_coord_flt(nv, fmt_cofs);} -void cm_print_cpos(nvObj_t *nv) { _print_axis_coord_flt(nv, fmt_cpos);} +void cm_print_cofs(nvObj_t *nv) { _print_axis_coord_flt(nv, fmt_cofs); } +void cm_print_cpos(nvObj_t *nv) { _print_axis_coord_flt(nv, fmt_cpos); } -void cm_print_pos(nvObj_t *nv) { _print_pos(nv, fmt_pos, cm_get_units_mode(MODEL));} -void cm_print_mpo(nvObj_t *nv) { _print_pos(nv, fmt_mpo, MILLIMETERS);} -void cm_print_ofs(nvObj_t *nv) { _print_pos(nv, fmt_ofs, MILLIMETERS);} -void cm_print_tof(nvObj_t *nv) { _print_pos(nv, fmt_tof, MILLIMETERS);} -void cm_print_hom(nvObj_t *nv) { _print_hom(nv, fmt_hom);} +void cm_print_pos(nvObj_t *nv) { _print_pos(nv, fmt_pos, cm_get_units_mode(MODEL)); } +void cm_print_mpo(nvObj_t *nv) { _print_pos(nv, fmt_mpo, MILLIMETERS); } +void cm_print_ofs(nvObj_t *nv) { _print_pos(nv, fmt_ofs, MILLIMETERS); } +void cm_print_tof(nvObj_t *nv) { _print_pos(nv, fmt_tof, MILLIMETERS); } +void cm_print_hom(nvObj_t *nv) { _print_hom(nv, fmt_hom); } -#endif // __TEXT_MODE +#endif // __TEXT_MODE diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index 2efe9c8a..48883929 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -33,28 +33,28 @@ #define CANONICAL_MACHINE_H_ONCE #include "config.h" -#include "hardware.h" // Note: hardware.h is specific to the hardware target selected -#include "settings.h" #include "gcode.h" +#include "hardware.h" // Note: hardware.h is specific to the hardware target selected +#include "settings.h" #if MARLIN_COMPAT_ENABLED == true -#include "marlin_compatibility.h" // import Marlin definitions and enums +#include "marlin_compatibility.h" // import Marlin definitions and enums #endif /* Defines, Macros, and Assorted Parameters */ -#define MODEL (GCodeState_t *)&cm->gm // absolute pointer from canonical machine gm model -#define RUNTIME (GCodeState_t *)&mr->gm // absolute pointer from runtime mm struct -#define ACTIVE_MODEL cm->am // active model pointer is maintained by cm_set_motion_state() +#define MODEL (GCodeState_t *)&cm->gm // absolute pointer from canonical machine gm model +#define RUNTIME (GCodeState_t *)&mr->gm // absolute pointer from runtime mm struct +#define ACTIVE_MODEL cm->am // active model pointer is maintained by cm_set_motion_state() -#define _to_millimeters(a) ((cm->gm.units_mode == INCHES) ? ((float)a * (float)MM_PER_INCH) : (float)a) -#define _to_inches(a) ((cm->gm.units_mode == INCHES) ? ((float)a * (float)(1/MM_PER_INCH)) : (float)a) +#define _to_millimeters(a) ((cm->gm.units_mode == INCHES) ? ((float)a * (float)MM_PER_INCH) : (float)a) +#define _to_inches(a) ((cm->gm.units_mode == INCHES) ? ((float)a * (float)(1 / MM_PER_INCH)) : (float)a) -#define DISABLE_SOFT_LIMIT (999999) -#define JERK_INPUT_MIN (0.01) // minimum allowable jerk setting in millions mm/min^3 -#define JERK_INPUT_MAX (1000000) // maximum allowable jerk setting in millions mm/min^3 -#define PROBES_STORED 3 // we store three probes for coordinate rotation computation -#define MAX_LINENUM 2000000000 // set 2 billion as max line number +#define DISABLE_SOFT_LIMIT (999999) +#define JERK_INPUT_MIN (0.01) // minimum allowable jerk setting in millions mm/min^3 +#define JERK_INPUT_MAX (1000000) // maximum allowable jerk setting in millions mm/min^3 +#define PROBES_STORED 3 // we store three probes for coordinate rotation computation +#define MAX_LINENUM 2000000000 // set 2 billion as max line number /***************************************************************************** * MACHINE STATE MODEL @@ -68,115 +68,115 @@ // ### LAYER 8 CRITICAL REGION ### // ### DO NOT CHANGE THESE ENUMERATIONS WITHOUT COMMUNITY INPUT ### -typedef enum { // check alignment with messages in config.c / msg_stat strings - COMBINED_INITIALIZING = 0, // [0] machine is initializing - COMBINED_READY, // [1] machine is ready for use - COMBINED_ALARM, // [2] machine in alarm state - COMBINED_PROGRAM_STOP, // [3] program stop/no more blocks - COMBINED_PROGRAM_END, // [4] program end - COMBINED_RUN, // [5] machine is running - COMBINED_HOLD, // [6] machine is holding - COMBINED_PROBE, // [7] probe cycle active - COMBINED_CYCLE, // [8] reserved for canned cycles - COMBINED_HOMING, // [9] homing cycle active - COMBINED_JOG, // [10] jogging cycle active - COMBINED_INTERLOCK, // [11] machine in safety interlock hold - COMBINED_SHUTDOWN, // [12] machine in shutdown state - COMBINED_PANIC // [13] machine in panic state +typedef enum { // check alignment with messages in config.c / msg_stat strings + COMBINED_INITIALIZING = 0, // [0] machine is initializing + COMBINED_READY, // [1] machine is ready for use + COMBINED_ALARM, // [2] machine in alarm state + COMBINED_PROGRAM_STOP, // [3] program stop/no more blocks + COMBINED_PROGRAM_END, // [4] program end + COMBINED_RUN, // [5] machine is running + COMBINED_HOLD, // [6] machine is holding + COMBINED_PROBE, // [7] probe cycle active + COMBINED_CYCLE, // [8] reserved for canned cycles + COMBINED_HOMING, // [9] homing cycle active + COMBINED_JOG, // [10] jogging cycle active + COMBINED_INTERLOCK, // [11] machine in safety interlock hold + COMBINED_SHUTDOWN, // [12] machine in shutdown state + COMBINED_PANIC // [13] machine in panic state } cmCombinedState; //### END CRITICAL REGION ### -typedef enum { // Note: MachineState signals if the machine is in cycle (5) or some other non-cycle state - MACHINE_INITIALIZING = 0, // machine is initializing - MACHINE_READY, // machine is ready for use but idle - MACHINE_ALARM, // machine is in alarm state - MACHINE_PROGRAM_STOP, // no blocks to run; like PROGRAM_END but without the M2 to reset gcode state - MACHINE_PROGRAM_END, // program end (same as MACHINE_READY, really...) - MACHINE_CYCLE, // machine is in cycle, running; blocks still to run, or steppers are busy - MACHINE_INTERLOCK, // machine is in interlock state - MACHINE_SHUTDOWN, // machine is in shutdown state - MACHINE_PANIC // machine is in panic state +typedef enum { // Note: MachineState signals if the machine is in cycle (5) or some other non-cycle state + MACHINE_INITIALIZING = 0, // machine is initializing + MACHINE_READY, // machine is ready for use but idle + MACHINE_ALARM, // machine is in alarm state + MACHINE_PROGRAM_STOP, // no blocks to run; like PROGRAM_END but without the M2 to reset gcode state + MACHINE_PROGRAM_END, // program end (same as MACHINE_READY, really...) + MACHINE_CYCLE, // machine is in cycle, running; blocks still to run, or steppers are busy + MACHINE_INTERLOCK, // machine is in interlock state + MACHINE_SHUTDOWN, // machine is in shutdown state + MACHINE_PANIC // machine is in panic state } cmMachineState; typedef enum { - MOTION_STOP = 0, // motion has stopped: set when the steppers reach the end of the planner queue - MOTION_RUN // machine is in motion: set when the steppers execute an ALINE segment + MOTION_STOP = 0, // motion has stopped: set when the steppers reach the end of the planner queue + MOTION_RUN // machine is in motion: set when the steppers execute an ALINE segment } cmMotionState; typedef enum { - CYCLE_NONE = 0, // not in a cycle - CYCLE_MACHINING, // in normal machining cycle - CYCLE_HOMING, // in homing cycle - CYCLE_PROBE, // in probe cycle - CYCLE_JOG // in jogging cycle -// CYCLE_G81 // illustration of canned cycles -// ... + CYCLE_NONE = 0, // not in a cycle + CYCLE_MACHINING, // in normal machining cycle + CYCLE_HOMING, // in homing cycle + CYCLE_PROBE, // in probe cycle + CYCLE_JOG // in jogging cycle + // CYCLE_G81 // illustration of canned cycles + // ... } cmCycleType; -typedef enum { // feedhold type parameter - FEEDHOLD_TYPE_HOLD, // simple feedhold at max jerk with no actions - FEEDHOLD_TYPE_ACTIONS, // feedhold at max jerk with hold entry actions - FEEDHOLD_TYPE_SKIP, // feedhold at max jerk with queue flush and sync command - FEEDHOLD_TYPE_SCRAM // feedhold at high jerk and stop all active devices +typedef enum { // feedhold type parameter + FEEDHOLD_TYPE_HOLD, // simple feedhold at max jerk with no actions + FEEDHOLD_TYPE_ACTIONS, // feedhold at max jerk with hold entry actions + FEEDHOLD_TYPE_SKIP, // feedhold at max jerk with queue flush and sync command + FEEDHOLD_TYPE_SCRAM // feedhold at high jerk and stop all active devices } cmFeedholdType; -typedef enum { // feedhold final operation - FEEDHOLD_EXIT_CYCLE = 0, // exit feedhold with cycle restart - FEEDHOLD_EXIT_FLUSH, // exit feedhold with flush - FEEDHOLD_EXIT_STOP, // perform program stop - FEEDHOLD_EXIT_END, // perform program end - FEEDHOLD_EXIT_ALARM, // perform alarm - FEEDHOLD_EXIT_SHUTDOWN, // perform shutdown - FEEDHOLD_EXIT_INTERLOCK, // report as interlock - FEEDHOLD_EXIT_RESET_POSITION // reset machine positions to hold point +typedef enum { // feedhold final operation + FEEDHOLD_EXIT_CYCLE = 0, // exit feedhold with cycle restart + FEEDHOLD_EXIT_FLUSH, // exit feedhold with flush + FEEDHOLD_EXIT_STOP, // perform program stop + FEEDHOLD_EXIT_END, // perform program end + FEEDHOLD_EXIT_ALARM, // perform alarm + FEEDHOLD_EXIT_SHUTDOWN, // perform shutdown + FEEDHOLD_EXIT_INTERLOCK, // report as interlock + FEEDHOLD_EXIT_RESET_POSITION // reset machine positions to hold point } cmFeedholdExit; -typedef enum { // feedhold state machine - FEEDHOLD_OFF = 0, // 0 - no feedhold in effect - FEEDHOLD_REQUESTED, // 1 - feedhold has been requested but not started yet (NOT USED) - FEEDHOLD_SYNC, // 2 - start hold - sync to latest aline segment - FEEDHOLD_DECEL_CONTINUE, // 3 - in deceleration that will not end at zero - FEEDHOLD_DECEL_TO_ZERO, // 4 - in deceleration that will go to zero - FEEDHOLD_DECEL_COMPLETE, // 5 - feedhold deceleration has completed, but motors may not have stopped yet - FEEDHOLD_MOTION_STOPPING, // 6 - waiting for motors to have stopped at hold point (motion stop) - FEEDHOLD_MOTION_STOPPED, // 7 - motion has stopped at hold point - FEEDHOLD_HOLD_ACTIONS_PENDING, // 8 - wait for feedhold actions to complete - FEEDHOLD_HOLD_ACTIONS_COMPLETE, // 9 - FEEDHOLD_HOLD, // 10 - HOLDING (steady state) - FEEDHOLD_EXIT_ACTIONS_PENDING, // performing exit actions - FEEDHOLD_EXIT_ACTIONS_COMPLETE // completed exit actions +typedef enum { // feedhold state machine + FEEDHOLD_OFF = 0, // 0 - no feedhold in effect + FEEDHOLD_REQUESTED, // 1 - feedhold has been requested but not started yet (NOT USED) + FEEDHOLD_SYNC, // 2 - start hold - sync to latest aline segment + FEEDHOLD_DECEL_CONTINUE, // 3 - in deceleration that will not end at zero + FEEDHOLD_DECEL_TO_ZERO, // 4 - in deceleration that will go to zero + FEEDHOLD_DECEL_COMPLETE, // 5 - feedhold deceleration has completed, but motors may not have stopped yet + FEEDHOLD_MOTION_STOPPING, // 6 - waiting for motors to have stopped at hold point (motion stop) + FEEDHOLD_MOTION_STOPPED, // 7 - motion has stopped at hold point + FEEDHOLD_HOLD_ACTIONS_PENDING, // 8 - wait for feedhold actions to complete + FEEDHOLD_HOLD_ACTIONS_COMPLETE, // 9 + FEEDHOLD_HOLD, // 10 - HOLDING (steady state) + FEEDHOLD_EXIT_ACTIONS_PENDING, // performing exit actions + FEEDHOLD_EXIT_ACTIONS_COMPLETE // completed exit actions } cmFeedholdState; -typedef enum { // state machine for cycle start - CYCLE_START_OFF = 0, // not requested +typedef enum { // state machine for cycle start + CYCLE_START_OFF = 0, // not requested CYCLE_START_REQUESTED, CYCLE_START_COMPLETE } cmCycleState; -typedef enum { // queue flush state machine - QUEUE_FLUSH_OFF = 0, // no queue flush in effect - QUEUE_FLUSH_REQUESTED // flush has been requested but not started yet +typedef enum { // queue flush state machine + QUEUE_FLUSH_OFF = 0, // no queue flush in effect + QUEUE_FLUSH_REQUESTED // flush has been requested but not started yet } cmFlushState; -typedef enum { // applies to cm->homing_state - HOMING_NOT_HOMED = 0, // machine is not homed (0=false) - HOMING_HOMED = 1, // machine is homed (1=true) - HOMING_WAITING // machine waiting to be homed +typedef enum { // applies to cm->homing_state + HOMING_NOT_HOMED = 0, // machine is not homed (0=false) + HOMING_HOMED = 1, // machine is homed (1=true) + HOMING_WAITING // machine waiting to be homed } cmHomingState; -typedef enum { // applies to cm->probe_state - PROBE_FAILED = 0, // probe reached endpoint without triggering - PROBE_SUCCEEDED = 1, // probe was triggered, cm->probe_results has position - PROBE_WAITING = 2 // probe is waiting to be started or is running +typedef enum { // applies to cm->probe_state + PROBE_FAILED = 0, // probe reached endpoint without triggering + PROBE_SUCCEEDED = 1, // probe was triggered, cm->probe_results has position + PROBE_WAITING = 2 // probe is waiting to be started or is running } cmProbeState; -typedef enum { // feed override state machine +typedef enum { // feed override state machine MFO_OFF = 0, MFO_REQUESTED, MFO_SYNC } cmOverrideState; -typedef enum { // job kill state machine +typedef enum { // job kill state machine JOB_KILL_OFF = 0, JOB_KILL_REQUESTED, JOB_KILL_RUNNING @@ -187,16 +187,15 @@ typedef enum { // job kill state machine */ typedef struct cmAxis { - // axis settings - cmAxisMode axis_mode; // see cmAxisMode above - float velocity_max; // max velocity in mm/min or deg/min - float feedrate_max; // max velocity in mm/min or deg/min - float jerk_max; // max jerk (Jm) in mm/min^3 divided by 1 million - float jerk_high; // high speed deceleration jerk (Jh) in mm/min^3 divided by 1 million - float travel_min; // min work envelope for soft limits - float travel_max; // max work envelope for soft limits - float radius; // radius in mm for rotary axis modes + cmAxisMode axis_mode; // see cmAxisMode above + float velocity_max; // max velocity in mm/min or deg/min + float feedrate_max; // max velocity in mm/min or deg/min + float jerk_max; // max jerk (Jm) in mm/min^3 divided by 1 million + float jerk_high; // high speed deceleration jerk (Jh) in mm/min^3 divided by 1 million + float travel_min; // min work envelope for soft limits + float travel_max; // max work envelope for soft limits + float radius; // radius in mm for rotary axis modes // internal derived variables - computed during data entry and cached for computational efficiency float recip_velocity_max; @@ -205,126 +204,126 @@ typedef struct cmAxis { float high_junction_accel; // homing settings - uint8_t homing_input; // set 1-N for homing input. 0 will disable homing - uint8_t homing_dir; // 0=search to negative, 1=search to positive - float search_velocity; // homing search velocity - float latch_velocity; // homing latch velocity - float latch_backoff; // backoff sufficient to clear a switch - float zero_backoff; // backoff from switches for machine zero + uint8_t homing_input; // set 1-N for homing input. 0 will disable homing + uint8_t homing_dir; // 0=search to negative, 1=search to positive + float search_velocity; // homing search velocity + float latch_velocity; // homing latch velocity + float latch_backoff; // backoff sufficient to clear a switch + float zero_backoff; // backoff from switches for machine zero } cfgAxis_t; -typedef struct cmArc { // planner and runtime variables for arc generation +typedef struct cmArc { // planner and runtime variables for arc generation magic_t magic_start; - uint8_t run_state; // runtime state machine sequence + uint8_t run_state; // runtime state machine sequence - float position[AXES]; // accumulating runtime position - float ijk_offset[3]; // arc IJK offsets + float position[AXES]; // accumulating runtime position + float ijk_offset[3]; // arc IJK offsets - float length; // length of line or helix in mm - float radius; // Raw R value, or computed via offsets - float theta; // starting angle of arc - float angular_travel; // travel along the arc in radians - float planar_travel; // travel in arc plane in mm - float linear_travel; // travel along linear axis of arc in mm - bool full_circle; // True if full circle arcs specified - float rotations; // number of full rotations to add (P value + sign) + float length; // length of line or helix in mm + float radius; // Raw R value, or computed via offsets + float theta; // starting angle of arc + float angular_travel; // travel along the arc in radians + float planar_travel; // travel in arc plane in mm + float linear_travel; // travel along linear axis of arc in mm + bool full_circle; // True if full circle arcs specified + float rotations; // number of full rotations to add (P value + sign) - cmAxes plane_axis_0; // arc plane axis 0 - e.g. X for G17 - cmAxes plane_axis_1; // arc plane axis 1 - e.g. Y for G17 - cmAxes linear_axis; // linear axis (normal to plane) + cmAxes plane_axis_0; // arc plane axis 0 - e.g. X for G17 + cmAxes plane_axis_1; // arc plane axis 1 - e.g. Y for G17 + cmAxes linear_axis; // linear axis (normal to plane) - float segments; // number of segments in arc or blend - int32_t segment_count; // count of running segments - float segment_theta; // angular motion per segment - float segment_linear_travel; // linear motion per segment - float center_0; // center of circle at plane axis 0 (e.g. X for G17) - float center_1; // center of circle at plane axis 1 (e.g. Y for G17) + float segments; // number of segments in arc or blend + int32_t segment_count; // count of running segments + float segment_theta; // angular motion per segment + float segment_linear_travel; // linear motion per segment + float center_0; // center of circle at plane axis 0 (e.g. X for G17) + float center_1; // center of circle at plane axis 1 (e.g. Y for G17) - GCodeState_t gm; // Gcode state struct is passed for each arc segment. + GCodeState_t gm; // Gcode state struct is passed for each arc segment. magic_t magic_end; } cmArc_t; -typedef struct cmMachine { // struct to manage canonical machine globals and state - magic_t magic_start; // magic number to test memory integrity +typedef struct cmMachine { // struct to manage canonical machine globals and state + magic_t magic_start; // magic number to test memory integrity /**** Config variables (PUBLIC) ****/ // System group settings - float junction_integration_time; // how aggressively will the machine corner? 1.6 or so is about the upper limit - float chordal_tolerance; // arc chordal accuracy setting in mm - float feedhold_z_lift; // mm to move Z axis on feedhold, or 0 to disable - bool soft_limit_enable; // true to enable soft limit testing on Gcode inputs - bool limit_enable; // true to enable limit switches (disabled is same as override) + float junction_integration_time; // how aggressively will the machine corner? 1.6 or so is about the upper limit + float chordal_tolerance; // arc chordal accuracy setting in mm + float feedhold_z_lift; // mm to move Z axis on feedhold, or 0 to disable + bool soft_limit_enable; // true to enable soft limit testing on Gcode inputs + bool limit_enable; // true to enable limit switches (disabled is same as override) // Coordinate systems and offsets - float coord_offset[COORDS+1][AXES]; // persistent coordinate offsets: absolute (G53) + G54,G55,G56,G57,G58,G59 - float tool_offset[AXES]; // current tool offset + float coord_offset[COORDS + 1][AXES]; // persistent coordinate offsets: absolute (G53) + G54,G55,G56,G57,G58,G59 + float tool_offset[AXES]; // current tool offset // Axis settings cfgAxis_t a[AXES]; // gcode power-on default settings - defaults are not the same as the gm state - cmCoordSystem default_coord_system; // G10 active coordinate system default + cmCoordSystem default_coord_system; // G10 active coordinate system default cmCanonicalPlane default_select_plane; // G17,G18,G19 reset default - cmUnitsMode default_units_mode; // G20,G21 reset default - cmPathControl default_path_control; // G61,G61.1,G64 reset default - cmDistanceMode default_distance_mode; // G90,G91 reset default + cmUnitsMode default_units_mode; // G20,G21 reset default + cmPathControl default_path_control; // G61,G61.1,G64 reset default + cmDistanceMode default_distance_mode; // G90,G91 reset default - /**** Runtime variables (PRIVATE) ****/ + /**** Runtime variables (PRIVATE) ****/ // Global state variables and flags - cmMachineState machine_state; // macs: machine/cycle/motion is the actual machine state - cmCycleType cycle_type; // cycs - cmMotionState motion_state; // mots + cmMachineState machine_state; // macs: machine/cycle/motion is the actual machine state + cmCycleType cycle_type; // cycs + cmMotionState motion_state; // mots - cmFeedholdType hold_type; // hold: type of feedhold requested - cmFeedholdExit hold_exit; // hold: final state of hold on exit - cmFeedholdState hold_state; // hold: feedhold state machine + cmFeedholdType hold_type; // hold: type of feedhold requested + cmFeedholdExit hold_exit; // hold: final state of hold on exit + cmFeedholdState hold_state; // hold: feedhold state machine - cmFlushState queue_flush_state; // queue flush state machine - cmCycleState cycle_start_state; // used to manage cycle starts and restarts - cmJobKillState job_kill_state; // used to manage job kill transitions - cmOverrideState mfo_state; // feed override state machine + cmFlushState queue_flush_state; // queue flush state machine + cmCycleState cycle_start_state; // used to manage cycle starts and restarts + cmJobKillState job_kill_state; // used to manage job kill transitions + cmOverrideState mfo_state; // feed override state machine - bool return_flags[AXES]; // flags for recording which axes moved - used in feedhold exit move + bool return_flags[AXES]; // flags for recording which axes moved - used in feedhold exit move - uint8_t limit_requested; // set non-zero to request limit switch processing (value is input number) - bool deferred_write_flag; // G10 data has changed (e.g. offsets) - flag to persist them + uint8_t limit_requested; // set non-zero to request limit switch processing (value is input number) + bool deferred_write_flag; // G10 data has changed (e.g. offsets) - flag to persist them - cmHomingState homing_state; // home: homing cycle sub-state machine - uint8_t homed[AXES]; // individual axis homing flags + cmHomingState homing_state; // home: homing cycle sub-state machine + uint8_t homed[AXES]; // individual axis homing flags - bool probe_report_enable; // 0=disabled, 1=enabled - cmProbeState probe_state[PROBES_STORED]; // probing state machine (simple) - uint8_t probe_input; // probing digital input - float probe_results[PROBES_STORED][AXES]; // probing results + bool probe_report_enable; // 0=disabled, 1=enabled + cmProbeState probe_state[PROBES_STORED]; // probing state machine (simple) + uint8_t probe_input; // probing digital input + float probe_results[PROBES_STORED][AXES]; // probing results - float rotation_matrix[3][3]; // three-by-three rotation matrix. We ignore UVW and ABC axes - float rotation_z_offset; // separately handle a z-offset to maintain consistent distance to bed + float rotation_matrix[3][3]; // three-by-three rotation matrix. We ignore UVW and ABC axes + float rotation_z_offset; // separately handle a z-offset to maintain consistent distance to bed - float jogging_dest; // jogging destination as a relative move from current position + float jogging_dest; // jogging destination as a relative move from current position - /**** Model state structures ****/ - void *mp; // linked mpPlanner_t - use a void pointer to avoid circular header files - cmArc_t arc; // arc parameters - GCodeState_t *am; // active Gcode model is maintained by state management + /**** Model state structures ****/ + void *mp; // linked mpPlanner_t - use a void pointer to avoid circular header files + cmArc_t arc; // arc parameters + GCodeState_t *am; // active Gcode model is maintained by state management - GCodeState_t gm; // core gcode model state - GCodeStateX_t gmx; // extended gcode model state + GCodeState_t gm; // core gcode model state + GCodeStateX_t gmx; // extended gcode model state magic_t magic_end; } cmMachine_t; -typedef struct cmToolTable { // struct to keep a global tool table - float tt_offset[TOOLS+1][AXES]; // persistent tool table offsets +typedef struct cmToolTable { // struct to keep a global tool table + float tt_offset[TOOLS + 1][AXES]; // persistent tool table offsets } cmToolTable_t; /**** Externs - See canonical_machine.cpp for allocation ****/ -extern cmMachine_t *cm; // pointer to active canonical machine -extern cmMachine_t cm1; // canonical machine primary machine -extern cmMachine_t cm2; // canonical machine secondary machine +extern cmMachine_t *cm; // pointer to active canonical machine +extern cmMachine_t cm1; // canonical machine primary machine +extern cmMachine_t cm2; // canonical machine secondary machine extern cmToolTable_t tt; /***************************************************************************** @@ -356,7 +355,7 @@ uint8_t cm_get_distance_mode(const GCodeState_t *gcode_state); uint8_t cm_get_arc_distance_mode(const GCodeState_t *gcode_state); uint8_t cm_get_feed_rate_mode(const GCodeState_t *gcode_state); uint8_t cm_get_tool(const GCodeState_t *gcode_state); -uint8_t cm_get_block_delete_switch(void); +uint8_t cm_get_block_delete_switch(void); uint8_t cm_get_runtime_busy(void); float cm_get_feed_rate(const GCodeState_t *gcode_state); @@ -387,40 +386,39 @@ stat_t cm_test_soft_limits(const float target[]); // Initialization and termination (4.3.2) void canonical_machine_inits(void); void canonical_machine_init(cmMachine_t *_cm, void *_mp); -void canonical_machine_reset_rotation(cmMachine_t *_cm); // NOT in NIST +void canonical_machine_reset_rotation(cmMachine_t *_cm); // NOT in NIST void canonical_machine_reset(cmMachine_t *_cm); void canonical_machine_init_assertions(cmMachine_t *_cm); stat_t canonical_machine_test_assertions(cmMachine_t *_cm); // Representation (4.3.3) -stat_t cm_select_plane(const uint8_t plane); // G17, G18, G19 -stat_t cm_set_units_mode(const uint8_t mode); // G20, G21 -stat_t cm_set_distance_mode(const uint8_t mode); // G90, G91 -stat_t cm_set_arc_distance_mode(const uint8_t mode); // G90.1, G91.1 -stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, // G43, G43.2 +stat_t cm_select_plane(const uint8_t plane); // G17, G18, G19 +stat_t cm_set_units_mode(const uint8_t mode); // G20, G21 +stat_t cm_set_distance_mode(const uint8_t mode); // G90, G91 +stat_t cm_set_arc_distance_mode(const uint8_t mode); // G90.1, G91.1 +stat_t cm_set_tl_offset(const uint8_t H_word, const bool H_flag, // G43, G43.2 const bool apply_additional); -stat_t cm_cancel_tl_offset(void); // G49 -stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, // G10 - const uint8_t L_word, const bool L_flag, - const float offset[], const bool flag[]); +stat_t cm_cancel_tl_offset(void); // G49 +stat_t cm_set_g10_data(const uint8_t P_word, const bool P_flag, // G10 + const uint8_t L_word, const bool L_flag, const float offset[], const bool flag[]); -void cm_set_position_by_axis(const uint8_t axis, const float position); // set position to abs pos - single axis -void cm_reset_position_to_absolute_position(cmMachine_t *_cm); // set position to abs pos - all axes -stat_t cm_set_absolute_origin(const float origin[], bool flag[]); // G28.3 -void cm_set_axis_origin(uint8_t axis, const float position); // G28.3 planner callback +void cm_set_position_by_axis(const uint8_t axis, const float position); // set position to abs pos - single axis +void cm_reset_position_to_absolute_position(cmMachine_t *_cm); // set position to abs pos - all axes +stat_t cm_set_absolute_origin(const float origin[], bool flag[]); // G28.3 +void cm_set_axis_origin(uint8_t axis, const float position); // G28.3 planner callback -stat_t cm_set_coord_system(const uint8_t coord_system); // G54 - G59 -stat_t cm_set_g92_offsets(const float offset[], const bool flag[]); // G92 -stat_t cm_reset_g92_offsets(void); // G92.1 -stat_t cm_suspend_g92_offsets(void); // G92.2 -stat_t cm_resume_g92_offsets(void); // G92.3 +stat_t cm_set_coord_system(const uint8_t coord_system); // G54 - G59 +stat_t cm_set_g92_offsets(const float offset[], const bool flag[]); // G92 +stat_t cm_reset_g92_offsets(void); // G92.1 +stat_t cm_suspend_g92_offsets(void); // G92.2 +stat_t cm_resume_g92_offsets(void); // G92.3 // Free Space Motion (4.3.4) -stat_t cm_straight_traverse(const float *target, const bool *flags, const cmMotionProfile motion_profile); // G0 -stat_t cm_set_g28_position(void); // G28.1 -stat_t cm_goto_g28_position(const float target[], const bool flags[]); // G28 -stat_t cm_set_g30_position(void); // G30.1 -stat_t cm_goto_g30_position(const float target[], const bool flags[]); // G30 +stat_t cm_straight_traverse(const float *target, const bool *flags, const cmMotionProfile motion_profile); // G0 +stat_t cm_set_g28_position(void); // G28.1 +stat_t cm_goto_g28_position(const float target[], const bool flags[]); // G28 +stat_t cm_set_g30_position(void); // G30.1 +stat_t cm_goto_g30_position(const float target[], const bool flags[]); // G30 // Machining Attributes (4.3.5) stat_t cm_set_feed_rate(const float feed_rate); // F parameter @@ -428,96 +426,96 @@ stat_t cm_set_feed_rate_mode(const uint8_t mode); // G stat_t cm_set_path_control(GCodeState_t *gcode_state, const uint8_t mode); // G61, G61.1, G64 // Machining Functions (4.3.6) -stat_t cm_straight_feed(const float *target, const bool *flags, const cmMotionProfile motion_profile); //G1 -stat_t cm_dwell(const float seconds); // G4, P parameter +stat_t cm_straight_feed(const float *target, const bool *flags, const cmMotionProfile motion_profile); // G1 +stat_t cm_dwell(const float seconds); // G4, P parameter -stat_t cm_arc_feed(const float target[], const bool target_f[], // G2/G3 - target endpoint - const float offset[], const bool offset_f[], // IJK offsets - const float radius, const bool radius_f, // radius if radius mode - const float P_word, const bool P_word_f, // parameter - const bool modal_g1_f, // modal group flag for motion group - const cmMotionMode motion_mode); // defined motion mode +stat_t cm_arc_feed(const float target[], const bool target_f[], // G2/G3 - target endpoint + const float offset[], const bool offset_f[], // IJK offsets + const float radius, const bool radius_f, // radius if radius mode + const float P_word, const bool P_word_f, // parameter + const bool modal_g1_f, // modal group flag for motion group + const cmMotionMode motion_mode); // defined motion mode // Spindle Functions (4.3.7) // see spindle.h for spindle functions - which would go right here // Tool Functions (4.3.8) -stat_t cm_select_tool(const uint8_t tool); // T parameter -stat_t cm_change_tool(const uint8_t tool); // M6 +stat_t cm_select_tool(const uint8_t tool); // T parameter +stat_t cm_change_tool(const uint8_t tool); // M6 // Miscellaneous Functions (4.3.9) // see coolant.h for coolant functions - which would go right here -void cm_message(const char *message); // msg to console (e.g. Gcode comments) +void cm_message(const char *message); // msg to console (e.g. Gcode comments) void cm_reset_overrides(void); -stat_t cm_m48_enable(uint8_t enable); // M48, M49 +stat_t cm_m48_enable(uint8_t enable); // M48, M49 // stat_t cm_fro_control(const float P_word, const bool P_flag); // M50 // stat_t cm_tro_control(const float P_word, const bool P_flag); // M50.1 // See spindle.cpp for cm_spo_control() // M51 // Program Functions (4.3.10) -void cm_cycle_start(void); // (no Gcode) -void cm_cycle_end(void); // (no Gcode) -void cm_canned_cycle_end(void); // end of canned cycle -void cm_program_stop(void); // M0 -void cm_optional_program_stop(void); // M1 -void cm_program_end(void); // M2 +void cm_cycle_start(void); // (no Gcode) +void cm_cycle_end(bool from_command = false); // (no Gcode) +void cm_canned_cycle_end(void); // end of canned cycle +void cm_program_stop(void); // M0 +void cm_optional_program_stop(void); // M1 +void cm_program_end(void); // M2 -stat_t cm_json_command(char *json_string); // M100 -stat_t cm_json_command_immediate(char *json_string); // M100.1 -stat_t cm_json_wait(char *json_string); // M102 +stat_t cm_json_command(char *json_string); // M100 +stat_t cm_json_command_immediate(char *json_string); // M100.1 +stat_t cm_json_wait(char *json_string); // M102 /**** Cycles and External FIles ****/ // Feedhold and related functions (cycle_feedhold.cpp) void cm_operation_init(void); -stat_t cm_operation_runner_callback(void); // operation action runner +stat_t cm_operation_runner_callback(void); // operation action runner void cm_request_alarm(void); void cm_request_fasthold(void); void cm_request_cycle_start(void); void cm_request_feedhold(cmFeedholdType type, cmFeedholdExit exit); void cm_request_queue_flush(); -stat_t cm_feedhold_sequencing_callback(void); // process feedhold, cycle start and queue flush requests +stat_t cm_feedhold_sequencing_callback(void); // process feedhold, cycle start and queue flush requests stat_t cm_feedhold_command_blocker(void); -bool cm_has_hold(void); // has hold in primary planner +bool cm_has_hold(void); // has hold in primary planner // Homing cycles (cycle_homing.cpp) -stat_t cm_homing_cycle_start(const float axes[], const bool flags[]); // G28.2 -stat_t cm_homing_cycle_start_no_set(const float axes[], const bool flags[]); // G28.4 -stat_t cm_homing_cycle_callback(void); // G28.2/.4 main loop callback -void cm_abort_homing(cmMachine_t *_cm); // called from the queue flush sequence to clean up +stat_t cm_homing_cycle_start(const float axes[], const bool flags[]); // G28.2 +stat_t cm_homing_cycle_start_no_set(const float axes[], const bool flags[]); // G28.4 +stat_t cm_homing_cycle_callback(void); // G28.2/.4 main loop callback +void cm_abort_homing(cmMachine_t *_cm); // called from the queue flush sequence to clean up // Probe cycles -stat_t cm_straight_probe(float target[], bool flags[], // G38.x +stat_t cm_straight_probe(float target[], bool flags[], // G38.x bool trip_sense, bool alarm_flag); -stat_t cm_probing_cycle_callback(void); // G38.x main loop callback -void cm_abort_probing(cmMachine_t *_cm); // called from the queue flush sequence to clean up +stat_t cm_probing_cycle_callback(void); // G38.x main loop callback +void cm_abort_probing(cmMachine_t *_cm); // called from the queue flush sequence to clean up -stat_t cm_get_prbr(nvObj_t *nv); // enable/disable probe report +stat_t cm_get_prbr(nvObj_t *nv); // enable/disable probe report stat_t cm_set_prbr(nvObj_t *nv); // Jogging cycle (cycle_jogging.cpp) -stat_t cm_jogging_cycle_callback(void); // jogging cycle main loop -stat_t cm_jogging_cycle_start(uint8_t axis); // {"jogx":-100.3} -float cm_get_jogging_dest(void); // get jogging destination +stat_t cm_jogging_cycle_callback(void); // jogging cycle main loop +stat_t cm_jogging_cycle_start(uint8_t axis); // {"jogx":-100.3} +float cm_get_jogging_dest(void); // get jogging destination // Alarm management (alarm.cpp) -stat_t cm_alrm(nvObj_t *nv); // trigger alarm from command input -stat_t cm_shutd(nvObj_t *nv); // trigger shutdown from command input -stat_t cm_pnic(nvObj_t *nv); // trigger panic from command input -stat_t cm_clr(nvObj_t *nv); // clear alarm and shutdown from command input -void cm_clear(void); // raw clear command -void cm_parse_clear(const char *s); // parse gcode for M30 or M2 clear condition -stat_t cm_is_alarmed(void); // return non-zero status if alarm, shutdown or panic -void cm_halt(void); // halt motion, spindle, coolant, heaters -void cm_halt_motion(void); // halt motion (immediate stop) but not spindle & other IO -stat_t cm_alarm(const stat_t status, const char *msg); // enter alarm state - preserve Gcode state -stat_t cm_shutdown(const stat_t status, const char *msg); // enter shutdown state - dump all state -stat_t cm_panic(const stat_t status, const char *msg); // enter panic state - needs RESET -void cm_request_job_kill(void); // control-D handler +stat_t cm_alrm(nvObj_t *nv); // trigger alarm from command input +stat_t cm_shutd(nvObj_t *nv); // trigger shutdown from command input +stat_t cm_pnic(nvObj_t *nv); // trigger panic from command input +stat_t cm_clr(nvObj_t *nv); // clear alarm and shutdown from command input +void cm_clear(void); // raw clear command +void cm_parse_clear(const char *s); // parse gcode for M30 or M2 clear condition +stat_t cm_is_alarmed(void); // return non-zero status if alarm, shutdown or panic +void cm_halt(void); // halt motion, spindle, coolant, heaters +void cm_halt_motion(void); // halt motion (immediate stop) but not spindle & other IO +stat_t cm_alarm(const stat_t status, const char *msg); // enter alarm state - preserve Gcode state +stat_t cm_shutdown(const stat_t status, const char *msg); // enter shutdown state - dump all state +stat_t cm_panic(const stat_t status, const char *msg); // enter panic state - needs RESET +void cm_request_job_kill(void); // control-D handler /**** cfgArray interface functions ****/ @@ -528,9 +526,9 @@ const configSubtable *const getCmConfig_1(); const configSubtable *const getMpoConfig_1(); const configSubtable *const getPosConfig_1(); const configSubtable *const getOfsConfig_1(); -const configSubtable * const getHomConfig_1(); -const configSubtable * const getPrbConfig_1(); -const configSubtable * const getJogConfig_1(); +const configSubtable *const getHomConfig_1(); +const configSubtable *const getPrbConfig_1(); +const configSubtable *const getJogConfig_1(); const configSubtable *const getAxisConfig_1(); // stat_t cm_get_mline(nvObj_t *nv); // get model line number @@ -542,48 +540,48 @@ const configSubtable *const getAxisConfig_1(); // stat_t cm_get_mots(nvObj_t *nv); // get raw motion state // stat_t cm_get_hold(nvObj_t *nv); // get raw hold state -stat_t cm_get_home(nvObj_t *nv); // get machine homing state -stat_t cm_set_home(nvObj_t *nv); // set machine homing state -stat_t cm_get_hom(nvObj_t *nv); // get homing state for axis -stat_t cm_get_prob(nvObj_t *nv); // get probe state -stat_t cm_get_prb (nvObj_t *nv); // get probe result for axis +stat_t cm_get_home(nvObj_t *nv); // get machine homing state +stat_t cm_set_home(nvObj_t *nv); // set machine homing state +stat_t cm_get_hom(nvObj_t *nv); // get homing state for axis +stat_t cm_get_prob(nvObj_t *nv); // get probe state +stat_t cm_get_prb(nvObj_t *nv); // get probe result for axis stat_t cm_get_probe_input(nvObj_t *nv); stat_t cm_set_probe_input(nvObj_t *nv); -stat_t cm_run_jog(nvObj_t *nv); // start jogging cycle +stat_t cm_run_jog(nvObj_t *nv); // start jogging cycle -stat_t cm_get_unit(nvObj_t *nv); // get unit mode -stat_t cm_get_coor(nvObj_t *nv); // get coordinate system in effect -stat_t cm_get_momo(nvObj_t *nv); // get motion mode -stat_t cm_get_plan(nvObj_t *nv); // get active plane -stat_t cm_get_path(nvObj_t *nv); // get patch control mode -stat_t cm_get_dist(nvObj_t *nv); // get distance mode -stat_t cm_get_admo(nvObj_t *nv); // get arc offset mode -stat_t cm_get_frmo(nvObj_t *nv); // get feedrate mode -stat_t cm_get_toolv(nvObj_t *nv); // get tool (value) -stat_t cm_get_pwr(nvObj_t *nv); // get motor power enable state +stat_t cm_get_unit(nvObj_t *nv); // get unit mode +stat_t cm_get_coor(nvObj_t *nv); // get coordinate system in effect +stat_t cm_get_momo(nvObj_t *nv); // get motion mode +stat_t cm_get_plan(nvObj_t *nv); // get active plane +stat_t cm_get_path(nvObj_t *nv); // get patch control mode +stat_t cm_get_dist(nvObj_t *nv); // get distance mode +stat_t cm_get_admo(nvObj_t *nv); // get arc offset mode +stat_t cm_get_frmo(nvObj_t *nv); // get feedrate mode +stat_t cm_get_toolv(nvObj_t *nv); // get tool (value) +stat_t cm_get_pwr(nvObj_t *nv); // get motor power enable state -stat_t cm_get_vel(nvObj_t *nv); // get runtime velocity -stat_t cm_get_feed(nvObj_t *nv); // get feed rate, converted to units -stat_t cm_get_pos(nvObj_t *nv); // get runtime work position -stat_t cm_get_mpo(nvObj_t *nv); // get runtime machine position -stat_t cm_get_ofs(nvObj_t *nv); // get runtime work offset -stat_t cm_get_coord(nvObj_t *nv); // get coordinate offset -stat_t cm_set_coord(nvObj_t *nv); // set coordinate offset +stat_t cm_get_vel(nvObj_t *nv); // get runtime velocity +stat_t cm_get_feed(nvObj_t *nv); // get feed rate, converted to units +stat_t cm_get_pos(nvObj_t *nv); // get runtime work position +stat_t cm_get_mpo(nvObj_t *nv); // get runtime machine position +stat_t cm_get_ofs(nvObj_t *nv); // get runtime work offset +stat_t cm_get_coord(nvObj_t *nv); // get coordinate offset +stat_t cm_set_coord(nvObj_t *nv); // set coordinate offset -stat_t cm_get_g92e(nvObj_t *nv); // get g92 enable state -stat_t cm_get_g92(nvObj_t *nv); // get g92 offset -stat_t cm_get_g28(nvObj_t *nv); // get g28 offset -stat_t cm_get_g30(nvObj_t *nv); // get g30 offset +stat_t cm_get_g92e(nvObj_t *nv); // get g92 enable state +stat_t cm_get_g92(nvObj_t *nv); // get g92 offset +stat_t cm_get_g28(nvObj_t *nv); // get g28 offset +stat_t cm_get_g30(nvObj_t *nv); // get g30 offset -//stat_t cm_run_qf(nvObj_t *nv); // run queue flush -stat_t cm_run_home(nvObj_t *nv); // start homing cycle +// stat_t cm_run_qf(nvObj_t *nv); // run queue flush +stat_t cm_run_home(nvObj_t *nv); // start homing cycle -//stat_t cm_dam(nvObj_t *nv); // dump active model (debugging command) +// stat_t cm_dam(nvObj_t *nv); // dump active model (debugging command) -stat_t cm_get_tof(nvObj_t *nv); // get tool offset -stat_t cm_set_tof(nvObj_t *nv); // set tool offset -stat_t cm_get_tt(nvObj_t *nv); // get tool table value -stat_t cm_set_tt(nvObj_t *nv); // set tool table value +stat_t cm_get_tof(nvObj_t *nv); // get tool offset +stat_t cm_set_tof(nvObj_t *nv); // set tool offset +stat_t cm_get_tt(nvObj_t *nv); // get tool table value +stat_t cm_set_tt(nvObj_t *nv); // set tool table value // stat_t cm_get_am(nvObj_t *nv); // get axis mode // stat_t cm_set_am(nvObj_t *nv); // set axis mode @@ -620,191 +618,190 @@ void cm_set_axis_high_jerk(const uint8_t axis, const float jerk); // stat_t cm_get_zb(nvObj_t *nv); // get homing zero backoff // stat_t cm_set_zb(nvObj_t *nv); // set homing zero backoff -stat_t cm_get_jt(nvObj_t *nv); // get junction integration time constant -stat_t cm_set_jt(nvObj_t *nv); // set junction integration time constant -stat_t cm_get_ct(nvObj_t *nv); // get chordal tolerance -stat_t cm_set_ct(nvObj_t *nv); // set chordal tolerance -stat_t cm_get_zl(nvObj_t *nv); // get feedhold Z lift -stat_t cm_set_zl(nvObj_t *nv); // set feedhold Z lift -stat_t cm_get_sl(nvObj_t *nv); // get soft limit enable -stat_t cm_set_sl(nvObj_t *nv); // set soft limit enable -stat_t cm_get_lim(nvObj_t *nv); // get hard limit enable -stat_t cm_set_lim(nvObj_t *nv); // set hard limit enable +stat_t cm_get_jt(nvObj_t *nv); // get junction integration time constant +stat_t cm_set_jt(nvObj_t *nv); // set junction integration time constant +stat_t cm_get_ct(nvObj_t *nv); // get chordal tolerance +stat_t cm_set_ct(nvObj_t *nv); // set chordal tolerance +stat_t cm_get_zl(nvObj_t *nv); // get feedhold Z lift +stat_t cm_set_zl(nvObj_t *nv); // set feedhold Z lift +stat_t cm_get_sl(nvObj_t *nv); // get soft limit enable +stat_t cm_set_sl(nvObj_t *nv); // set soft limit enable +stat_t cm_get_lim(nvObj_t *nv); // get hard limit enable +stat_t cm_set_lim(nvObj_t *nv); // set hard limit enable -stat_t cm_get_m48(nvObj_t *nv); // get M48 value (enable/disable overrides) -stat_t cm_set_m48(nvObj_t *nv); // set M48 value (enable/disable overrides) -stat_t cm_get_froe(nvObj_t *nv); // get feedrate override enable -stat_t cm_set_froe(nvObj_t *nv); // set feedrate override enable -stat_t cm_get_fro(nvObj_t *nv); // get feedrate override factor -stat_t cm_set_fro(nvObj_t *nv); // set feedrate override factor +stat_t cm_get_m48(nvObj_t *nv); // get M48 value (enable/disable overrides) +stat_t cm_set_m48(nvObj_t *nv); // set M48 value (enable/disable overrides) +stat_t cm_get_froe(nvObj_t *nv); // get feedrate override enable +stat_t cm_set_froe(nvObj_t *nv); // set feedrate override enable +stat_t cm_get_fro(nvObj_t *nv); // get feedrate override factor +stat_t cm_set_fro(nvObj_t *nv); // set feedrate override factor -stat_t cm_get_troe(nvObj_t *nv); // get traverse override enable -stat_t cm_set_troe(nvObj_t *nv); // set traverse override enable -stat_t cm_get_tro(nvObj_t *nv); // get traverse override factor -stat_t cm_set_tro(nvObj_t *nv); // set traverse override factor +stat_t cm_get_troe(nvObj_t *nv); // get traverse override enable +stat_t cm_set_troe(nvObj_t *nv); // set traverse override enable +stat_t cm_get_tro(nvObj_t *nv); // get traverse override factor +stat_t cm_set_tro(nvObj_t *nv); // set traverse override factor -stat_t cm_set_probe(nvObj_t *nv); // store current position as the latest probe +stat_t cm_set_probe(nvObj_t *nv); // store current position as the latest probe +stat_t cm_set_tram(nvObj_t *nv); // attempt setting the rotation matrix +stat_t cm_get_tram(nvObj_t *nv); // return if the rotation matrix is non-identity -stat_t cm_set_tram(nvObj_t *nv); // attempt setting the rotation matrix -stat_t cm_get_tram(nvObj_t *nv); // return if the rotation matrix is non-identity +stat_t cm_set_nxln(nvObj_t *nv); // set what value we expect the next line number to have +stat_t cm_get_nxln(nvObj_t *nv); // return what value we expect the next line number to have -stat_t cm_set_nxln(nvObj_t *nv); // set what value we expect the next line number to have -stat_t cm_get_nxln(nvObj_t *nv); // return what value we expect the next line number to have - -stat_t cm_get_gpl(nvObj_t *nv); // get gcode default plane -stat_t cm_set_gpl(nvObj_t *nv); // set gcode default plane -stat_t cm_get_gun(nvObj_t *nv); // get gcode default units mode -stat_t cm_set_gun(nvObj_t *nv); // set gcode default units mode -stat_t cm_get_gco(nvObj_t *nv); // get gcode default coordinate system -stat_t cm_set_gco(nvObj_t *nv); // set gcode default coordinate system -stat_t cm_get_gpa(nvObj_t *nv); // get gcode default path control mode -stat_t cm_set_gpa(nvObj_t *nv); // set gcode default path control mode -stat_t cm_get_gdi(nvObj_t *nv); // get gcode default distance mode -stat_t cm_set_gdi(nvObj_t *nv); // set gcode default distance mode +stat_t cm_get_gpl(nvObj_t *nv); // get gcode default plane +stat_t cm_set_gpl(nvObj_t *nv); // set gcode default plane +stat_t cm_get_gun(nvObj_t *nv); // get gcode default units mode +stat_t cm_set_gun(nvObj_t *nv); // set gcode default units mode +stat_t cm_get_gco(nvObj_t *nv); // get gcode default coordinate system +stat_t cm_set_gco(nvObj_t *nv); // set gcode default coordinate system +stat_t cm_get_gpa(nvObj_t *nv); // get gcode default path control mode +stat_t cm_set_gpa(nvObj_t *nv); // set gcode default path control mode +stat_t cm_get_gdi(nvObj_t *nv); // get gcode default distance mode +stat_t cm_set_gdi(nvObj_t *nv); // set gcode default distance mode /*--- text_mode support functions ---*/ #ifdef __TEXT_MODE - void cm_print_vel(nvObj_t *nv); // model state reporting - void cm_print_feed(nvObj_t *nv); - void cm_print_line(nvObj_t *nv); - void cm_print_stat(nvObj_t *nv); - void cm_print_macs(nvObj_t *nv); - void cm_print_cycs(nvObj_t *nv); - void cm_print_mots(nvObj_t *nv); - void cm_print_hold(nvObj_t *nv); - void cm_print_home(nvObj_t *nv); - void cm_print_hom(nvObj_t *nv); - void cm_print_unit(nvObj_t *nv); - void cm_print_coor(nvObj_t *nv); - void cm_print_momo(nvObj_t *nv); - void cm_print_plan(nvObj_t *nv); - void cm_print_path(nvObj_t *nv); - void cm_print_dist(nvObj_t *nv); - void cm_print_admo(nvObj_t *nv); - void cm_print_frmo(nvObj_t *nv); - void cm_print_tool(nvObj_t *nv); - void cm_print_g92e(nvObj_t *nv); +void cm_print_vel(nvObj_t *nv); // model state reporting +void cm_print_feed(nvObj_t *nv); +void cm_print_line(nvObj_t *nv); +void cm_print_stat(nvObj_t *nv); +void cm_print_macs(nvObj_t *nv); +void cm_print_cycs(nvObj_t *nv); +void cm_print_mots(nvObj_t *nv); +void cm_print_hold(nvObj_t *nv); +void cm_print_home(nvObj_t *nv); +void cm_print_hom(nvObj_t *nv); +void cm_print_unit(nvObj_t *nv); +void cm_print_coor(nvObj_t *nv); +void cm_print_momo(nvObj_t *nv); +void cm_print_plan(nvObj_t *nv); +void cm_print_path(nvObj_t *nv); +void cm_print_dist(nvObj_t *nv); +void cm_print_admo(nvObj_t *nv); +void cm_print_frmo(nvObj_t *nv); +void cm_print_tool(nvObj_t *nv); +void cm_print_g92e(nvObj_t *nv); - void cm_print_gpl(nvObj_t *nv); // Gcode defaults - void cm_print_gun(nvObj_t *nv); - void cm_print_gco(nvObj_t *nv); - void cm_print_gpa(nvObj_t *nv); - void cm_print_gdi(nvObj_t *nv); +void cm_print_gpl(nvObj_t *nv); // Gcode defaults +void cm_print_gun(nvObj_t *nv); +void cm_print_gco(nvObj_t *nv); +void cm_print_gpa(nvObj_t *nv); +void cm_print_gdi(nvObj_t *nv); - void cm_print_lin(nvObj_t *nv); // generic print for linear values - void cm_print_pos(nvObj_t *nv); // print runtime work position in prevailing units - void cm_print_mpo(nvObj_t *nv); // print runtime work position always in MM uints - void cm_print_ofs(nvObj_t *nv); // print runtime work offset always in MM uints - void cm_print_tof(nvObj_t *nv); // print tool length offset +void cm_print_lin(nvObj_t *nv); // generic print for linear values +void cm_print_pos(nvObj_t *nv); // print runtime work position in prevailing units +void cm_print_mpo(nvObj_t *nv); // print runtime work position always in MM uints +void cm_print_ofs(nvObj_t *nv); // print runtime work offset always in MM uints +void cm_print_tof(nvObj_t *nv); // print tool length offset - void cm_print_jt(nvObj_t *nv); // global CM settings - void cm_print_ct(nvObj_t *nv); - void cm_print_zl(nvObj_t *nv); - void cm_print_sl(nvObj_t *nv); - void cm_print_lim(nvObj_t *nv); - void cm_print_saf(nvObj_t *nv); +void cm_print_jt(nvObj_t *nv); // global CM settings +void cm_print_ct(nvObj_t *nv); +void cm_print_zl(nvObj_t *nv); +void cm_print_sl(nvObj_t *nv); +void cm_print_lim(nvObj_t *nv); +void cm_print_saf(nvObj_t *nv); - void cm_print_m48(nvObj_t *nv); - void cm_print_froe(nvObj_t *nv); - void cm_print_fro(nvObj_t *nv); - void cm_print_troe(nvObj_t *nv); - void cm_print_tro(nvObj_t *nv); +void cm_print_m48(nvObj_t *nv); +void cm_print_froe(nvObj_t *nv); +void cm_print_fro(nvObj_t *nv); +void cm_print_troe(nvObj_t *nv); +void cm_print_tro(nvObj_t *nv); - void cm_print_tram(nvObj_t *nv); // print if the axis has been rotated - void cm_print_nxln(nvObj_t *nv); // print the value of the next line number expected +void cm_print_tram(nvObj_t *nv); // print if the axis has been rotated +void cm_print_nxln(nvObj_t *nv); // print the value of the next line number expected - void cm_print_am(nvObj_t *nv); // axis print functions - void cm_print_fr(nvObj_t *nv); - void cm_print_vm(nvObj_t *nv); - void cm_print_tm(nvObj_t *nv); - void cm_print_tn(nvObj_t *nv); - void cm_print_jm(nvObj_t *nv); - void cm_print_jh(nvObj_t *nv); - void cm_print_ra(nvObj_t *nv); +void cm_print_am(nvObj_t *nv); // axis print functions +void cm_print_fr(nvObj_t *nv); +void cm_print_vm(nvObj_t *nv); +void cm_print_tm(nvObj_t *nv); +void cm_print_tn(nvObj_t *nv); +void cm_print_jm(nvObj_t *nv); +void cm_print_jh(nvObj_t *nv); +void cm_print_ra(nvObj_t *nv); - void cm_print_hi(nvObj_t *nv); - void cm_print_hd(nvObj_t *nv); - void cm_print_sv(nvObj_t *nv); - void cm_print_lv(nvObj_t *nv); - void cm_print_lb(nvObj_t *nv); - void cm_print_zb(nvObj_t *nv); - void cm_print_cofs(nvObj_t *nv); - void cm_print_cpos(nvObj_t *nv); +void cm_print_hi(nvObj_t *nv); +void cm_print_hd(nvObj_t *nv); +void cm_print_sv(nvObj_t *nv); +void cm_print_lv(nvObj_t *nv); +void cm_print_lb(nvObj_t *nv); +void cm_print_zb(nvObj_t *nv); +void cm_print_cofs(nvObj_t *nv); +void cm_print_cpos(nvObj_t *nv); -#else // __TEXT_MODE +#else // __TEXT_MODE - #define cm_print_vel tx_print_stub // model state reporting - #define cm_print_feed tx_print_stub - #define cm_print_line tx_print_stub - #define cm_print_stat tx_print_stub - #define cm_print_macs tx_print_stub - #define cm_print_cycs tx_print_stub - #define cm_print_mots tx_print_stub - #define cm_print_hold tx_print_stub - #define cm_print_home tx_print_stub - #define cm_print_hom tx_print_stub - #define cm_print_unit tx_print_stub - #define cm_print_coor tx_print_stub - #define cm_print_momo tx_print_stub - #define cm_print_plan tx_print_stub - #define cm_print_path tx_print_stub - #define cm_print_dist tx_print_stub - #define cm_print_admo tx_print_stub - #define cm_print_frmo tx_print_stub - #define cm_print_tool tx_print_stub - #define cm_print_g92e tx_print_stub +#define cm_print_vel tx_print_stub // model state reporting +#define cm_print_feed tx_print_stub +#define cm_print_line tx_print_stub +#define cm_print_stat tx_print_stub +#define cm_print_macs tx_print_stub +#define cm_print_cycs tx_print_stub +#define cm_print_mots tx_print_stub +#define cm_print_hold tx_print_stub +#define cm_print_home tx_print_stub +#define cm_print_hom tx_print_stub +#define cm_print_unit tx_print_stub +#define cm_print_coor tx_print_stub +#define cm_print_momo tx_print_stub +#define cm_print_plan tx_print_stub +#define cm_print_path tx_print_stub +#define cm_print_dist tx_print_stub +#define cm_print_admo tx_print_stub +#define cm_print_frmo tx_print_stub +#define cm_print_tool tx_print_stub +#define cm_print_g92e tx_print_stub - #define cm_print_gpl tx_print_stub // Gcode defaults - #define cm_print_gun tx_print_stub - #define cm_print_gco tx_print_stub - #define cm_print_gpa tx_print_stub - #define cm_print_gdi tx_print_stub +#define cm_print_gpl tx_print_stub // Gcode defaults +#define cm_print_gun tx_print_stub +#define cm_print_gco tx_print_stub +#define cm_print_gpa tx_print_stub +#define cm_print_gdi tx_print_stub - #define cm_print_lin tx_print_stub // generic print for linear values - #define cm_print_pos tx_print_stub // print runtime work position in prevailing units - #define cm_print_mpo tx_print_stub // print runtime work position always in MM units - #define cm_print_ofs tx_print_stub // print runtime work offset always in MM units +#define cm_print_lin tx_print_stub // generic print for linear values +#define cm_print_pos tx_print_stub // print runtime work position in prevailing units +#define cm_print_mpo tx_print_stub // print runtime work position always in MM units +#define cm_print_ofs tx_print_stub // print runtime work offset always in MM units - #define cm_print_jt tx_print_stub // global CM settings - #define cm_print_ct tx_print_stub - #define cm_print_zl tx_print_stub - #define cm_print_sl tx_print_stub - #define cm_print_lim tx_print_stub - #define cm_print_saf tx_print_stub +#define cm_print_jt tx_print_stub // global CM settings +#define cm_print_ct tx_print_stub +#define cm_print_zl tx_print_stub +#define cm_print_sl tx_print_stub +#define cm_print_lim tx_print_stub +#define cm_print_saf tx_print_stub - #define cm_print_m48 tx_print_stub - #define cm_print_froe tx_print_stub - #define cm_print_fro tx_print_stub - #define cm_print_troe tx_print_stub - #define cm_print_tro tx_print_stub - #define cm_print_tram tx_print_stub +#define cm_print_m48 tx_print_stub +#define cm_print_froe tx_print_stub +#define cm_print_fro tx_print_stub +#define cm_print_troe tx_print_stub +#define cm_print_tro tx_print_stub +#define cm_print_tram tx_print_stub - #define cm_print_tram tx_print_stub - #define cm_print_nxln tx_print_stub +#define cm_print_tram tx_print_stub +#define cm_print_nxln tx_print_stub - #define cm_print_am tx_print_stub // axis print functions - #define cm_print_fr tx_print_stub - #define cm_print_vm tx_print_stub - #define cm_print_tm tx_print_stub - #define cm_print_tn tx_print_stub - #define cm_print_jm tx_print_stub - #define cm_print_jh tx_print_stub - #define cm_print_ra tx_print_stub +#define cm_print_am tx_print_stub // axis print functions +#define cm_print_fr tx_print_stub +#define cm_print_vm tx_print_stub +#define cm_print_tm tx_print_stub +#define cm_print_tn tx_print_stub +#define cm_print_jm tx_print_stub +#define cm_print_jh tx_print_stub +#define cm_print_ra tx_print_stub - #define cm_print_hi tx_print_stub - #define cm_print_hd tx_print_stub - #define cm_print_sv tx_print_stub - #define cm_print_lv tx_print_stub - #define cm_print_lb tx_print_stub - #define cm_print_zb tx_print_stub - #define cm_print_cofs tx_print_stub - #define cm_print_cpos tx_print_stub +#define cm_print_hi tx_print_stub +#define cm_print_hd tx_print_stub +#define cm_print_sv tx_print_stub +#define cm_print_lv tx_print_stub +#define cm_print_lb tx_print_stub +#define cm_print_zb tx_print_stub +#define cm_print_cofs tx_print_stub +#define cm_print_cpos tx_print_stub - #define cm_print_pdt txt_print_stub +#define cm_print_pdt txt_print_stub -#endif // __TEXT_MODE +#endif // __TEXT_MODE -#endif // End of include guard: CANONICAL_MACHINE_H_ONCE +#endif // End of include guard: CANONICAL_MACHINE_H_ONCE diff --git a/g2core/coolant.cpp b/g2core/coolant.cpp index 4f94b07c..9597b471 100644 --- a/g2core/coolant.cpp +++ b/g2core/coolant.cpp @@ -25,15 +25,15 @@ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "g2core.h" // #1 dependency order -#include "config.h" // #2 -#include "canonical_machine.h" // #3 -#include "text_parser.h" // #4 - -#include "gpio.h" #include "coolant.h" -#include "planner.h" + +#include "canonical_machine.h" // #3 +#include "config.h" // #2 +#include "g2core.h" // #1 dependency order +#include "gpio.h" #include "hardware.h" +#include "planner.h" +#include "text_parser.h" // #4 #include "util.h" /**** Allocate structures ****/ @@ -57,7 +57,7 @@ coCoolant_t coolant; /**** Static functions ****/ -static void _exec_coolant_control(float* value, bool* flag); +static void _exec_coolant_control(float *value, bool *flag); /**************************************************************************************** * coolant_init() @@ -65,17 +65,17 @@ static void _exec_coolant_control(float* value, bool* flag); */ void coolant_init() { if (MIST_ENABLE_OUTPUT_NUMBER > 0) { - coolant.mist.output = d_out[MIST_ENABLE_OUTPUT_NUMBER-1]; + coolant.mist.output = d_out[MIST_ENABLE_OUTPUT_NUMBER - 1]; coolant.mist.output->setEnabled(IO_ENABLED); coolant.mist.output->setPolarity((ioPolarity)COOLANT_MIST_POLARITY); } if (FLOOD_ENABLE_OUTPUT_NUMBER > 0) { - coolant.flood.output = d_out[FLOOD_ENABLE_OUTPUT_NUMBER-1]; + coolant.flood.output = d_out[FLOOD_ENABLE_OUTPUT_NUMBER - 1]; coolant.flood.output->setEnabled(IO_ENABLED); coolant.flood.output->setPolarity((ioPolarity)COOLANT_FLOOD_POLARITY); } - coolant.mist.state = COOLANT_OFF; + coolant.mist.state = COOLANT_OFF; coolant.flood.state = COOLANT_OFF; } @@ -90,16 +90,14 @@ void coolant_reset() { * _exec_coolant_control() - actually execute the coolant command */ -stat_t coolant_control_immediate(coControl control, coSelect select) -{ - float value[] = { (float)control }; - bool flags[] = { (select & COOLANT_MIST), (select & COOLANT_FLOOD) }; +stat_t coolant_control_immediate(coControl control, coSelect select) { + float value[] = {(float)control}; + bool flags[] = {(select & COOLANT_MIST), (select & COOLANT_FLOOD)}; _exec_coolant_control(value, flags); - return(STAT_OK); + return (STAT_OK); } -stat_t coolant_control_sync(coControl control, coSelect select) -{ +stat_t coolant_control_sync(coControl control, coSelect select) { // Skip the PAUSE operation if pause_enable is not enabled (pause-on-hold) // The pause setting in mist coolant is treated as the master even though it's replicated in flood if ((control == COOLANT_PAUSE) && (!coolant.mist.pause_enable)) { @@ -107,14 +105,13 @@ stat_t coolant_control_sync(coControl control, coSelect select) } // queue the coolant control - float value[] = { (float)control }; - bool flags[] = { (select & COOLANT_MIST), (select & COOLANT_FLOOD) }; + float value[] = {(float)control}; + bool flags[] = {(select & COOLANT_MIST), (select & COOLANT_FLOOD)}; mp_queue_command(_exec_coolant_control, value, flags); - return(STAT_OK); + return (STAT_OK); } static void _exec_coolant_helper(coCoolantChannel_t &co, coControl control) { - bool action = true; int8_t enable_bit = 0; switch (control) { @@ -152,16 +149,15 @@ static void _exec_coolant_helper(coCoolantChannel_t &co, coControl control) { } } -static void _exec_coolant_control(float* value, bool* flag) { - +static void _exec_coolant_control(float *value, bool *flag) { coControl control = (coControl)value[0]; if (control > COOLANT_ACTION_MAX) { return; } - if (flag[0]) { // Mist, M7 + if (flag[0]) { // Mist, M7 _exec_coolant_helper(coolant.mist, control); } - if (flag[1]) { // Flood, M8 + if (flag[1]) { // Flood, M8 _exec_coolant_helper(coolant.flood, control); } } @@ -176,31 +172,30 @@ bool coolant_ready() { return true; } **** Coolant Settings ****************************************************************** ****************************************************************************************/ -stat_t co_get_com(nvObj_t *nv) { return(get_integer(nv, coolant.mist.state)); } -stat_t co_set_com(nvObj_t *nv) { return(coolant_control_immediate((coControl)nv->value_int, COOLANT_MIST)); } -stat_t co_get_cof(nvObj_t *nv) { return(get_integer(nv, coolant.flood.state)); } -stat_t co_set_cof(nvObj_t *nv) { return(coolant_control_immediate((coControl)nv->value_int, COOLANT_FLOOD)); } +stat_t co_get_com(nvObj_t *nv) { return (get_integer(nv, coolant.mist.state)); } +stat_t co_set_com(nvObj_t *nv) { return (coolant_control_immediate((coControl)nv->value_int, COOLANT_MIST)); } +stat_t co_get_cof(nvObj_t *nv) { return (get_integer(nv, coolant.flood.state)); } +stat_t co_set_cof(nvObj_t *nv) { return (coolant_control_immediate((coControl)nv->value_int, COOLANT_FLOOD)); } -stat_t co_get_coph(nvObj_t *nv) { return(get_integer(nv, coolant.mist.pause_enable)); } -stat_t co_set_coph(nvObj_t *nv) -{ +stat_t co_get_coph(nvObj_t *nv) { return (get_integer(nv, coolant.mist.pause_enable)); } +stat_t co_set_coph(nvObj_t *nv) { ritorno(set_integer(nv, (uint8_t &)coolant.mist.pause_enable, 0, 1)); return (set_integer(nv, (uint8_t &)coolant.flood.pause_enable, 0, 1)); } -stat_t co_get_comp(nvObj_t *nv) { return(get_integer(nv, coolant.mist.polarity)); } +stat_t co_get_comp(nvObj_t *nv) { return (get_integer(nv, coolant.mist.polarity)); } stat_t co_set_comp(nvObj_t *nv) { stat_t ret = set_integer(nv, (uint8_t &)coolant.mist.polarity, 0, 1); if (ret == STAT_OK && coolant.mist.output) { - coolant.mist.output->setPolarity((ioPolarity) coolant.mist.polarity); + coolant.mist.output->setPolarity((ioPolarity)coolant.mist.polarity); } return ret; } -stat_t co_get_cofp(nvObj_t *nv) { return(get_integer(nv, coolant.flood.polarity)); } +stat_t co_get_cofp(nvObj_t *nv) { return (get_integer(nv, coolant.flood.polarity)); } stat_t co_set_cofp(nvObj_t *nv) { stat_t ret = set_integer(nv, (uint8_t &)coolant.flood.polarity, 0, 1); if (ret == STAT_OK && coolant.flood.output) { - coolant.flood.output->setPolarity((ioPolarity) coolant.flood.polarity); + coolant.flood.output->setPolarity((ioPolarity)coolant.flood.polarity); } return ret; } @@ -215,13 +210,13 @@ stat_t co_set_cofp(nvObj_t *nv) { const char fmt_coph[] = "[coph] coolant pause on hold%7d [0=no,1=pause_on_hold]\n"; const char fmt_comp[] = "[comp] coolant mist polarity%7d [0=low is ON,1=high is ON]\n"; const char fmt_cofp[] = "[cofp] coolant flood polarity%6d [0=low is ON,1=high is ON]\n"; -const char fmt_com[] = "[com] coolant mist%16d [0=OFF,1=ON]\n"; -const char fmt_cof[] = "[cof] coolant flood%15d [0=OFF,1=ON]\n"; +const char fmt_com[] = "[com] coolant mist%16d [0=OFF,1=ON]\n"; +const char fmt_cof[] = "[cof] coolant flood%15d [0=OFF,1=ON]\n"; -void co_print_coph(nvObj_t* nv) { text_print(nv, fmt_coph); } // TYPE_INT -void co_print_comp(nvObj_t* nv) { text_print(nv, fmt_comp); } // TYPE_INT -void co_print_cofp(nvObj_t* nv) { text_print(nv, fmt_cofp); } // TYPE_INT -void co_print_com(nvObj_t* nv) { text_print(nv, fmt_com); } // TYPE_INT -void co_print_cof(nvObj_t* nv) { text_print(nv, fmt_cof); } // TYPE_INT +void co_print_coph(nvObj_t *nv) { text_print(nv, fmt_coph); } // TYPE_INT +void co_print_comp(nvObj_t *nv) { text_print(nv, fmt_comp); } // TYPE_INT +void co_print_cofp(nvObj_t *nv) { text_print(nv, fmt_cofp); } // TYPE_INT +void co_print_com(nvObj_t *nv) { text_print(nv, fmt_com); } // TYPE_INT +void co_print_cof(nvObj_t *nv) { text_print(nv, fmt_cof); } // TYPE_INT #endif // __TEXT_MODE diff --git a/g2core/cycle_feedhold.cpp b/g2core/cycle_feedhold.cpp index 1b4e9e9d..9be77313 100644 --- a/g2core/cycle_feedhold.cpp +++ b/g2core/cycle_feedhold.cpp @@ -26,20 +26,20 @@ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "g2core.h" // #1 -#include "config.h" // #2 -#include "gcode.h" // #3 #include "canonical_machine.h" -#include "safety_manager.h" -#include "planner.h" -#include "plan_arc.h" -#include "stepper.h" -#include "spindle.h" +#include "config.h" // #2 #include "coolant.h" +#include "g2core.h" // #1 +#include "gcode.h" // #3 +#include "plan_arc.h" +#include "planner.h" +#include "safety_manager.h" +#include "spindle.h" +#include "stepper.h" #include "util.h" #include "xio.h" -//static void _start_feedhold(void); +// static void _start_feedhold(void); void _start_cycle_restart(void); void _start_queue_flush(void); void _start_job_kill(void); @@ -94,33 +94,33 @@ stat_t _run_reset_position(void); /*** Object Definitions ***/ -#define ACTION_MAX 6 // maximum actions that can be queued for an operation -typedef stat_t (*action_exec_t)(); // callback to action execution function +#define ACTION_MAX 6 // maximum actions that can be queued for an operation +typedef stat_t (*action_exec_t)(); // callback to action execution function -typedef struct cmAction { // struct to manage execution of operations - uint8_t number; // DIAGNOSTIC for easier debugging. Not used functionally. - struct cmAction *nx; // static pointer to next buffer - action_exec_t func; // callback to operation action function. nullptr == disabled +typedef struct cmAction { // struct to manage execution of operations + uint8_t number; // DIAGNOSTIC for easier debugging. Not used functionally. + struct cmAction *nx; // static pointer to next buffer + action_exec_t func; // callback to operation action function. nullptr == disabled - void reset() { // clears function pointer + void reset() { // clears function pointer func = nullptr; }; } cmAction_t; -typedef struct cmOperation { // operation runner object - cmAction action[ACTION_MAX]; // singly linked list of action structures - cmAction *add; // pointer to next action to be added - cmAction *run; // pointer to action being executed - bool in_operation; // set true when an operation is running +typedef struct cmOperation { // operation runner object + cmAction action[ACTION_MAX]; // singly linked list of action structures + cmAction *add; // pointer to next action to be added + cmAction *run; // pointer to action being executed + bool in_operation; // set true when an operation is running void reset() { - for (uint8_t i=0; i < ACTION_MAX; i++) { + for (uint8_t i = 0; i < ACTION_MAX; i++) { action[i].reset(); // reset the action controller object action[i].number = i; // DIAGNOSTIC only. Otherwise not used - action[i].nx = &action[i+1]; // link to the next action + action[i].nx = &action[i + 1]; // link to the next action } - action[ACTION_MAX-1].nx = nullptr; // set last action (end of list) - add = action; // initialize pointers to first action struct + action[ACTION_MAX - 1].nx = nullptr; // set last action (end of list) + add = action; // initialize pointers to first action struct run = action; in_operation = false; }; @@ -130,7 +130,7 @@ typedef struct cmOperation { // operation runner object // nothing has been run, and there's no more room, bail return (STAT_INPUT_EXCEEDS_MAX_LENGTH); } - cmAction *old_add = add; // may be nullptr + cmAction *old_add = add; // may be nullptr add = action; // Move the running and upcoming actions to the front @@ -151,13 +151,13 @@ typedef struct cmOperation { // operation runner object return (STAT_OK); }; - stat_t add_action(stat_t(*action_exec)(), bool allow_add_from_operation = false) { + stat_t add_action(stat_t (*action_exec)(), bool allow_add_from_operation = false) { if (in_operation) { if (!allow_add_from_operation) { - return (STAT_COMMAND_NOT_ACCEPTED); // can't add + return (STAT_COMMAND_NOT_ACCEPTED); // can't add } } - if (add == nullptr) { + if (add == nullptr) { // no more room, try to repack ritorno(repack()); } @@ -167,34 +167,35 @@ typedef struct cmOperation { // operation runner object }; stat_t run_operation(void) { - if (run->func == nullptr) { return (STAT_NOOP); } // not an error. This is normal. - in_operation = true; // disable add_action during operations + if (run->func == nullptr) { + return (STAT_NOOP); + } // not an error. This is normal. + in_operation = true; // disable add_action during operations stat_t status; while ((status = run->func()) == STAT_OK) { run = run->nx; - if (run == nullptr || run->func == nullptr) { // operation has completed - reset(); // setup for next operation + if (run == nullptr || run->func == nullptr) { // operation has completed + reset(); // setup for next operation return (STAT_OK); } } - if (status == STAT_EAGAIN) { return (STAT_EAGAIN); } - reset(); // reset operation if action threw an error - return (status); // return error code + if (status == STAT_EAGAIN) { + return (STAT_EAGAIN); + } + reset(); // reset operation if action threw an error + return (status); // return error code }; } cmOperation_t; -cmOperation_t op; // operations runner object +cmOperation_t op; // operations runner object /**************************************************************************************** * cm_operation_init() */ -void cm_operation_init() -{ - op.reset(); -} +void cm_operation_init() { op.reset(); } /**************************************************************************************** **** Feedhold and Related Functions **************************************************** @@ -293,18 +294,17 @@ void cm_operation_init() * handled in the sequencer. */ -stat_t cm_operation_runner_callback() -{ - if (cm1.job_kill_state == JOB_KILL_REQUESTED) { // job kill must wait for any active hold to complete +stat_t cm_operation_runner_callback() { + if (cm1.job_kill_state == JOB_KILL_REQUESTED) { // job kill must wait for any active hold to complete _start_job_kill(); } -// if (cm1.hold_state == FEEDHOLD_REQUESTED) { // look for a queued p2 feedhold -// _start_feedhold(); -// } - if (cm1.queue_flush_state == QUEUE_FLUSH_REQUESTED) { // look for a queued flush request + // if (cm1.hold_state == FEEDHOLD_REQUESTED) { // look for a queued p2 feedhold + // _start_feedhold(); + // } + if (cm1.queue_flush_state == QUEUE_FLUSH_REQUESTED) { // look for a queued flush request _start_queue_flush(); } - if (cm1.cycle_start_state == CYCLE_START_REQUESTED) { // look for a queued cycle start ot restart + if (cm1.cycle_start_state == CYCLE_START_REQUESTED) { // look for a queued cycle start ot restart _start_cycle_restart(); } @@ -316,17 +316,13 @@ stat_t cm_operation_runner_callback() * cm_has_hold() - return true if a hold condition exists (or a pending hold request) */ -bool cm_has_hold() -{ - return (cm1.hold_state != FEEDHOLD_OFF); -} +bool cm_has_hold() { return (cm1.hold_state != FEEDHOLD_OFF); } /* * cm_feedhold_command_blocker() - prevents new Gcode commands from reaching the parser while feedhold is in effect */ -stat_t cm_feedhold_command_blocker() -{ +stat_t cm_feedhold_command_blocker() { if (cm1.hold_state != FEEDHOLD_OFF) { return (STAT_EAGAIN); } @@ -337,21 +333,18 @@ stat_t cm_feedhold_command_blocker() * end state functions and helpers */ -stat_t _run_program_stop() -{ - cm1.hold_state = FEEDHOLD_OFF; // clear the feedhold - cm_cycle_end(); // end cycle and run program stop +stat_t _run_program_stop() { + cm1.hold_state = FEEDHOLD_OFF; // clear the feedhold + cm_cycle_end(); // end cycle and run program stop return (STAT_OK); } -stat_t _run_program_end() -{ +stat_t _run_program_end() { cm_program_end(); return (STAT_OK); } -stat_t _run_reset_position() -{ +stat_t _run_reset_position() { cm_reset_position_to_absolute_position(cm); return (STAT_OK); } @@ -396,15 +389,14 @@ stat_t _run_interlock_ended() { * _start_cycle_start() - run the cycle start */ -void cm_request_cycle_start() -{ - if (cm1.hold_state != FEEDHOLD_OFF) { // restart from a feedhold - if (cm1.queue_flush_state == QUEUE_FLUSH_REQUESTED) { // possible race condition. Flush wins +void cm_request_cycle_start() { + if (cm1.hold_state != FEEDHOLD_OFF) { // restart from a feedhold + if (cm1.queue_flush_state == QUEUE_FLUSH_REQUESTED) { // possible race condition. Flush wins cm1.cycle_start_state = CYCLE_START_OFF; } else { cm1.cycle_start_state = CYCLE_START_REQUESTED; } - } else { // execute cycle start directly + } else { // execute cycle start directly if (mp_has_runnable_buffer(&mp1)) { cm_cycle_start(); st_request_exec_move(); @@ -413,23 +405,44 @@ void cm_request_cycle_start() } } -void _start_cycle_restart() -{ +void _start_cycle_restart() { // Feedhold cycle restart builds an operation to complete multiple actions if (cm1.hold_state == FEEDHOLD_HOLD) { cm1.cycle_start_state = CYCLE_START_OFF; switch (cm1.hold_type) { - case FEEDHOLD_TYPE_HOLD: { op.add_action(_feedhold_restart_no_actions); break; } - case FEEDHOLD_TYPE_ACTIONS: { op.add_action(_feedhold_restart_with_actions); break; } - default: {} + case FEEDHOLD_TYPE_HOLD: { + op.add_action(_feedhold_restart_no_actions); + break; + } + case FEEDHOLD_TYPE_ACTIONS: { + op.add_action(_feedhold_restart_with_actions); + break; + } + default: { + } } switch (cm1.hold_exit) { - case FEEDHOLD_EXIT_CYCLE: { op.add_action(_run_restart_cycle); break; } - case FEEDHOLD_EXIT_FLUSH: { op.add_action(_run_queue_flush); } // no break - case FEEDHOLD_EXIT_STOP: { op.add_action(_run_program_stop); break; } - case FEEDHOLD_EXIT_END: { op.add_action(_run_program_end); break; } - case FEEDHOLD_EXIT_INTERLOCK: { op.add_action(_run_interlock_ended); break; } - default: {} + case FEEDHOLD_EXIT_CYCLE: { + op.add_action(_run_restart_cycle); + break; + } + case FEEDHOLD_EXIT_FLUSH: { + op.add_action(_run_queue_flush); + } // no break + case FEEDHOLD_EXIT_STOP: { + op.add_action(_run_program_stop); + break; + } + case FEEDHOLD_EXIT_END: { + op.add_action(_run_program_end); + break; + } + case FEEDHOLD_EXIT_INTERLOCK: { + op.add_action(_run_interlock_ended); + break; + } + default: { + } } } } @@ -443,8 +456,7 @@ void _start_cycle_restart() * { cm_request_queue_flush(); xio_flush_to_command(); } */ -void cm_request_queue_flush() -{ +void cm_request_queue_flush() { // Can only initiate a queue flush if in a feedhold and e-stop not pressed if ((cm1.hold_state != FEEDHOLD_OFF) && safety_manager->can_queue_flush()) { cm1.queue_flush_state = QUEUE_FLUSH_REQUESTED; @@ -453,8 +465,7 @@ void cm_request_queue_flush() } } -void _start_queue_flush() -{ +void _start_queue_flush() { devflags_t flags = DEV_IS_DATA; // Don't initiate the queue until in HOLD state (this also means that runtime is idle) @@ -474,18 +485,18 @@ void _start_queue_flush() // It is completely synchronous so it can be called directly; // it does not need to be part of an operation(). -stat_t _run_queue_flush() // typically runs from cm1 planner +stat_t _run_queue_flush() // typically runs from cm1 planner { // resetting the planner, but ALSO updating the planner position - do before aborts - planner_reset((mpPlanner_t *)cm->mp); // reset primary planner. also resets the mr under the planner + planner_reset((mpPlanner_t *)cm->mp); // reset primary planner. also resets the mr under the planner cm_reset_position_to_absolute_position(cm); // now that the planner is reset, if the code in these aborts uses planner position, it'll be correct(ish) - cm_abort_arc(cm); // kill arcs so they don't just create more alines - cm_abort_homing(cm); // kill homing so it can reset cleanly - cm_abort_probing(cm); // kill probing so it can exit cleanly + cm_abort_arc(cm); // kill arcs so they don't just create more alines + cm_abort_homing(cm); // kill homing so it can reset cleanly + cm_abort_probing(cm); // kill probing so it can exit cleanly cm1.queue_flush_state = QUEUE_FLUSH_OFF; - qr_request_queue_report(0); // request a queue report, since we've changed the number of buffers available + qr_request_queue_report(0); // request a queue report, since we've changed the number of buffers available return (STAT_OK); } @@ -509,24 +520,20 @@ stat_t _run_queue_flush() // typically runs from cm1 planner * (6) job kill from INTERLOCK perform PROGRAM_END */ -void cm_request_job_kill() -{ - cm1.job_kill_state = JOB_KILL_REQUESTED; -} +void cm_request_job_kill() { cm1.job_kill_state = JOB_KILL_REQUESTED; } // _run_job_kill() should not be called until motion has stopped. // It is completely synchronous so it can be called directly; // it does not need to be part of an operation(). -stat_t _run_job_kill() -{ +stat_t _run_job_kill() { // if in p2 switch to p1 and copy actual position back to p1 if (cm == &cm2) { - cm = &cm1; // return to primary planner (p1) - mp = (mpPlanner_t *)cm->mp; // cm->mp is a void pointer + cm = &cm1; // return to primary planner (p1) + mp = (mpPlanner_t *)cm->mp; // cm->mp is a void pointer mr = mp->mr; - copy_vector(cm1.gmx.position, mr2.position); // transfer actual position back to p1 + copy_vector(cm1.gmx.position, mr2.position); // transfer actual position back to p1 copy_vector(cm1.gm.target, mr2.position); copy_vector(mp1.position, mr2.position); copy_vector(mr1.position, mr2.position); @@ -534,10 +541,10 @@ stat_t _run_job_kill() _run_queue_flush(); - coolant_control_immediate(COOLANT_OFF, COOLANT_BOTH); // stop coolant - spindle_stop(); // stop spindle + coolant_control_immediate(COOLANT_OFF, COOLANT_BOTH); // stop coolant + spindle_stop(); // stop spindle - cm_set_motion_state(MOTION_STOP); // set to stop and set the active model + cm_set_motion_state(MOTION_STOP); // set to stop and set the active model cm->hold_state = FEEDHOLD_OFF; cm_program_end(); @@ -549,26 +556,27 @@ stat_t _run_job_kill() // _start_job_kill() will be entered multiple times until the REQUEST is reset to OFF -void _start_job_kill() -{ +void _start_job_kill() { switch (cm1.machine_state) { - case MACHINE_ALARM: // Case 0's - nothing to do. turn off the request + case MACHINE_ALARM: // Case 0's - nothing to do. turn off the request case MACHINE_SHUTDOWN: case MACHINE_PANIC: { cm1.job_kill_state = JOB_KILL_OFF; return; } - case MACHINE_CYCLE: { // Case 2's - if (cm1.hold_state == FEEDHOLD_OFF) { // Case 2a - in cycle and not in a hold + case MACHINE_CYCLE: { // Case 2's + if (cm1.hold_state == FEEDHOLD_OFF) { // Case 2a - in cycle and not in a hold op.add_action(_feedhold_no_actions); -// op.add_action(_run_job_kill); + // op.add_action(_run_job_kill); } - if (cm1.hold_state == FEEDHOLD_HOLD) { // Case 2c - in a finished hold + if (cm1.hold_state == FEEDHOLD_HOLD) { // Case 2c - in a finished hold _run_job_kill(); } - return; // Case 2b - hold is in progress. Wait for hold to reach HOLD + return; // Case 2b - hold is in progress. Wait for hold to reach HOLD } - default: { _run_job_kill(); } // Cases 1,3,4,5,6 + default: { + _run_job_kill(); + } // Cases 1,3,4,5,6 } } @@ -584,27 +592,55 @@ void _start_job_kill() * - See cmFeedholdFinal - the final state when the feedhold is exited */ -void cm_request_feedhold(cmFeedholdType type, cmFeedholdExit exit) -{ +void cm_request_feedhold(cmFeedholdType type, cmFeedholdExit exit) { // Can only initiate a feedhold if not already in a feedhold if ((cm1.hold_state == FEEDHOLD_OFF)) { cm1.hold_type = type; cm1.hold_exit = exit; switch (cm1.hold_type) { - case FEEDHOLD_TYPE_HOLD: { op.add_action(_feedhold_no_actions); break; } - case FEEDHOLD_TYPE_ACTIONS: { op.add_action(_feedhold_with_actions); break; } - case FEEDHOLD_TYPE_SKIP: { op.add_action(_feedhold_skip); break; } - default: {} + case FEEDHOLD_TYPE_HOLD: { + op.add_action(_feedhold_no_actions); + break; + } + case FEEDHOLD_TYPE_ACTIONS: { + op.add_action(_feedhold_with_actions); + break; + } + case FEEDHOLD_TYPE_SKIP: { + op.add_action(_feedhold_skip); + break; + } + default: { + } } switch (cm1.hold_exit) { - case FEEDHOLD_EXIT_STOP: { op.add_action(_run_program_stop); break; } - case FEEDHOLD_EXIT_END: { op.add_action(_run_program_end); break; } - case FEEDHOLD_EXIT_ALARM: { op.add_action(_run_alarm); break; } - case FEEDHOLD_EXIT_SHUTDOWN: { op.add_action(_run_shutdown); break; } - case FEEDHOLD_EXIT_INTERLOCK: { op.add_action(_run_interlock_started); break; } - case FEEDHOLD_EXIT_RESET_POSITION: { op.add_action(_run_reset_position); break; } - default: {} + case FEEDHOLD_EXIT_STOP: { + op.add_action(_run_program_stop); + break; + } + case FEEDHOLD_EXIT_END: { + op.add_action(_run_program_end); + break; + } + case FEEDHOLD_EXIT_ALARM: { + op.add_action(_run_alarm); + break; + } + case FEEDHOLD_EXIT_SHUTDOWN: { + op.add_action(_run_shutdown); + break; + } + case FEEDHOLD_EXIT_INTERLOCK: { + op.add_action(_run_interlock_started); + break; + } + case FEEDHOLD_EXIT_RESET_POSITION: { + op.add_action(_run_reset_position); + break; + } + default: { + } } return; } @@ -615,25 +651,33 @@ void cm_request_feedhold(cmFeedholdType type, cmFeedholdExit exit) // re-load a hold cm1.hold_type = type; switch (cm1.hold_type) { - case FEEDHOLD_TYPE_HOLD: { op.add_action(_feedhold_no_actions, true); break; } - case FEEDHOLD_TYPE_ACTIONS: { op.add_action(_feedhold_with_actions, true); break; } - case FEEDHOLD_TYPE_SKIP: { op.add_action(_feedhold_skip, true); break; } - default: {} + case FEEDHOLD_TYPE_HOLD: { + op.add_action(_feedhold_no_actions, true); + break; + } + case FEEDHOLD_TYPE_ACTIONS: { + op.add_action(_feedhold_with_actions, true); + break; + } + case FEEDHOLD_TYPE_SKIP: { + op.add_action(_feedhold_skip, true); + break; + } + default: { + } } } // Look for p2 feedhold (feedhold in a feedhold) - if ((cm1.hold_state >= FEEDHOLD_HOLD) && - (cm2.hold_state == FEEDHOLD_OFF) && (cm2.machine_state == MACHINE_CYCLE)) { + if ((cm1.hold_state >= FEEDHOLD_HOLD) && (cm2.hold_state == FEEDHOLD_OFF) && (cm2.machine_state == MACHINE_CYCLE)) { cm2.hold_state = FEEDHOLD_SYNC; return; } // Reset the request if it's invalid if ((cm1.machine_state != MACHINE_CYCLE) || (cm1.motion_state == MOTION_STOP)) { - cm->hold_state = FEEDHOLD_OFF; // cannot honor the feedhold request. reset it + cm->hold_state = FEEDHOLD_OFF; // cannot honor the feedhold request. reset it } - } /* void _start_p2_feedhold() @@ -653,26 +697,30 @@ void _start_p2_feedhold() * Encapsulate entering and exiting p2, as this is tricky and must be done exactly right */ -void _enter_p2() -{ +void _enter_p2() { // Copy the primary canonical machine to the secondary. Here it's OK to co a memcpy. // Set parameters in cm, gm and gmx so you can actually use it memcpy(&cm2, &cm1, sizeof(cmMachine_t)); cm2.hold_state = FEEDHOLD_OFF; + // set gm to copy of current run buffer gm + mpBuf_t *bf = mp_get_run_buffer(); + if (bf) { + cm2.gm = bf->gm; + } cm2.gm.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE; cm2.gm.absolute_override = ABSOLUTE_OVERRIDE_OFF; cm2.queue_flush_state = QUEUE_FLUSH_OFF; cm2.gm.feed_rate = 0; - cm2.arc.run_state = BLOCK_INACTIVE; // Stop a running p1 arc from continuing to execute in p2 + cm2.arc.run_state = BLOCK_INACTIVE; // Stop a running p1 arc from continuing to execute in p2 // Set mp planner to p2 and reset it cm2.mp = &mp2; - planner_reset((mpPlanner_t *)cm2.mp); // mp is a void pointer + planner_reset((mpPlanner_t *)cm2.mp); // mp is a void pointer // Clear the target and set the positions to the current hold position memset(&(cm2.return_flags), 0, sizeof(cm2.return_flags)); memset(&(cm2.gm.target), 0, sizeof(cm2.gm.target)); - memset(&(cm2.gm.target_comp), 0, sizeof(cm2.gm.target_comp)); // zero Kahan compensation + memset(&(cm2.gm.target_comp), 0, sizeof(cm2.gm.target_comp)); // zero Kahan compensation copy_vector(cm2.gmx.position, mr1.position); copy_vector(mp2.position, mr1.position); @@ -686,20 +734,18 @@ void _enter_p2() // Reassign the globals to the secondary CM cm = &cm2; - mp = (mpPlanner_t *)cm2.mp; // mp is a void pointer + mp = (mpPlanner_t *)cm2.mp; // mp is a void pointer mr = mp2.mr; } -void _exit_p2() -{ - cm = &cm1; // return to primary planner (p1) - mp = (mpPlanner_t *)cm1.mp; // cm->mp is a void pointer +void _exit_p2() { + cm = &cm1; // return to primary planner (p1) + mp = (mpPlanner_t *)cm1.mp; // cm->mp is a void pointer mr = mp1.mr; } -void _check_motion_stopped() -{ - if (mp_runtime_is_idle()) { // wait for steppers to actually finish +void _check_motion_stopped() { + if (mp_runtime_is_idle()) { // wait for steppers to actually finish mpBuf_t *bf = mp_get_r(); @@ -707,55 +753,53 @@ void _check_motion_stopped() // If SKIP type, discard the remainder of the block and position to the next block // OR if the buffer is empty then there's nothing to discard, don't modify the buffer either if ((cm->hold_type == FEEDHOLD_TYPE_SKIP) || (bf->buffer_state == MP_BUFFER_EMPTY)) { - copy_vector(mp->position, mr->position); // update planner position to the final runtime position + copy_vector(mp->position, mr->position); // update planner position to the final runtime position if (mp_get_run_buffer()) { - mp_free_run_buffer(); // advance to next block, discarding the rest of the move + mp_free_run_buffer(); // advance to next block, discarding the rest of the move } - } else { // Otherwise setup the block to complete motion (regardless of how hold will ultimately be exited) - bf->length = get_axis_vector_length(mr->position, mr->target); // update bf w/remaining length in move - bf->block_state = BLOCK_INITIAL_ACTION; // tell _exec to re-use the bf buffer - bf->buffer_state = MP_BUFFER_BACK_PLANNED; // so it can be forward planned again - bf->plannable = true; // needed so block can be re-planned + } else { // Otherwise setup the block to complete motion (regardless of how hold will ultimately be exited) + bf->length = get_axis_vector_length(mr->position, mr->target); // update bf w/remaining length in move + bf->block_state = BLOCK_INITIAL_ACTION; // tell _exec to re-use the bf buffer + bf->buffer_state = MP_BUFFER_BACK_PLANNED; // so it can be forward planned again + bf->plannable = true; // needed so block can be re-planned } - mr->reset(); // reset MR for next use and for forward planning + mr->reset(); // reset MR for next use and for forward planning cm_set_motion_state(MOTION_STOP); cm->hold_state = FEEDHOLD_MOTION_STOPPED; sr_request_status_report(SR_REQUEST_IMMEDIATE); } } -stat_t _feedhold_skip() -{ +stat_t _feedhold_skip() { // check for actual motion to stop if (cm1.machine_state != MACHINE_CYCLE) { return (STAT_OK); } - if (cm1.hold_state == FEEDHOLD_OFF) { // if entered while OFF start a feedhold + if (cm1.hold_state == FEEDHOLD_OFF) { // if entered while OFF start a feedhold cm1.hold_type = FEEDHOLD_TYPE_SKIP; - cm1.hold_state = FEEDHOLD_SYNC; // ...FLUSH can be overridden by setting hold_exit after this function + cm1.hold_state = FEEDHOLD_SYNC; // ...FLUSH can be overridden by setting hold_exit after this function } if (cm1.hold_state < FEEDHOLD_MOTION_STOPPED) { return (STAT_EAGAIN); } - cm1.hold_state = FEEDHOLD_OFF; // cannot be in HOLD or command won't plan (see mp_plan_block_list()) - mp_replan_queue(mp_get_r()); // unplan current forward plan (bf head block), and reset all blocks - st_request_forward_plan(); // replan from the new bf buffer + cm1.hold_state = FEEDHOLD_OFF; // cannot be in HOLD or command won't plan (see mp_plan_block_list()) + mp_replan_queue(mp_get_r()); // unplan current forward plan (bf head block), and reset all blocks + st_request_forward_plan(); // replan from the new bf buffer return (STAT_OK); } -stat_t _feedhold_no_actions() -{ +stat_t _feedhold_no_actions() { // initiate the feedhold - if (cm1.hold_state == FEEDHOLD_OFF) { // start a feedhold + if (cm1.hold_state == FEEDHOLD_OFF) { // start a feedhold cm1.hold_type = FEEDHOLD_TYPE_HOLD; -// cm1.hold_exit = FEEDHOLD_EXIT_STOP; // default exit for NO_ACTIONS is STOP... + // cm1.hold_exit = FEEDHOLD_EXIT_STOP; // default exit for NO_ACTIONS is STOP... if (cm1.motion_state == MOTION_STOP) { // if motion has already stopped declare that you are in a feedhold _check_motion_stopped(); cm1.hold_state = FEEDHOLD_HOLD; } else { - cm1.hold_state = FEEDHOLD_SYNC; // ... STOP can be overridden by setting hold_exit after this function + cm1.hold_state = FEEDHOLD_SYNC; // ... STOP can be overridden by setting hold_exit after this function return (STAT_EAGAIN); } } @@ -765,50 +809,50 @@ stat_t _feedhold_no_actions() return (STAT_EAGAIN); } // complete the feedhold - mp_replan_queue(mp_get_r()); // unplan current forward plan (bf head block), and reset all blocks - st_request_forward_plan(); // replan from the new bf buffer + mp_replan_queue(mp_get_r()); // unplan current forward plan (bf head block), and reset all blocks + st_request_forward_plan(); // replan from the new bf buffer cm1.hold_state = FEEDHOLD_HOLD; return (STAT_OK); } -void _feedhold_actions_done_callback(float* vect, bool* flag) -{ - cm1.hold_state = FEEDHOLD_HOLD_ACTIONS_COMPLETE; // penultimate state before transitioning to FEEDHOLD_HOLD +void _feedhold_actions_done_callback(float *vect, bool *flag) { + cm1.hold_state = FEEDHOLD_HOLD_ACTIONS_COMPLETE; // penultimate state before transitioning to FEEDHOLD_HOLD sr_request_status_report(SR_REQUEST_IMMEDIATE); } -stat_t _feedhold_with_actions() // Execute Case (5) +stat_t _feedhold_with_actions() // Execute Case (5) { // if entered while OFF start a feedhold if (cm1.hold_state == FEEDHOLD_OFF) { if (mp_runtime_is_idle()) { // if motion has already stopped declare that you are in a feedhold _check_motion_stopped(); cm1.hold_state = FEEDHOLD_HOLD; - cm1.hold_type = FEEDHOLD_TYPE_HOLD; // no actions will be performed, don't try to undo them + cm1.hold_type = FEEDHOLD_TYPE_HOLD; // no actions will be performed, don't try to undo them } else { - cm1.hold_state = FEEDHOLD_SYNC; // ... STOP can be overridden by setting hold_exit after this function + cm1.hold_state = FEEDHOLD_SYNC; // ... STOP can be overridden by setting hold_exit after this function return (STAT_EAGAIN); } } // Code to run once motion has stopped if (cm1.hold_state == FEEDHOLD_MOTION_STOPPED) { - cm1.hold_state = FEEDHOLD_HOLD_ACTIONS_PENDING; // next state + cm1.hold_state = FEEDHOLD_HOLD_ACTIONS_PENDING; // next state // check for re-entry into feedhold from a cancelled resume if (cm != &cm2) { - _enter_p2(); // enter p2 correctly - cm_set_g30_position(); // set position to return to on exit + _enter_p2(); // enter p2 correctly + cm_set_g30_position(); // set position to return to on exit } // execute feedhold actions - if (fp_NOT_ZERO(cm->feedhold_z_lift)) {// optional Z lift - bool flags[] = { 0,0,1,0,0,0 }; - float target[] = { 0,0,0,0,0,0 }; // convert to inches if in inches mode + if (fp_NOT_ZERO(cm->feedhold_z_lift)) { // optional Z lift + bool flags[] = {0, 0, 1, 0, 0, 0}; + float target[] = {0, 0, 0, 0, 0, 0}; // convert to inches if in inches mode bool skip_move = false; if (cm->feedhold_z_lift < 0) { // if the value is negative, we want to go to Z-max position with G53 if (cm->homed[AXIS_Z]) { // ONLY IF HOMED - cm_set_absolute_override(MODEL, ABSOLUTE_OVERRIDE_ON_DISPLAY_WITH_OFFSETS); // Position stored in abs coords + cm_set_absolute_override( + MODEL, ABSOLUTE_OVERRIDE_ON_DISPLAY_WITH_OFFSETS); // Position stored in abs coords cm_set_distance_mode(ABSOLUTE_DISTANCE_MODE); // Must run in absolute distance mode target[AXIS_Z] = _to_inches(cm->a[AXIS_Z].travel_max); } else { @@ -821,11 +865,11 @@ stat_t _feedhold_with_actions() // Execute Case (5) if (!skip_move) { cm_straight_traverse(target, flags, PROFILE_NORMAL); - cm_set_distance_mode(cm1.gm.distance_mode); // restore distance mode to p1 setting + cm_set_distance_mode(cm1.gm.distance_mode); // restore distance mode to p1 setting } } - spindle_pause(); // optional spindle pause - coolant_control_sync(COOLANT_PAUSE, COOLANT_BOTH); // optional coolant pause + spindle_pause(); // optional spindle pause + coolant_control_sync(COOLANT_PAUSE, COOLANT_BOTH); // optional coolant pause mp_queue_command(_feedhold_actions_done_callback, nullptr, nullptr); return (STAT_EAGAIN); } @@ -840,7 +884,7 @@ stat_t _feedhold_with_actions() // Execute Case (5) cm1.hold_state = FEEDHOLD_HOLD; return (STAT_OK); } - return (STAT_EAGAIN); // keep the compiler happy. Never executed. + return (STAT_EAGAIN); // keep the compiler happy. Never executed. } /**************************************************************************************** @@ -849,28 +893,26 @@ stat_t _feedhold_with_actions() // Execute Case (5) * _feedhold_restart_actions_done_callback() */ -void _feedhold_restart_actions_done_callback(float* vect, bool* flag) -{ - cm1.hold_state = FEEDHOLD_EXIT_ACTIONS_COMPLETE; // penultimate state before transitioning to FEEDHOLD_OFF +void _feedhold_restart_actions_done_callback(float *vect, bool *flag) { + cm1.hold_state = FEEDHOLD_EXIT_ACTIONS_COMPLETE; // penultimate state before transitioning to FEEDHOLD_OFF sr_request_status_report(SR_REQUEST_IMMEDIATE); } //+++++ Make this more robust so it handles being called before reaching HOLD state -stat_t _feedhold_restart_no_actions() -{ +stat_t _feedhold_restart_no_actions() { if (cm1.hold_state == FEEDHOLD_OFF) { - return (STAT_OK); // was called erroneously. Can happen for !%~ + return (STAT_OK); // was called erroneously. Can happen for !%~ } - cm = &cm1; // return to primary planner (p1) - mp = (mpPlanner_t *)cm->mp; // cm->mp is a void pointer + cm = &cm1; // return to primary planner (p1) + mp = (mpPlanner_t *)cm->mp; // cm->mp is a void pointer mr = mp->mr; return (STAT_OK); } -stat_t _feedhold_restart_with_actions() // Execute Cases (6) and (7) +stat_t _feedhold_restart_with_actions() // Execute Cases (6) and (7) { if (cm1.hold_state == FEEDHOLD_OFF) { - return (STAT_OK); // was called erroneously. Can happen for !%~ + return (STAT_OK); // was called erroneously. Can happen for !%~ } // Check to run first-time code @@ -880,8 +922,8 @@ stat_t _feedhold_restart_with_actions() // Execute Cases (6) and (7) } // perform end-hold actions --- while still in secondary machine - coolant_control_sync(COOLANT_RESUME, COOLANT_BOTH); // resume coolant if paused - spindle_resume(); // resume spindle if paused + coolant_control_sync(COOLANT_RESUME, COOLANT_BOTH); // resume coolant if paused + spindle_resume(); // resume spindle if paused // do return move though an intermediate point; queue a wait cm2.return_flags[AXIS_Z] = false; @@ -893,14 +935,13 @@ stat_t _feedhold_restart_with_actions() // Execute Cases (6) and (7) // wait for exit actions to complete if (cm1.hold_state == FEEDHOLD_EXIT_ACTIONS_PENDING) { - if (cm2.hold_state == FEEDHOLD_MOTION_STOPPED) { if (!mp_runtime_is_idle()) { // if there's still motion, wait return (STAT_EAGAIN); } - cm2.hold_state = FEEDHOLD_OFF; // "inner" feedhold is now done, clear it as off - cm1.hold_state = FEEDHOLD_MOTION_STOPPED; // pass back the state as motion has stopped for clean re-entry + cm2.hold_state = FEEDHOLD_OFF; // "inner" feedhold is now done, clear it as off + cm1.hold_state = FEEDHOLD_MOTION_STOPPED; // pass back the state as motion has stopped for clean re-entry // flush the queue of moves and commands for the exit, return cm2 to STOPPED _run_queue_flush(); @@ -913,20 +954,19 @@ stat_t _feedhold_restart_with_actions() // Execute Cases (6) and (7) // finalize feedhold exit if (cm1.hold_state == FEEDHOLD_EXIT_ACTIONS_COMPLETE) { - _exit_p2(); // re-enter p1 correctly + _exit_p2(); // re-enter p1 correctly return (STAT_OK); } - return (STAT_EAGAIN); // still waiting + return (STAT_EAGAIN); // still waiting } -stat_t _run_restart_cycle(void) -{ +stat_t _run_restart_cycle(void) { if (cm1.hold_state == FEEDHOLD_MOTION_STOPPED) { // the restart was cancelled, move along, nothing to see here... return (STAT_OK); } - cm1.hold_state = FEEDHOLD_OFF; // must precede st_request_exec_move() + cm1.hold_state = FEEDHOLD_OFF; // must precede st_request_exec_move() if (mp_has_runnable_buffer(&mp1)) { cm_cycle_start(); diff --git a/g2core/gcode_parser.cpp b/g2core/gcode_parser.cpp index fb7e9d91..95dadc96 100644 --- a/g2core/gcode_parser.cpp +++ b/g2core/gcode_parser.cpp @@ -730,7 +730,7 @@ static stat_t _parse_gcode_block(char *buf, char *active_comment) } break; } - case 49: SET_NON_MODAL (next_action, NEXT_ACTION_CANCEL_TL_OFFSET); + case 49: SET_NON_MODAL (next_action, NEXT_ACTION_CANCEL_TL_OFFSET); case 53: SET_NON_MODAL (absolute_override, ABSOLUTE_OVERRIDE_ON_DISPLAY_WITH_NO_OFFSETS); case 54: SET_MODAL (MODAL_GROUP_G12, coord_system, G54); case 55: SET_MODAL (MODAL_GROUP_G12, coord_system, G55); diff --git a/g2core/plan_exec.cpp b/g2core/plan_exec.cpp index f4381398..75598685 100644 --- a/g2core/plan_exec.cpp +++ b/g2core/plan_exec.cpp @@ -26,24 +26,24 @@ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "g2core.h" #include "config.h" #include "controller.h" -#include "planner.h" -#include "kinematics.h" -#include "stepper.h" #include "encoder.h" +#include "g2core.h" +#include "kinematics.h" +#include "planner.h" #include "report.h" -#include "util.h" #include "spindle.h" -#include "xio.h" // DIAGNOSTIC +#include "stepper.h" +#include "util.h" +#include "xio.h" // DIAGNOSTIC // execute routines (NB: These are all called from the LO interrupt) -static stat_t _exec_aline_head(mpBuf_t *bf); // passing bf because body might need it, and it might call body -static stat_t _exec_aline_body(mpBuf_t *bf); // passing bf so that body can extend itself if the exit velocity rises. +static stat_t _exec_aline_head(mpBuf_t *bf); // passing bf because body might need it, and it might call body +static stat_t _exec_aline_body(mpBuf_t *bf); // passing bf so that body can extend itself if the exit velocity rises. static stat_t _exec_aline_tail(mpBuf_t *bf); static stat_t _exec_aline_segment(void); -static void _exec_aline_normalize_block(mpBlockRuntimeBuf_t *b); +static void _exec_aline_normalize_block(mpBlockRuntimeBuf_t *b); static stat_t _exec_aline_feedhold(mpBuf_t *bf); static void _init_forward_diffs(float v_0, float v_1); @@ -149,8 +149,8 @@ static void _init_forward_diffs(float v_0, float v_1); * f. RUNNING/COMMAND BACK_PLANNED/MOVE plan move, exit OK * g. RUNNING/COMMAND FULLY_PLANNED/MOVE exit NOOP * h. RUNNING/COMMAND COMMAND(s) NOT_PLANNED skip/plan command(s), exit OK - * i. RUNNING/COMMAND COMMAND(s) BACK_PLANNED/MOVE skip/plan command(s), plan move (Note 1a), exit OK - * j. RUNNING/COMMAND COMMAND(s) FULLY_PLANNED/MOVE skip command(s), exit NOOP + * i. RUNNING/COMMAND COMMAND(s) BACK_PLANNED/MOVE skip/plan command(s), plan move (Note 1a), + * exit OK j. RUNNING/COMMAND COMMAND(s) FULLY_PLANNED/MOVE skip command(s), exit NOOP * * (Note: all COMMAND(s) in 2j. should be in PLANNED state) */ @@ -168,65 +168,62 @@ static void _init_forward_diffs(float v_0, float v_1); * mr->p is only advanced in mp_exec_aline(), after mp->r = mr->p. * This code aligns the buffers and the blocks for exec_aline(). */ -static stat_t _plan_aline(mpBuf_t *bf, float entry_velocity) -{ - mpBlockRuntimeBuf_t* block = mr->p; // set a local planning block so pointer doesn't change on you +static stat_t _plan_aline(mpBuf_t *bf, float entry_velocity) { + mpBlockRuntimeBuf_t *block = mr->p; // set a local planning block so pointer doesn't change on you mp_calculate_ramps(block, bf, entry_velocity); // (which it will if you don't do this) debug_trap_if_true((block->exit_velocity > block->cruise_velocity), - "_plan_line() exit velocity > cruise velocity after calculate_ramps()"); + "_plan_line() exit velocity > cruise velocity after calculate_ramps()"); debug_trap_if_true((block->head_length < 0.00001 && block->body_length < 0.00001 && block->tail_length < 0.00001), - "_plan_line() zero or negative length block after calculate_ramps()"); + "_plan_line() zero or negative length block after calculate_ramps()"); - bf->buffer_state = MP_BUFFER_FULLY_PLANNED; //...here + bf->buffer_state = MP_BUFFER_FULLY_PLANNED; //...here bf->plannable = false; - return (STAT_OK); // report that we planned something... + return (STAT_OK); // report that we planned something... } -stat_t mp_forward_plan() -{ +stat_t mp_forward_plan() { mpBuf_t *bf = mp_get_run_buffer(); float entry_velocity; // Case 0: Examine current running buffer for early exit conditions - if (bf == NULL) { // case 0a: NULL means nothing is running - this is OK - st_prep_null(); + if (bf == NULL) { // case 0a: NULL means nothing is running - this is OK return (STAT_OK); } - if (bf->buffer_state < MP_BUFFER_BACK_PLANNED) { // case 0b: nothing to do. get outta here. + if (bf->buffer_state < MP_BUFFER_BACK_PLANNED) { // case 0b: nothing to do. get outta here. return (STAT_OK); } // Case 2: Running cases - move bf past run buffer so it acts like case 1 if (bf->buffer_state == MP_BUFFER_RUNNING) { bf = bf->nx; - entry_velocity = mr->r->exit_velocity; // set Note 1 entry_velocity (move cases) + entry_velocity = mr->r->exit_velocity; // set Note 1 entry_velocity (move cases) } else { - entry_velocity = mr->entry_velocity; // set Note 2 entry velocity (command cases) + entry_velocity = mr->entry_velocity; // set Note 2 entry velocity (command cases) } // bf points to a command block; start cases 1f, 1g, 1h, 1i, 1j, 1k, 2c, 2d, 2e, 2h, 2i, 2j bool planned_something = false; - if (bf->block_type != BLOCK_TYPE_ALINE) { // meaning it's a COMMAND + if (bf->block_type != BLOCK_TYPE_ALINE) { // meaning it's a COMMAND while (bf->block_type >= BLOCK_TYPE_COMMAND) { if (bf->buffer_state == MP_BUFFER_BACK_PLANNED) { - bf->buffer_state = MP_BUFFER_FULLY_PLANNED; // "planning" is just setting the state (for now) + bf->buffer_state = MP_BUFFER_FULLY_PLANNED; // "planning" is just setting the state (for now) planned_something = true; } bf = bf->nx; } // Note: bf now points to the first non-command buffer past the command(s) - if ((bf->block_type == BLOCK_TYPE_ALINE) && (bf->buffer_state > MP_BUFFER_BACK_PLANNED )) { // case 1i - entry_velocity = mr->r->exit_velocity; // set entry_velocity for Note 1a + if ((bf->block_type == BLOCK_TYPE_ALINE) && (bf->buffer_state > MP_BUFFER_BACK_PLANNED)) { // case 1i + entry_velocity = mr->r->exit_velocity; // set entry_velocity for Note 1a } } // bf will always be on a non-command at this point - either a move or empty buffer // process move - if (bf->block_type == BLOCK_TYPE_ALINE) { // do cases 1a - 1e; finish cases 1f - 1k - if (bf->buffer_state == MP_BUFFER_BACK_PLANNED) {// do 1a; finish 1f, 1j, 2d, 2i + if (bf->block_type == BLOCK_TYPE_ALINE) { // do cases 1a - 1e; finish cases 1f - 1k + if (bf->buffer_state == MP_BUFFER_BACK_PLANNED) { // do 1a; finish 1f, 1j, 2d, 2i _plan_aline(bf, entry_velocity); planned_something = true; } @@ -241,8 +238,7 @@ stat_t mp_forward_plan() * Manages run buffers and other details */ -stat_t mp_exec_move() -{ +stat_t mp_exec_move() { mpBuf_t *bf; // Run an out of band dwell. It was probably set in the previous st_load_move() @@ -258,13 +254,13 @@ stat_t mp_exec_move() // If something is MP_BUFFER_BACK_PLANNED, we don't want to idle or prep_null() if ((bf = mp_get_run_buffer()) == NULL || (bf->buffer_state < MP_BUFFER_BACK_PLANNED)) { if (kn->idle_task()) { - return STAT_OK; // IOW: we need something loaded + return STAT_OK; // IOW: we need something loaded } st_prep_null(); - return (STAT_NOOP); // IOW: exec is done, nothing to load here, move on + return (STAT_NOOP); // IOW: exec is done, nothing to load here, move on } - if (bf->block_type == BLOCK_TYPE_ALINE) { // cycle auto-start for lines only + if (bf->block_type == BLOCK_TYPE_ALINE) { // cycle auto-start for lines only // first-time operations if (bf->buffer_state != MP_BUFFER_RUNNING) { @@ -281,17 +277,16 @@ stat_t mp_exec_move() } if (bf->buffer_state == MP_BUFFER_BACK_PLANNED) { - // debug_trap_if_true((cm->motion_state == MOTION_RUN), "mp_exec_move() buffer prepped but not planned"); - // IMPORTANT: can't rpt_exception from here! - // We need to have it planned. We don't want to do this here, - // as it might already be happening in a lower interrupt. + // debug_trap_if_true((cm->motion_state == MOTION_RUN), "mp_exec_move() buffer prepped but not + // planned"); IMPORTANT: can't rpt_exception from here! We need to have it planned. We don't want to do + // this here, as it might already be happening in a lower interrupt. st_prep_null(); st_request_forward_plan(); - return (STAT_NOOP); // IOW: kick it back to the loader + return (STAT_NOOP); // IOW: kick it back to the loader } if (bf->buffer_state == MP_BUFFER_FULLY_PLANNED) { - bf->buffer_state = MP_BUFFER_RUNNING; // must precede mp_planner_time_acccounting() + bf->buffer_state = MP_BUFFER_RUNNING; // must precede mp_planner_time_acccounting() } else { return (STAT_NOOP); } @@ -307,9 +302,9 @@ stat_t mp_exec_move() } } if (bf->bf_func == NULL) { - return(cm_panic(STAT_INTERNAL_ERROR, "mp_exec_move()")); // never supposed to get here + return (cm_panic(STAT_INTERNAL_ERROR, "mp_exec_move()")); // never supposed to get here } - return (bf->bf_func(bf)); // run the move callback in the planner buffer + return (bf->bf_func(bf)); // run the move callback in the planner buffer } /*************************************************************************/ @@ -400,8 +395,7 @@ stat_t mp_exec_move() ** **** NOTICE ** NOTICE ** NOTICE ****/ -stat_t mp_exec_aline(mpBuf_t *bf) -{ +stat_t mp_exec_aline(mpBuf_t *bf) { // don't run the block if the machine is not in cycle if (cm_get_machine_state() != MACHINE_CYCLE) { return (STAT_NOOP); @@ -416,7 +410,6 @@ stat_t mp_exec_aline(mpBuf_t *bf) // Initialize all new blocks, regardless of normal or feedhold operation if (mr->block_state == BLOCK_INACTIVE) { - // ASSERTIONS // Zero length moves (and other too-short moves) should have already been removed earlier @@ -431,22 +424,22 @@ stat_t mp_exec_aline(mpBuf_t *bf) // This is because a "head" is *always* entry->cruise, and a "tail" is *always* cruise->exit, // even if there are no other sections in the move. (This is a significant time savings.) debug_trap_if_true((mr->entry_velocity > mr->r->cruise_velocity), - "mp_exec_aline() mr->entry_velocity > mr->r->cruise_velocity"); + "mp_exec_aline() mr->entry_velocity > mr->r->cruise_velocity"); debug_trap_if_true((mr->r->exit_velocity > mr->r->cruise_velocity), - "mp_exec_aline() mr->exit_velocity > mr->r->cruise_velocity"); + "mp_exec_aline() mr->exit_velocity > mr->r->cruise_velocity"); // Start a new move by setting up the runtime singleton (mr) - memcpy(&mr->gm, &(bf->gm), sizeof(GCodeState_t)); // copy in the gcode model state - bf->block_state = BLOCK_ACTIVE; // note that this buffer is running - mr->block_state = BLOCK_INITIAL_ACTION; // note the planner doesn't look at block_state + memcpy(&mr->gm, &(bf->gm), sizeof(GCodeState_t)); // copy in the gcode model state + bf->block_state = BLOCK_ACTIVE; // note that this buffer is running + mr->block_state = BLOCK_INITIAL_ACTION; // note the planner doesn't look at block_state // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!! THIS IS THE ONLY PLACE WHERE mr->r AND mr->p ARE ALLOWED TO BE CHANGED !!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Swap P and R blocks - mr->r = mr->p; // we are now going to run the planning block - mr->p = mr->p->nx; // re-use the old running block as the new planning block + mr->r = mr->p; // we are now going to run the planning block + mr->p = mr->p->nx; // re-use the old running block as the new planning block // Check to make sure no sections are less than MIN_SEGMENT_TIME & adjust if necessary _exec_aline_normalize_block(mr->r); @@ -456,8 +449,8 @@ stat_t mp_exec_aline(mpBuf_t *bf) copy_vector(mr->target, bf->gm.target); copy_vector(mr->axis_flags, bf->axis_flags); - mr->run_bf = bf; // DIAGNOSTIC: points to running bf - mr->plan_bf = bf->nx; // DIAGNOSTIC: points to next bf to forward plan + mr->run_bf = bf; // DIAGNOSTIC: points to running bf + mr->plan_bf = bf->nx; // DIAGNOSTIC: points to next bf to forward plan // characterize the move for starting section - head/body/tail mr->section_state = SECTION_NEW; @@ -470,10 +463,12 @@ stat_t mp_exec_aline(mpBuf_t *bf) } // generate the way points for position correction at section ends - for (uint8_t axis=0; axiswaypoint[SECTION_HEAD][axis] = mr->position[axis] + mr->unit[axis] * mr->r->head_length; - mr->waypoint[SECTION_BODY][axis] = mr->position[axis] + mr->unit[axis] * (mr->r->head_length + mr->r->body_length); - mr->waypoint[SECTION_TAIL][axis] = mr->position[axis] + mr->unit[axis] * (mr->r->head_length + mr->r->body_length + mr->r->tail_length); + mr->waypoint[SECTION_BODY][axis] = + mr->position[axis] + mr->unit[axis] * (mr->r->head_length + mr->r->body_length); + mr->waypoint[SECTION_TAIL][axis] = + mr->position[axis] + mr->unit[axis] * (mr->r->head_length + mr->r->body_length + mr->r->tail_length); } } @@ -482,8 +477,8 @@ stat_t mp_exec_aline(mpBuf_t *bf) // Feedhold Processing - We need to handle the following cases (listed in rough sequence order): if (cm->hold_state != FEEDHOLD_OFF) { // if running actions, or in HOLD state, or exiting with actions - if (cm->hold_state >= FEEDHOLD_MOTION_STOPPED) { // handles _exec_aline_feedhold_processing case (7) - return (STAT_NOOP); // VERY IMPORTANT to exit as a NOOP. Do not load another move + if (cm->hold_state >= FEEDHOLD_MOTION_STOPPED) { // handles _exec_aline_feedhold_processing case (7) + return (STAT_NOOP); // VERY IMPORTANT to exit as a NOOP. Do not load another move } // STAT_OK terminates aline execution for this move // STAT_NOOP terminates execution and does not load another move @@ -499,10 +494,15 @@ stat_t mp_exec_aline(mpBuf_t *bf) //**** main dispatcher to process segments *** status = STAT_OK; - if (mr->section == SECTION_HEAD) { status = _exec_aline_head(bf); } - else if (mr->section == SECTION_BODY) { status = _exec_aline_body(bf); } - else if (mr->section == SECTION_TAIL) { status = _exec_aline_tail(bf); } - else { return(cm_panic(STAT_INTERNAL_ERROR, "exec_aline()"));} // never supposed to get here + if (mr->section == SECTION_HEAD) { + status = _exec_aline_head(bf); + } else if (mr->section == SECTION_BODY) { + status = _exec_aline_body(bf); + } else if (mr->section == SECTION_TAIL) { + status = _exec_aline_tail(bf); + } else { + return (cm_panic(STAT_INTERNAL_ERROR, "exec_aline()")); + } // never supposed to get here // Conditionally set the move to be unplannable. We can't use the if/else block above, // since the head may call a body or a tail, and a body call tail, so we wait till after. @@ -523,7 +523,7 @@ stat_t mp_exec_aline(mpBuf_t *bf) if (cm->hold_state == FEEDHOLD_DECEL_TO_ZERO) { if ((status == STAT_OK) || (status == STAT_NOOP)) { cm->hold_state = FEEDHOLD_DECEL_COMPLETE; - bf->block_state = BLOCK_INITIAL_ACTION; // reset bf so it can restart the rest of the move + bf->block_state = BLOCK_INITIAL_ACTION; // reset bf so it can restart the rest of the move } } @@ -541,19 +541,19 @@ stat_t mp_exec_aline(mpBuf_t *bf) // STAT_NOOP treated as a STAT_OK if (status == STAT_EAGAIN) { - sr_request_status_report(SR_REQUEST_TIMED); // continue reporting mr buffer - // Note that that'll happen in a lower interrupt level. + sr_request_status_report(SR_REQUEST_TIMED); // continue reporting mr buffer + // Note that that'll happen in a lower interrupt level. } else { - mr->block_state = BLOCK_INACTIVE; // invalidate mr buffer (reset) + mr->block_state = BLOCK_INACTIVE; // invalidate mr buffer (reset) mr->section_state = SECTION_OFF; - mp->run_time_remaining = 0.0; // it's done, so time goes to zero - mr->entry_velocity = mr->r->exit_velocity; // feed the old exit into the entry. + mp->run_time_remaining = 0.0; // it's done, so time goes to zero + mr->entry_velocity = mr->r->exit_velocity; // feed the old exit into the entry. if (bf->block_state == BLOCK_ACTIVE) { - if (mp_free_run_buffer()) { // returns true of the buffer is empty + if (mp_free_run_buffer()) { // returns true of the buffer is empty if (cm->hold_state == FEEDHOLD_OFF) { - cm_set_motion_state(MOTION_STOP); // also sets active model to RUNTIME - cm_cycle_end(); // free buffer & end cycle if planner is empty + cm_set_motion_state(MOTION_STOP); // also sets active model to RUNTIME + cm_cycle_end(); // free buffer & end cycle if planner is empty } } else { st_request_forward_plan(); @@ -677,37 +677,36 @@ stat_t mp_exec_aline(mpBuf_t *bf) */ // Total time: 147us -static void _init_forward_diffs(const float v_0, const float v_1) -{ +static void _init_forward_diffs(const float v_0, const float v_1) { // Times from *here* -/* Full formulation: - const float fifth_T = T * 0.2; //(1/5) T - const float two_fifths_T = T * 0.4; //(2/5) T - const float twentienth_T_2 = T * T * 0.05; // (1/20) T^2 + /* Full formulation: + const float fifth_T = T * 0.2; //(1/5) T + const float two_fifths_T = T * 0.4; //(2/5) T + const float twentienth_T_2 = T * T * 0.05; // (1/20) T^2 - const float P_0 = v_0; - const float P_1 = v_0 + fifth_T*a_0; - const float P_2 = v_0 + two_fifths_T*a_0 + twentienth_T_2*j_0; - const float P_3 = v_1 - two_fifths_T*a_1 + twentienth_T_2*j_1; - const float P_4 = v_1 - fifth_T*a_1; - const float P_5 = v_1; + const float P_0 = v_0; + const float P_1 = v_0 + fifth_T*a_0; + const float P_2 = v_0 + two_fifths_T*a_0 + twentienth_T_2*j_0; + const float P_3 = v_1 - two_fifths_T*a_1 + twentienth_T_2*j_1; + const float P_4 = v_1 - fifth_T*a_1; + const float P_5 = v_1; - const float A = 5*( P_1 - P_4 + 2*(P_3 - P_2) ) + P_5 - P_0; - const float B = 5*( P_0 + P_4 - 4*(P_3 + P_1) + 6*P_2 ); - const float C = 10*( P_3 - P_0 + 3*(P_1 - P_2) ); - const float D = 10*( P_0 + P_2 - 2*P_1 ); - const float E = 5*( P_1 - P_0 ); - //const float F = P_0; -*/ - float A = -6.0*v_0 + 6.0*v_1; - float B = 15.0*v_0 - 15.0*v_1; - float C = -10.0*v_0 + 10.0*v_1; + const float A = 5*( P_1 - P_4 + 2*(P_3 - P_2) ) + P_5 - P_0; + const float B = 5*( P_0 + P_4 - 4*(P_3 + P_1) + 6*P_2 ); + const float C = 10*( P_3 - P_0 + 3*(P_1 - P_2) ); + const float D = 10*( P_0 + P_2 - 2*P_1 ); + const float E = 5*( P_1 - P_0 ); + //const float F = P_0; + */ + float A = -6.0 * v_0 + 6.0 * v_1; + float B = 15.0 * v_0 - 15.0 * v_1; + float C = -10.0 * v_0 + 10.0 * v_1; // D = 0 // E = 0 // F = Vi - const float h = 1/(mr->segments); - const float h_2 = h * h; + const float h = 1 / (mr->segments); + const float h_2 = h * h; const float h_3 = h_2 * h; const float h_4 = h_3 * h; const float h_5 = h_4 * h; @@ -724,11 +723,11 @@ static void _init_forward_diffs(const float v_0, const float v_1) * F_1 = 120 A h^5 */ - mr->forward_diff_5 = Ah_5 + Bh_4 + Ch_3; - mr->forward_diff_4 = 30.0*Ah_5 + 14.0*Bh_4 + 6.0*Ch_3; - mr->forward_diff_3 = 150.0*Ah_5 + 36.0*Bh_4 + 6.0*Ch_3; - mr->forward_diff_2 = 240.0*Ah_5 + 24.0*Bh_4; - mr->forward_diff_1 = 120.0*Ah_5; + mr->forward_diff_5 = Ah_5 + Bh_4 + Ch_3; + mr->forward_diff_4 = 30.0 * Ah_5 + 14.0 * Bh_4 + 6.0 * Ch_3; + mr->forward_diff_3 = 150.0 * Ah_5 + 36.0 * Bh_4 + 6.0 * Ch_3; + mr->forward_diff_2 = 240.0 * Ah_5 + 24.0 * Bh_4; + mr->forward_diff_1 = 120.0 * Ah_5; mr->segment_velocity = v_0; mr->target_velocity = v_0 + mr->forward_diff_5; @@ -738,41 +737,40 @@ static void _init_forward_diffs(const float v_0, const float v_1) * _exec_aline_head() */ -static stat_t _exec_aline_head(mpBuf_t *bf) -{ - if (mr->section_state == SECTION_NEW) { // INITIALIZATION +static stat_t _exec_aline_head(mpBuf_t *bf) { + if (mr->section_state == SECTION_NEW) { // INITIALIZATION if (fp_ZERO(mr->r->head_length)) { mr->section = SECTION_BODY; - return(_exec_aline_body(bf)); // skip ahead to the body generator + return (_exec_aline_body(bf)); // skip ahead to the body generator } - mr->segments = ceil(uSec(mr->r->head_time) / NOM_SEGMENT_USEC);// # of segments for the section + mr->segments = ceil(uSec(mr->r->head_time) / NOM_SEGMENT_USEC); // # of segments for the section mr->segment_count = (uint32_t)mr->segments; - mr->segment_time = mr->r->head_time / mr->segments; // time to advance for each segment + mr->segment_time = mr->r->head_time / mr->segments; // time to advance for each segment if (mr->segment_count == 1) { // We will only have one segment, simply set the velocities mr->segment_velocity = mr->entry_velocity; mr->target_velocity = mr->r->cruise_velocity; } else { - _init_forward_diffs(mr->entry_velocity, mr->r->cruise_velocity); // <-- sets inital segment_velocity + _init_forward_diffs(mr->entry_velocity, mr->r->cruise_velocity); // <-- sets inital segment_velocity } if (mr->segment_time < MIN_SEGMENT_TIME) { debug_trap("mr->segment_time < MIN_SEGMENT_TIME (head)"); - return(STAT_OK); // exit without advancing position, say we're done + return (STAT_OK); // exit without advancing position, say we're done } - mr->section = SECTION_HEAD; // redundant, likely will be optimized out + mr->section = SECTION_HEAD; // redundant, likely will be optimized out mr->section_state = SECTION_RUNNING; } else { mr->segment_velocity = mr->target_velocity; mr->target_velocity += mr->forward_diff_5; } - if (_exec_aline_segment() == STAT_OK) { // set up for second half + if (_exec_aline_segment() == STAT_OK) { // set up for second half if ((fp_ZERO(mr->r->body_length)) && (fp_ZERO(mr->r->tail_length))) { - return(STAT_OK); // ends the move + return (STAT_OK); // ends the move } - mr->section = SECTION_BODY; // advance to body + mr->section = SECTION_BODY; // advance to body mr->section_state = SECTION_NEW; } else { mr->forward_diff_5 += mr->forward_diff_4; @@ -780,7 +778,7 @@ static stat_t _exec_aline_head(mpBuf_t *bf) mr->forward_diff_3 += mr->forward_diff_2; mr->forward_diff_2 += mr->forward_diff_1; } - return(STAT_EAGAIN); + return (STAT_EAGAIN); } /********************************************************************************************* @@ -789,12 +787,11 @@ static stat_t _exec_aline_head(mpBuf_t *bf) * The body is broken into little segments even though it is a straight line * so that feed holds can happen in the middle of a line with minimum latency */ -static stat_t _exec_aline_body(mpBuf_t *bf) -{ +static stat_t _exec_aline_body(mpBuf_t *bf) { if (mr->section_state == SECTION_NEW) { if (fp_ZERO(mr->r->body_length)) { mr->section = SECTION_TAIL; - return(_exec_aline_tail(bf)); // skip ahead to tail periods + return (_exec_aline_tail(bf)); // skip ahead to tail periods } float body_time = mr->r->body_time; @@ -805,17 +802,17 @@ static stat_t _exec_aline_body(mpBuf_t *bf) mr->segment_count = (uint32_t)mr->segments; if (mr->segment_time < MIN_SEGMENT_TIME) { debug_trap("mr->segment_time < MIN_SEGMENT_TIME (body)"); - return(STAT_OK); // exit without advancing position, say we're done + return (STAT_OK); // exit without advancing position, say we're done } mr->section = SECTION_BODY; - mr->section_state = SECTION_RUNNING; // uses PERIOD_2 so last segment detection works + mr->section_state = SECTION_RUNNING; // uses PERIOD_2 so last segment detection works } - if (_exec_aline_segment() == STAT_OK) { // OK means this section is done + if (_exec_aline_segment() == STAT_OK) { // OK means this section is done if (fp_ZERO(mr->r->tail_length)) { - return (STAT_OK); // ends the move + return (STAT_OK); // ends the move } - mr->section = SECTION_TAIL; // advance to tail + mr->section = SECTION_TAIL; // advance to tail mr->section_state = SECTION_NEW; } return (STAT_EAGAIN); @@ -825,27 +822,28 @@ static stat_t _exec_aline_body(mpBuf_t *bf) * _exec_aline_tail() */ -static stat_t _exec_aline_tail(mpBuf_t *bf) -{ - if (mr->section_state == SECTION_NEW) { // INITIALIZATION +static stat_t _exec_aline_tail(mpBuf_t *bf) { + if (mr->section_state == SECTION_NEW) { // INITIALIZATION // Mark the block as unplannable bf->plannable = false; - if (fp_ZERO(mr->r->tail_length)) { return(STAT_OK);} // end the move - mr->segments = ceil(uSec(mr->r->tail_time) / NOM_SEGMENT_USEC);// # of segments for the section + if (fp_ZERO(mr->r->tail_length)) { + return (STAT_OK); + } // end the move + mr->segments = ceil(uSec(mr->r->tail_time) / NOM_SEGMENT_USEC); // # of segments for the section mr->segment_count = (uint32_t)mr->segments; - mr->segment_time = mr->r->tail_time / mr->segments; // time to advance for each segment + mr->segment_time = mr->r->tail_time / mr->segments; // time to advance for each segment if (mr->segment_count == 1) { mr->segment_velocity = mr->r->cruise_velocity; mr->target_velocity = mr->r->exit_velocity; } else { - _init_forward_diffs(mr->r->cruise_velocity, mr->r->exit_velocity); // <-- sets inital segment_velocity + _init_forward_diffs(mr->r->cruise_velocity, mr->r->exit_velocity); // <-- sets inital segment_velocity } if (mr->segment_time < MIN_SEGMENT_TIME) { debug_trap("mr->segment_time < MIN_SEGMENT_TIME (tail)"); - return(STAT_OK); // exit without advancing position, say we're done - // return(STAT_MINIMUM_TIME_MOVE); // exit without advancing position + return (STAT_OK); // exit without advancing position, say we're done + // return(STAT_MINIMUM_TIME_MOVE); // exit without advancing position } mr->section = SECTION_TAIL; mr->section_state = SECTION_RUNNING; @@ -855,7 +853,7 @@ static stat_t _exec_aline_tail(mpBuf_t *bf) } if (_exec_aline_segment() == STAT_OK) { - return(STAT_OK); // STAT_OK completes the move + return (STAT_OK); // STAT_OK completes the move } else { mr->forward_diff_5 += mr->forward_diff_4; mr->forward_diff_4 += mr->forward_diff_3; @@ -888,8 +886,7 @@ static stat_t _exec_aline_tail(mpBuf_t *bf) float exec_target_steps[MOTORS]; float exec_travel_steps[MOTORS]; -static stat_t _exec_aline_segment() -{ +static stat_t _exec_aline_segment() { // Set target position for the segment // If the segment ends on a section waypoint synchronize to the head, body or tail end // Otherwise if not at a section waypoint compute target from segment time and velocity @@ -898,10 +895,10 @@ static stat_t _exec_aline_segment() if ((--mr->segment_count == 0) && (cm->hold_state == FEEDHOLD_OFF)) { copy_vector(mr->gm.target, mr->waypoint[mr->section]); } else { - float segment_length = (mr->segment_velocity+mr->target_velocity) * 0.5 * mr->segment_time; + float segment_length = (mr->segment_velocity + mr->target_velocity) * 0.5 * mr->segment_time; // See https://en.wikipedia.org/wiki/Kahan_summation_algorithm // for the summation compensation description - for (uint8_t a=0; agm.target[a] = mr->position[a] + (mr->unit[a] * segment_length); @@ -913,9 +910,11 @@ static stat_t _exec_aline_segment() } // Convert target position to steps - kn->inverse_kinematics(mr->gm, mr->gm.target, mr->position, mr->segment_velocity, mr->target_velocity, mr->segment_time, exec_target_steps); + kn->inverse_kinematics(mr->gm, mr->gm.target, mr->position, mr->segment_velocity, mr->target_velocity, + mr->segment_time, exec_target_steps); - // Update the mb->run_time_remaining -- we know it's missing the current segment's time before it's loaded, that's ok. + // Update the mb->run_time_remaining -- we know it's missing the current segment's time before it's loaded, that's + // ok. mp->run_time_remaining -= mr->segment_time; if (mp->run_time_remaining < 0) { mp->run_time_remaining = 0.0; @@ -924,11 +923,11 @@ static stat_t _exec_aline_segment() // Set the target steps and call the stepper prep function ritorno(mp_set_target_steps(exec_target_steps)); - copy_vector(mr->position, mr->gm.target); // update position from target + copy_vector(mr->position, mr->gm.target); // update position from target if (mr->segment_count == 0) { - return (STAT_OK); // this section has run all its segments + return (STAT_OK); // this section has run all its segments } - return (STAT_EAGAIN); // this section still has more segments to run + return (STAT_EAGAIN); // this section still has more segments to run } /********************************************************************************************* @@ -937,8 +936,7 @@ static stat_t _exec_aline_segment() * Check to make sure no sections are less than MIN_SEGMENT_TIME & adjust if necessary */ -static void _exec_aline_normalize_block(mpBlockRuntimeBuf_t *b) -{ +static void _exec_aline_normalize_block(mpBlockRuntimeBuf_t *b) { if ((b->head_length > 0) && (b->head_time < MIN_SEGMENT_TIME)) { // Compute the new body time. head_time !== body_time b->body_length += b->head_length; @@ -959,30 +957,27 @@ static void _exec_aline_normalize_block(mpBlockRuntimeBuf_t *b) // If there's still a head or a tail, we will add the body to whichever there is, maybe both. // We saved it for last since it's the most expensive. if ((b->body_length > 0) && (b->body_time < MIN_SEGMENT_TIME)) { - // We'll add the time to either the head or the tail or split it if (b->tail_length > 0) { - if (b->head_length > 0) { // Split the body to the head and tail + if (b->head_length > 0) { // Split the body to the head and tail b->head_length += b->body_length * 0.5; - b->tail_length += b->body_length * 0.5; // let the compiler optimize out one of these * + b->tail_length += b->body_length * 0.5; // let the compiler optimize out one of these * b->head_time = (2.0 * b->head_length) / (mr->entry_velocity + b->cruise_velocity); b->tail_time = (2.0 * b->tail_length) / (b->cruise_velocity + b->exit_velocity); b->body_length = 0; b->body_time = 0; - } else { // Put it all in the tail + } else { // Put it all in the tail b->tail_length += b->body_length; b->tail_time = (2.0 * b->tail_length) / (b->cruise_velocity + b->exit_velocity); b->body_length = 0; b->body_time = 0; } - } - else if (b->head_length > 0) { // Put it all in the head + } else if (b->head_length > 0) { // Put it all in the head b->head_length += b->body_length; b->head_time = (2.0 * b->head_length) / (mr->entry_velocity + b->cruise_velocity); b->body_length = 0; b->body_time = 0; - } - else { // Uh oh! We have a move that's all body, and is still too short!! + } else { // Uh oh! We have a move that's all body, and is still too short!! debug_trap("_exec_aline_normalize_block() - found a move that is too short"); } } @@ -1008,65 +1003,65 @@ static void _exec_aline_normalize_block(mpBlockRuntimeBuf_t *b) * or tail. */ -static stat_t _exec_aline_feedhold(mpBuf_t *bf) -{ +static stat_t _exec_aline_feedhold(mpBuf_t *bf) { // Case (4) - Wait for the steppers to stop and complete the feedhold if (cm->hold_state == FEEDHOLD_MOTION_STOPPING) { - if (mp_runtime_is_idle()) { // wait for steppers to actually finish + if (mp_runtime_is_idle()) { // wait for steppers to actually finish // Motion has stopped, so we can rely on positions and other values to be stable // If hold was SKIP type, discard the remainder of the block and position to the next block if (cm->hold_type == FEEDHOLD_TYPE_SKIP) { - copy_vector(mp->position, mr->position); // update planner position to the final runtime position - mp_free_run_buffer(); // advance to next block, discarding the rest of the move + copy_vector(mp->position, mr->position); // update planner position to the final runtime position + mp_free_run_buffer(); // advance to next block, discarding the rest of the move } // Otherwise setup the block to complete motion (regardless of how hold will ultimately be exited) else { bf->length = get_axis_vector_length(mr->position, mr->target); // update bf w/remaining length in move - // If length ~= 0 it's because the deceleration was exact. Handle this exception to avoid planning errors + // If length ~= 0 it's because the deceleration was exact. Handle this exception to avoid planning + // errors if (bf->length < EPSILON4) { - copy_vector(mp->position, mr->position);// update planner position to the final runtime position - mp_free_run_buffer(); // advance to next block, discarding the zero-length move + copy_vector(mp->position, mr->position); // update planner position to the final runtime position + mp_free_run_buffer(); // advance to next block, discarding the zero-length move } else { - bf->block_state = BLOCK_INITIAL_ACTION; // tell _exec to re-use the bf buffer + bf->block_state = BLOCK_INITIAL_ACTION; // tell _exec to re-use the bf buffer while (bf->buffer_state > MP_BUFFER_BACK_PLANNED) { - bf->buffer_state = MP_BUFFER_BACK_PLANNED;// revert from RUNNING so it can be forward planned again - bf->plannable = true; // needed so block can be re-planned + bf->buffer_state = + MP_BUFFER_BACK_PLANNED; // revert from RUNNING so it can be forward planned again + bf->plannable = true; // needed so block can be re-planned bf = mp_get_next_buffer(bf); } } } - mr->reset(); // reset MR for next use and for forward planning + mr->reset(); // reset MR for next use and for forward planning cm_set_motion_state(MOTION_STOP); cm->hold_state = FEEDHOLD_MOTION_STOPPED; sr_request_status_report(SR_REQUEST_IMMEDIATE); } - return (STAT_NOOP); // hold here. leave with a NOOP so it does not attempt another load and exec. + return (STAT_NOOP); // hold here. leave with a NOOP so it does not attempt another load and exec. } // Case (3') - Decelerated to zero. See also Feedhold Case (3) in mp_exec_aline() // This state is needed to return an OK to complete the aline exec before transitioning to case (4). if (cm->hold_state == FEEDHOLD_DECEL_COMPLETE) { - cm->hold_state = FEEDHOLD_MOTION_STOPPING; // wait for motion to come to a complete stop - return (STAT_OK); // exit from mp_exec_aline() + cm->hold_state = FEEDHOLD_MOTION_STOPPING; // wait for motion to come to a complete stop + return (STAT_OK); // exit from mp_exec_aline() } // Cases (1x), Case (2) // Build a tail-only move from here. Decelerate as fast as possible in the space available. if ((cm->hold_state == FEEDHOLD_SYNC) || ((cm->hold_state == FEEDHOLD_DECEL_CONTINUE) && (mr->block_state == BLOCK_INITIAL_ACTION))) { - // Case (1d) - Already decelerating (in a tail), continue the deceleration. - if (mr->section == SECTION_TAIL) { // if already in a tail don't decelerate. You already are - if (mr->r->exit_velocity < EPSILON2) { // allow near-zero velocities to be treated as zero + if (mr->section == SECTION_TAIL) { // if already in a tail don't decelerate. You already are + if (mr->r->exit_velocity < EPSILON2) { // allow near-zero velocities to be treated as zero cm->hold_state = FEEDHOLD_DECEL_TO_ZERO; } else { cm->hold_state = FEEDHOLD_DECEL_CONTINUE; } - return (STAT_EAGAIN); // exiting with EAGAIN will continue exec_aline() execution + return (STAT_EAGAIN); // exiting with EAGAIN will continue exec_aline() execution } // Case (1a) - Currently accelerating (in a head), skip and waited for body or tail @@ -1081,7 +1076,7 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf) mr->section = SECTION_TAIL; mr->section_state = SECTION_NEW; mr->entry_velocity = mr->segment_velocity; - mr->r->cruise_velocity = mr->entry_velocity; // cruise velocity must be set even if there's no body + mr->r->cruise_velocity = mr->entry_velocity; // cruise velocity must be set even if there's no body mr->r->tail_length = mp_get_target_length(0, mr->r->cruise_velocity, bf); // braking length mr->r->head_length = 0; mr->r->body_length = 0; @@ -1098,7 +1093,7 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf) if ((available_length + EPSILON2 - mr->r->tail_length) > 0) { cm->hold_state = FEEDHOLD_DECEL_TO_ZERO; mr->r->exit_velocity = 0; - mr->r->tail_time = mr->r->tail_length*2 / (mr->r->exit_velocity + mr->r->cruise_velocity); + mr->r->tail_time = mr->r->tail_length * 2 / (mr->r->exit_velocity + mr->r->cruise_velocity); bf->block_time = mr->r->tail_time; } // Cases (1b2, 1c2) deceleration will not fit in the block @@ -1107,7 +1102,7 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf) mr->r->tail_length = available_length; mr->r->exit_velocity = mp_get_decel_velocity(mr->r->cruise_velocity, mr->r->tail_length, bf); if (mr->r->exit_velocity >= 0) { - mr->r->tail_time = mr->r->tail_length*2 / (mr->r->exit_velocity + mr->r->cruise_velocity); + mr->r->tail_time = mr->r->tail_length * 2 / (mr->r->exit_velocity + mr->r->cruise_velocity); bf->block_time = mr->r->tail_time; } // The following branch is rarely if ever taken. It's possible for the deceleration calculation @@ -1124,5 +1119,5 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf) } _exec_aline_normalize_block(mr->r); } - return (STAT_EAGAIN); // exiting with EAGAIN will continue exec_aline() execution + return (STAT_EAGAIN); // exiting with EAGAIN will continue exec_aline() execution } diff --git a/g2core/planner.cpp b/g2core/planner.cpp index bfd77b5b..3bd1a1e0 100644 --- a/g2core/planner.cpp +++ b/g2core/planner.cpp @@ -51,38 +51,39 @@ * Models at different levels should never use data from other levels as the data may have * changed or be out-of-sync and lead to unpredictable results. */ -#include "g2core.h" -#include "config.h" -#include "canonical_machine.h" -#include "plan_arc.h" #include "planner.h" -#include "kinematics.h" -#include "stepper.h" + +#include "canonical_machine.h" +#include "config.h" #include "encoder.h" -#include "report.h" -#include "util.h" +#include "g2core.h" #include "json_parser.h" -#include "xio.h" //+++++ DIAGNOSTIC - only needed if xio_writeline() direct prints are used +#include "kinematics.h" +#include "plan_arc.h" +#include "report.h" +#include "stepper.h" +#include "util.h" +#include "xio.h" //+++++ DIAGNOSTIC - only needed if xio_writeline() direct prints are used // Allocate planner structures -mpPlanner_t *mp; // currently active planner (global variable) -mpPlanner_t mp1; // primary planning context -mpPlanner_t mp2; // secondary planning context +mpPlanner_t *mp; // currently active planner (global variable) +mpPlanner_t mp1; // primary planning context +mpPlanner_t mp2; // secondary planning context -mpPlannerRuntime_t *mr; // context for planner block runtime -mpPlannerRuntime_t mr1; // primary planner runtime context -mpPlannerRuntime_t mr2; // secondary planner runtime context +mpPlannerRuntime_t *mr; // context for planner block runtime +mpPlannerRuntime_t mr1; // primary planner runtime context +mpPlannerRuntime_t mr2; // secondary planner runtime context -mpBuf_t mp1_queue[PLANNER_QUEUE_SIZE]; // storage allocation for primary planner queue buffers -mpBuf_t mp2_queue[SECONDARY_QUEUE_SIZE]; // storage allocation for secondary planner queue buffers +mpBuf_t mp1_queue[PLANNER_QUEUE_SIZE]; // storage allocation for primary planner queue buffers +mpBuf_t mp2_queue[SECONDARY_QUEUE_SIZE]; // storage allocation for secondary planner queue buffers // Execution routines (NB: These are called from the LO interrupt) static stat_t _exec_dwell(mpBuf_t *bf); static stat_t _exec_command(mpBuf_t *bf); // DIAGNOSTICS -//static void _planner_time_accounting(); +// static void _planner_time_accounting(); static void _audit_buffers(); /**************************************************************************************** @@ -98,17 +99,17 @@ struct json_command_buffer_t { }; struct _json_commands_t { - json_command_buffer_t _json_bf[JSON_COMMAND_BUFFER_SIZE]; // storage of all buffers - json_command_buffer_t *_json_r; // pointer to the next "run" buffer - json_command_buffer_t *_json_w; // pointer tot he next "write" buffer + json_command_buffer_t _json_bf[JSON_COMMAND_BUFFER_SIZE]; // storage of all buffers + json_command_buffer_t *_json_r; // pointer to the next "run" buffer + json_command_buffer_t *_json_w; // pointer tot he next "write" buffer int8_t available; // Constructor (initializer) _json_commands_t() { json_command_buffer_t *js_pv = &_json_bf[JSON_COMMAND_BUFFER_SIZE - 1]; - for (uint8_t i=0; i < JSON_COMMAND_BUFFER_SIZE; i++) { - _json_bf[i].nx = &_json_bf[((i+1 == JSON_COMMAND_BUFFER_SIZE) ? 0 : i+1)]; + for (uint8_t i = 0; i < JSON_COMMAND_BUFFER_SIZE; i++) { + _json_bf[i].nx = &_json_bf[((i + 1 == JSON_COMMAND_BUFFER_SIZE) ? 0 : i + 1)]; _json_bf[i].pv = js_pv; js_pv = &_json_bf[i]; } @@ -116,16 +117,14 @@ struct _json_commands_t { }; // Write a json command to the buffer, using up one slot - void write_buffer(char * new_json) { + void write_buffer(char *new_json) { strcpy(_json_w->buf, new_json); available--; _json_w = _json_w->nx; }; // Read a buffer out, but do NOT free it (so it can be used directly) - char *read_buffer() { - return _json_r->buf; - }; + char *read_buffer() { return _json_r->buf; }; // Free the last read buffer. void free_buffer() { @@ -149,75 +148,72 @@ _json_commands_t jc; */ // initialize a planner queue -void _init_planner_queue(mpPlanner_t *_mp, mpBuf_t *queue, uint8_t size) -{ +void _init_planner_queue(mpPlanner_t *_mp, mpBuf_t *queue, uint8_t size) { mpBuf_t *pv, *nx; uint8_t i, nx_i; mpPlannerQueue_t *q = &(_mp->q); - memset(q, 0, sizeof(mpPlannerQueue_t)); // clear values, pointers and status + memset(q, 0, sizeof(mpPlannerQueue_t)); // clear values, pointers and status q->magic_start = MAGICNUM; q->magic_end = MAGICNUM; - memset(queue, 0, sizeof(mpBuf_t)*size); // clear all buffers in queue - q->bf = queue; // link the buffer pool first - q->w = queue; // init all buffer pointers + memset(queue, 0, sizeof(mpBuf_t) * size); // clear all buffers in queue + q->bf = queue; // link the buffer pool first + q->w = queue; // init all buffer pointers q->r = queue; q->queue_size = size; q->buffers_available = size; - pv = &q->bf[size-1]; - for (i=0; i < size; i++) { - q->bf[i].buffer_number = i; // number is for diagnostics only (otherwise not used) - nx_i = ((ibf[size - 1]; + for (i = 0; i < size; i++) { + q->bf[i].buffer_number = i; // number is for diagnostics only (otherwise not used) + nx_i = ((i < size - 1) ? (i + 1) : 0); // buffer increment & wrap nx = &q->bf[nx_i]; - q->bf[i].nx = nx; // setup circular list pointers + q->bf[i].nx = nx; // setup circular list pointers q->bf[i].pv = pv; pv = &q->bf[i]; } - q->bf[size-1].nx = queue; + q->bf[size - 1].nx = queue; } -void planner_init(mpPlanner_t *_mp, mpPlannerRuntime_t *_mr, mpBuf_t *queue, uint8_t queue_size) -{ +void planner_init(mpPlanner_t *_mp, mpPlannerRuntime_t *_mr, mpBuf_t *queue, uint8_t queue_size) { // init planner master structure - memset(_mp, 0, sizeof(mpPlanner_t)); // clear all values, pointers and status - _mp->magic_start = MAGICNUM; // set boundary condition assertions + memset(_mp, 0, sizeof(mpPlanner_t)); // clear all values, pointers and status + _mp->magic_start = MAGICNUM; // set boundary condition assertions _mp->magic_end = MAGICNUM; _mp->mfo_factor = 1.00; // init planner queues - _mp->q.bf = queue; // assign puffer pool to queue manager structure + _mp->q.bf = queue; // assign puffer pool to queue manager structure _init_planner_queue(_mp, queue, queue_size); // init runtime structs _mp->mr = _mr; - memset(_mr, 0, sizeof(mpPlannerRuntime_t)); // clear all values, pointers and status - _mr->magic_start = MAGICNUM; // mr assertions + memset(_mr, 0, sizeof(mpPlannerRuntime_t)); // clear all values, pointers and status + _mr->magic_start = MAGICNUM; // mr assertions _mr->magic_end = MAGICNUM; - _mr->block[0].nx = &_mr->block[1]; // Handle the two "stub blocks" in the runtime structure + _mr->block[0].nx = &_mr->block[1]; // Handle the two "stub blocks" in the runtime structure _mr->block[1].nx = &_mr->block[0]; _mr->r = &_mr->block[0]; _mr->p = &_mr->block[1]; } -void planner_reset(mpPlanner_t *_mp) // reset planner queue, cease MR activity, but leave positions alone +void planner_reset(mpPlanner_t *_mp) // reset planner queue, cease MR activity, but leave positions alone { // selectively reset mpPlanner and mpPlannerRuntime w/o actually wiping them _mp->reset(); _mp->mr->reset(); jc.reset(); - _init_planner_queue(_mp, _mp->q.bf, _mp->q.queue_size); // reset planner buffers + _init_planner_queue(_mp, _mp->q.bf, _mp->q.queue_size); // reset planner buffers } -stat_t planner_assert(const mpPlanner_t *_mp) -{ - if ((BAD_MAGIC(_mp->magic_start)) || (BAD_MAGIC(_mp->magic_end)) || - (BAD_MAGIC(_mp->mr->magic_start)) || (BAD_MAGIC(_mp->mr->magic_end))) { +stat_t planner_assert(const mpPlanner_t *_mp) { + if ((BAD_MAGIC(_mp->magic_start)) || (BAD_MAGIC(_mp->magic_end)) || (BAD_MAGIC(_mp->mr->magic_start)) || + (BAD_MAGIC(_mp->mr->magic_end))) { return (cm_panic(STAT_PLANNER_ASSERTION_FAILURE, "planner_assert()")); } - for (uint8_t i=0; i < _mp->q.queue_size; i++) { + for (uint8_t i = 0; i < _mp->q.queue_size; i++) { if ((_mp->q.bf[i].nx == nullptr) || (_mp->q.bf[i].pv == nullptr)) { return (cm_panic(STAT_PLANNER_ASSERTION_FAILURE, "planner buffer is corrupted")); } @@ -228,10 +224,9 @@ stat_t planner_assert(const mpPlanner_t *_mp) /**************************************************************************************** * mp_halt_runtime() - stop runtime movement immediately */ -void mp_halt_runtime() -{ - stepper_reset(); // stop the steppers and dwells - planner_reset(mp); // reset the active planner +void mp_halt_runtime() { + stepper_reset(); // stop the steppers and dwells + planner_reset(mp); // reset the active planner } /**************************************************************************************** @@ -262,17 +257,17 @@ void mp_halt_runtime() void mp_set_planner_position(uint8_t axis, const float position) { mp->position[axis] = position; } void mp_set_runtime_position(uint8_t axis, const float position) { mr->position[axis] = position; } -void mp_set_steps_to_runtime_position() -{ +void mp_set_steps_to_runtime_position() { if (mr == nullptr) { #if IN_DEBUGGER - __asm__ volatile("BKPT 1"); // mp_set_steps_to_runtime_position called with null mr! + __asm__ volatile("BKPT 1"); // mp_set_steps_to_runtime_position called with null mr! #endif return; } float step_position[MOTORS]; - // There use to be a call to kn_inverse_kinematics here, but we don't do that now, instead we call kn->sync_encoders() - // after handling the steps, allowing the kinematics to intelligently handle the offset of step and position. + // There use to be a call to kn_inverse_kinematics here, but we don't do that now, instead we call + // kn->sync_encoders() after handling the steps, allowing the kinematics to intelligently handle the offset of step + // and position. // Reset everything to match the internal encoders for (uint8_t motor = MOTOR_1; motor < MOTORS; motor++) { @@ -289,7 +284,6 @@ void mp_set_steps_to_runtime_position() kn->sync_encoders(mr->encoder_steps, mr->position); } - /*********************************************************************************** * mp_set_target_steps() - set target steps and prep the steppers * @@ -302,27 +296,27 @@ void mp_set_steps_to_runtime_position() // global, for use locally in various functions float mp_travel_steps[MOTORS]; -stat_t mp_set_target_steps(const float target_steps[MOTORS]) -{ +stat_t mp_set_target_steps(const float target_steps[MOTORS]) { // Bucket-brigade the old target down the chain before getting the new target from kinematics // // NB: The direct manipulation of steps to compute travel_steps only works for Cartesian kinematics. // Other kinematics may require transforming travel distance as opposed to simply subtracting steps. - for (uint8_t m=0; mcommanded_steps[m] = mr->position_steps[m]; // previous segment's position, delayed by 1 segment - mr->position_steps[m] = mr->target_steps[m]; // previous segment's target becomes position - mr->target_steps[m] = target_steps[m]; // set the new target + for (uint8_t m = 0; m < MOTORS; m++) { + mr->commanded_steps[m] = mr->position_steps[m]; // previous segment's position, delayed by 1 segment + mr->position_steps[m] = mr->target_steps[m]; // previous segment's target becomes position + mr->target_steps[m] = target_steps[m]; // set the new target mp_travel_steps[m] = mr->target_steps[m] - mr->position_steps[m]; - mr->encoder_steps[m] = en_read_encoder(m); // get current encoder position (time aligns to commanded_steps) + mr->encoder_steps[m] = en_read_encoder(m); // get current encoder position (time aligns to commanded_steps) mr->following_error[m] = mr->encoder_steps[m] - mr->commanded_steps[m]; } - return st_prep_line(mr->segment_velocity, mr->target_velocity, mp_travel_steps, mr->following_error, mr->segment_time); + return st_prep_line(mr->segment_velocity, mr->target_velocity, mp_travel_steps, mr->following_error, + mr->segment_time); } -stat_t mp_set_target_steps(const float target_steps[MOTORS], const float start_velocities[MOTORS], const float end_velocities[MOTORS], const float segment_time) -{ +stat_t mp_set_target_steps(const float target_steps[MOTORS], const float start_velocities[MOTORS], + const float end_velocities[MOTORS], const float segment_time) { mr->segment_time = segment_time; // Bucket-brigade the old target down the chain before getting the new target from kinematics @@ -330,19 +324,18 @@ stat_t mp_set_target_steps(const float target_steps[MOTORS], const float start_v // NB: The direct manipulation of steps to compute travel_steps only works for Cartesian kinematics. // Other kinematics may require transforming travel distance as opposed to simply subtracting steps. - for (uint8_t m=0; mcommanded_steps[m] = mr->position_steps[m]; // previous segment's position, delayed by 1 segment - mr->position_steps[m] = mr->target_steps[m]; // previous segment's target becomes position - mr->target_steps[m] = target_steps[m]; // set the new target + for (uint8_t m = 0; m < MOTORS; m++) { + mr->commanded_steps[m] = mr->position_steps[m]; // previous segment's position, delayed by 1 segment + mr->position_steps[m] = mr->target_steps[m]; // previous segment's target becomes position + mr->target_steps[m] = target_steps[m]; // set the new target mp_travel_steps[m] = mr->target_steps[m] - mr->position_steps[m]; - mr->encoder_steps[m] = en_read_encoder(m); // get current encoder position (time aligns to commanded_steps) + mr->encoder_steps[m] = en_read_encoder(m); // get current encoder position (time aligns to commanded_steps) mr->following_error[m] = mr->encoder_steps[m] - mr->commanded_steps[m]; } return st_prep_line(start_velocities, end_velocities, mp_travel_steps, mr->following_error, mr->segment_time); } - /**************************************************************************************** * mp_queue_command() - queue a synchronous Mcode, program control, or other command * _exec_command() - callback to execute command @@ -364,8 +357,7 @@ stat_t mp_set_target_steps(const float target_steps[MOTORS], const float start_v * and makes keeping the queue full much easier - therefore avoiding Q starvation */ -void mp_queue_command(cm_exec_t cm_exec, float *value, bool *flag) -{ +void mp_queue_command(cm_exec_t cm_exec, float *value, bool *flag) { mpBuf_t *bf; // Never supposed to fail as buffer availability was checked upstream in the controller @@ -374,28 +366,26 @@ void mp_queue_command(cm_exec_t cm_exec, float *value, bool *flag) return; } bf->block_type = BLOCK_TYPE_COMMAND; - memcpy(&bf->gm, &cm->gm, sizeof(GCodeState_t)); // snapshot the active gcode state - bf->bf_func = _exec_command; // callback to planner queue exec function - bf->cm_func = cm_exec; // callback to canonical machine exec function + memcpy(&bf->gm, &cm->gm, sizeof(GCodeState_t)); // snapshot the active gcode state + bf->bf_func = _exec_command; // callback to planner queue exec function + bf->cm_func = cm_exec; // callback to canonical machine exec function for (uint8_t axis = AXIS_X; axis < AXES; axis++) { - bf->unit[axis] = value[axis]; // use the unit vector to store command values + bf->unit[axis] = value[axis]; // use the unit vector to store command values bf->axis_flags[axis] = flag[axis]; } - mp_commit_write_buffer(BLOCK_TYPE_COMMAND); // must be final operation before exit + mp_commit_write_buffer(BLOCK_TYPE_COMMAND); // must be final operation before exit } -static stat_t _exec_command(mpBuf_t *bf) -{ +static stat_t _exec_command(mpBuf_t *bf) { st_prep_command(bf); return (STAT_OK); } -stat_t mp_runtime_command(mpBuf_t *bf) -{ - bf->cm_func(bf->unit, bf->axis_flags); // 2 vectors used by callbacks +stat_t mp_runtime_command(mpBuf_t *bf) { + bf->cm_func(bf->unit, bf->axis_flags); // 2 vectors used by callbacks if (mp_free_run_buffer()) { - cm_cycle_end(); // free buffer & perform cycle_end if planner is empty + cm_cycle_end(true); // free buffer & perform cycle_end if planner is empty } return (STAT_OK); } @@ -406,48 +396,42 @@ stat_t mp_runtime_command(mpBuf_t *bf) * mp_json_command_immediate() - execute a json command with response suppressed */ -static void _exec_json_command(float *value, bool *flag) -{ +static void _exec_json_command(float *value, bool *flag) { char *json_string = jc.read_buffer(); - json_parse_for_exec(json_string, true); // process it + json_parse_for_exec(json_string, true); // process it jc.free_buffer(); } -stat_t mp_json_command(char *json_string) -{ +stat_t mp_json_command(char *json_string) { // Never supposed to fail, since we stopped parsing when we were full jc.write_buffer(json_string); mp_queue_command(_exec_json_command, nullptr, nullptr); return (STAT_OK); } -stat_t mp_json_command_immediate(char *json_string) -{ - return json_parser(json_string); -} +stat_t mp_json_command_immediate(char *json_string) { return json_parser(json_string); } /**************************************************************************************** * _exec_json_wait() - execute json wait string * mp_json_wait() - queue a json wait command */ -static stat_t _exec_json_wait(mpBuf_t *bf) -{ +static stat_t _exec_json_wait(mpBuf_t *bf) { char *json_string = jc.read_buffer(); // process it - json_parse_for_exec(json_string, false); // do NOT execute + json_parse_for_exec(json_string, false); // do NOT execute nvObj_t *nv = nv_exec; while ((nv != NULL) && (nv->valuetype != TYPE_EMPTY)) { // For now we ignore non-BOOL if (nv->valuetype == TYPE_BOOLEAN) { - bool old_value = (bool)nv->value_int; // force it to bool + bool old_value = (bool)nv->value_int; // force it to bool nv_get_nvObj(nv); bool new_value = (bool)nv->value_int; if (old_value != new_value) { - st_prep_dwell(1.0); // 1ms exactly + st_prep_dwell(1.0); // 1ms exactly return STAT_OK; } } @@ -456,13 +440,12 @@ static stat_t _exec_json_wait(mpBuf_t *bf) jc.free_buffer(); if (mp_free_run_buffer()) { - cm_cycle_end(); // free buffer & perform cycle_end if planner is empty + cm_cycle_end(); // free buffer & perform cycle_end if planner is empty } return (STAT_OK); } -stat_t mp_json_wait(char *json_string) -{ +stat_t mp_json_wait(char *json_string) { // Never supposed to fail, since we stopped parsing when we were full jc.write_buffer(json_string); @@ -474,12 +457,11 @@ stat_t mp_json_wait(char *json_string) return STAT_ERROR; } bf->block_type = BLOCK_TYPE_COMMAND; - bf->bf_func = _exec_json_wait; // callback to planner queue exec function - mp_commit_write_buffer(BLOCK_TYPE_COMMAND); // must be final operation before exit + bf->bf_func = _exec_json_wait; // callback to planner queue exec function + mp_commit_write_buffer(BLOCK_TYPE_COMMAND); // must be final operation before exit return (STAT_OK); } - /**************************************************************************************** * mp_dwell() - queue a dwell * _exec_dwell() - dwell execution @@ -489,25 +471,23 @@ stat_t mp_json_wait(char *json_string) * timer than the stepper pulse timer. */ -stat_t mp_dwell(float seconds) -{ +stat_t mp_dwell(float seconds) { mpBuf_t *bf; - if ((bf = mp_get_write_buffer()) == NULL) { // get write buffer or fail - return(cm_panic(STAT_FAILED_GET_PLANNER_BUFFER, "mp_dwell()")); // not ever supposed to fail + if ((bf = mp_get_write_buffer()) == NULL) { // get write buffer or fail + return (cm_panic(STAT_FAILED_GET_PLANNER_BUFFER, "mp_dwell()")); // not ever supposed to fail } - bf->bf_func = _exec_dwell; // register callback to dwell start - bf->block_time = seconds; // in seconds, not minutes + bf->bf_func = _exec_dwell; // register callback to dwell start + bf->block_time = seconds; // in seconds, not minutes bf->block_state = BLOCK_INITIAL_ACTION; - mp_commit_write_buffer(BLOCK_TYPE_DWELL); // must be final operation before exit + mp_commit_write_buffer(BLOCK_TYPE_DWELL); // must be final operation before exit return (STAT_OK); } -static stat_t _exec_dwell(mpBuf_t *bf) -{ - st_prep_dwell(bf->block_time * 1000.0);// convert seconds to ms +static stat_t _exec_dwell(mpBuf_t *bf) { + st_prep_dwell(bf->block_time * 1000.0); // convert seconds to ms if (mp_free_run_buffer()) { - cm_cycle_end(); // free buffer & perform cycle_end if planner is empty + cm_cycle_end(); // free buffer & perform cycle_end if planner is empty } return (STAT_OK); } @@ -522,8 +502,7 @@ static stat_t _exec_dwell(mpBuf_t *bf) * This is useful for queuing a dwell after a spindle change. */ -void mp_request_out_of_band_dwell(float seconds) -{ +void mp_request_out_of_band_dwell(float seconds) { if (fp_NOT_ZERO(seconds)) { mr->out_of_band_dwell_flag = true; mr->out_of_band_dwell_seconds = seconds; @@ -544,20 +523,19 @@ uint8_t mp_get_planner_buffers(const mpPlanner_t *_mp) // which planner are you return (_mp->q.buffers_available); } -bool mp_planner_is_full(const mpPlanner_t *_mp) // which planner are you interested in? +bool mp_planner_is_full(const mpPlanner_t *_mp) // which planner are you interested in? { // We also need to ensure we have room for another JSON command return ((_mp->q.buffers_available < PLANNER_BUFFER_HEADROOM) || (jc.available == 0)); } -bool mp_has_runnable_buffer(const mpPlanner_t *_mp) // which planner are you interested in?) +bool mp_has_runnable_buffer(const mpPlanner_t *_mp) // which planner are you interested in?) { - return (_mp->q.r->buffer_state); // anything other than MP_BUFFER_EMPTY returns true + return (_mp->q.r->buffer_state); // anything other than MP_BUFFER_EMPTY returns true } -bool mp_is_phat_city_time() -{ - if(cm->hold_state == FEEDHOLD_HOLD) { +bool mp_is_phat_city_time() { + if (cm->hold_state == FEEDHOLD_HOLD) { return true; } return ((mp->plannable_time <= 0.0) || (PHAT_CITY_TIME < mp->plannable_time)); @@ -598,11 +576,9 @@ bool mp_is_phat_city_time() * - Feedholds require replanning to occur */ -stat_t mp_planner_callback() -{ +stat_t mp_planner_callback() { // Test if the planner has transitioned to an IDLE state if (mp_get_planner_buffers(mp) == mp->q.queue_size) { - // Edgge case: If there's no runnable buffer, FEEDHOLD_SYNC will never exit if (cm->hold_state == FEEDHOLD_SYNC) { cm->hold_state = FEEDHOLD_MOTION_STOPPED; @@ -617,21 +593,21 @@ stat_t mp_planner_callback() bool _timed_out = mp->block_timeout.isPast(); if (_timed_out) { - mp->block_timeout.clear(); // timer is set on commit_write_buffer() + mp->block_timeout.clear(); // timer is set on commit_write_buffer() } - if (!mp->request_planning && !_timed_out) { // Exit if no request or timeout + if (!mp->request_planning && !_timed_out) { // Exit if no request or timeout return (STAT_OK); } // Process a planner request or timeout if (mp->planner_state == PLANNER_IDLE) { - mp->p = mp_get_r(); // initialize planner pointer to run buffer + mp->p = mp_get_r(); // initialize planner pointer to run buffer mp->planner_state = PLANNER_STARTUP; } if (mp->planner_state == PLANNER_STARTUP) { if (!mp_planner_is_full(mp) && !_timed_out) { - return (STAT_OK); // remain in STARTUP + return (STAT_OK); // remain in STARTUP } mp->planner_state = PLANNER_PRIMING; } @@ -646,8 +622,7 @@ stat_t mp_planner_callback() * */ -void mp_replan_queue(mpBuf_t *bf, bool back_too/*=false*/) -{ +void mp_replan_queue(mpBuf_t *bf, bool back_too /*=false*/) { // if (back_too) { // mp->p = bf; // reset the plan-start pointer for back-planning // } @@ -730,22 +705,21 @@ void mp_replan_queue(mpBuf_t *bf, bool back_too/*=false*/) * mp_planner_time_accounting() - gather time in planner */ -void mp_planner_time_accounting() -{ - mpBuf_t *bf = mp_get_r(); // start with run buffer +void mp_planner_time_accounting() { + mpBuf_t *bf = mp_get_r(); // start with run buffer // check the run buffer to see if anything is running. Might not be - if (bf->buffer_state != MP_BUFFER_RUNNING) { // this is not an error condition + if (bf->buffer_state != MP_BUFFER_RUNNING) { // this is not an error condition return; } - mp->plannable_time = 0; //UPDATE_BF_MS(bf); // DIAGNOSTIC + mp->plannable_time = 0; // UPDATE_BF_MS(bf); // DIAGNOSTIC while ((bf = bf->nx) != mp_get_r()) { if (bf->buffer_state == MP_BUFFER_EMPTY || bf->plannable == true) { break; } mp->plannable_time += bf->block_time; } - UPDATE_MP_DIAGNOSTICS // DIAGNOSTIC + UPDATE_MP_DIAGNOSTICS // DIAGNOSTIC } /**** PLANNER BUFFER PRIMITIVES ************************************************************ @@ -823,9 +797,8 @@ void mp_planner_time_accounting() */ // Also clears unlocked, so the buffer cannot be used -static inline void _clear_buffer(mpBuf_t *bf) -{ - bf->reset(); // Call a reset method on the buffer object. +static inline void _clear_buffer(mpBuf_t *bf) { + bf->reset(); // Call a reset method on the buffer object. } /* @@ -834,16 +807,15 @@ mpBuf_t * mp_get_prev_buffer(const mpBuf_t *bf) { return (bf->pv); } mpBuf_t * mp_get_next_buffer(const mpBuf_t *bf) { return (bf->nx); } */ -mpBuf_t * mp_get_w() { return (mp->q.w); } -mpBuf_t * mp_get_r() { return (mp->q.r); } +mpBuf_t *mp_get_w() { return (mp->q.w); } +mpBuf_t *mp_get_r() { return (mp->q.r); } -mpBuf_t * mp_get_write_buffer() // get & clear a buffer +mpBuf_t *mp_get_write_buffer() // get & clear a buffer { - mpPlannerQueue_t *q = &(mp->q); if (q->w->buffer_state == MP_BUFFER_EMPTY) { - _clear_buffer(q->w); // NB: this is redundant if the buffer was cleared mp_free_run_buffer() + _clear_buffer(q->w); // NB: this is redundant if the buffer was cleared mp_free_run_buffer() q->w->buffer_state = MP_BUFFER_INITIALIZING; q->buffers_available--; return (mp_get_w()); @@ -853,7 +825,7 @@ mpBuf_t * mp_get_write_buffer() // get & clear a buffer return (NULL); } -void mp_unget_write_buffer() // mark buffer as empty and adjust free buffer count +void mp_unget_write_buffer() // mark buffer as empty and adjust free buffer count { mpPlannerQueue_t *q = &(mp->q); @@ -864,12 +836,11 @@ void mp_unget_write_buffer() // mark buffer as empty and adjust free buff } /*** WARNING *** -* The function calling mp_commit_write_buffer() must NOT use the write buffer once it has -* been committed. Interrupts may use the buffer immediately, invalidating its contents. -*/ + * The function calling mp_commit_write_buffer() must NOT use the write buffer once it has + * been committed. Interrupts may use the buffer immediately, invalidating its contents. + */ -void mp_commit_write_buffer(const blockType block_type) -{ +void mp_commit_write_buffer(const blockType block_type) { mpPlannerQueue_t *q = &(mp->q); q->w->block_type = block_type; @@ -879,23 +850,23 @@ void mp_commit_write_buffer(const blockType block_type) if ((mp->planner_state > PLANNER_STARTUP) && (cm->hold_state == FEEDHOLD_OFF)) { // NB: BEWARE! the requested exec may result in the planner buffer being // processed IMMEDIATELY and then freed - invalidating the contents - st_request_forward_plan(); // request an exec if the runtime is not busy + st_request_forward_plan(); // request an exec if the runtime is not busy } } - q->w->plannable = true; // enable block for planning + q->w->plannable = true; // enable block for planning mp->request_planning = true; - q->w = q->w->nx; // advance write buffer pointer - mp->block_timeout.set(BLOCK_TIMEOUT_MS);// reset the block timer - qr_request_queue_report(+1); // request QR and add to "added buffers" count + q->w = q->w->nx; // advance write buffer pointer + mp->block_timeout.set(BLOCK_TIMEOUT_MS); // reset the block timer + qr_request_queue_report(+1); // request QR and add to "added buffers" count } -// Note: mp_get_run_buffer() is only called by mp_exec_move(), which is inside an interrupt +// Note: mp_get_run_buffer() is called by mp_exec_move(), which is inside an interrupt // EMPTY and INITALIZING are the two cases where nothing is returned. This is not an error // Otherwise return the buffer. Let mp_exec_move() manage the state machine to sort out: // (1) is the the first time the run buffer has been retrieved? // (2) is the buffer in error - i.e. not yet ready for running? -mpBuf_t * mp_get_run_buffer() -{ +// mp_get_run_buffer() is now also called by mp_forward_plan(), and a couple of calls in feedhold. +mpBuf_t *mp_get_run_buffer() { mpBuf_t *r = mp->q.r; if (r->buffer_state == MP_BUFFER_EMPTY || r->buffer_state == MP_BUFFER_INITIALIZING) { @@ -906,18 +877,19 @@ mpBuf_t * mp_get_run_buffer() // Note: mp_free_run_buffer() is only called from mp_exec_XXX, which are within an interrupt // Clearing and advancing must be done atomically as other interrupts may be using the run buffer -bool mp_free_run_buffer() // EMPTY current run buffer & advance to the next +bool mp_free_run_buffer() // EMPTY current run buffer & advance to the next { mpPlannerQueue_t *q = &(mp->q); - mpBuf_t *r_now = q->r; // save this pointer is to avoid a race condition when clearing the buffer + mpBuf_t *r_now = q->r; // save this pointer is to avoid a race condition when clearing the buffer - _audit_buffers(); // DIAGNOSTIC audit for buffer chain integrity (only runs in DEBUG mode) - q->r = q->r->nx; // advance to next run buffer first... - _clear_buffer(r_now); // ... then clear out the old buffer (& set MP_BUFFER_EMPTY) -// r_now->buffer_state = MP_BUFFER_EMPTY; //... then mark the buffer empty while preserving content for debug inspection + _audit_buffers(); // DIAGNOSTIC audit for buffer chain integrity (only runs in DEBUG mode) + q->r = q->r->nx; // advance to next run buffer first... + _clear_buffer(r_now); // ... then clear out the old buffer (& set MP_BUFFER_EMPTY) + // r_now->buffer_state = MP_BUFFER_EMPTY; //... then mark the buffer empty while preserving content for debug + // inspection q->buffers_available++; - qr_request_queue_report(-1); // request a QR and add to the "removed buffers" count - return (q->w == q->r); // return true if the queue emptied + qr_request_queue_report(-1); // request a QR and add to the "removed buffers" count + return (q->w == q->r); // return true if the queue emptied } /* UNUSED FUNCTIONS - left in for completeness and for reference @@ -928,7 +900,6 @@ void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp) } */ - /************************************************************************************ *** DIAGNOSTICS ******************************************************************** ************************************************************************************/ @@ -944,38 +915,40 @@ void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp) //#define __AUDIT_BUFFERS #ifdef __DUMP_PLANNER -void mp_dump_planner(mpBuf_t *bf_start) // starting at bf +void mp_dump_planner(mpBuf_t *bf_start) // starting at bf { mpBuf_t *bf = bf_start; - printf ("Buf, Line, State, Hint, Planbl, Iter, Tmove, Tplan, Ovr, Thr, Len, Ve, Vc, Vx, Vemax, Vcset, Vcmax, Vxmax, Vjt\n"); + printf( + "Buf, Line, State, Hint, Planbl, Iter, Tmove, Tplan, Ovr, Thr, Len, Ve, Vc, Vx, Vemax, Vcset, Vcmax, Vxmax, " + "Vjt\n"); do { - printf ("%d,", (int)bf->buffer_number); - printf ("%d,", (int)bf->linenum); - printf ("%d,", (int)bf->buffer_state); - printf ("%d,", (int)bf->hint); - printf ("%d,", (int)bf->plannable); - printf ("%d,", (int)bf->iterations); + printf("%d,", (int)bf->buffer_number); + printf("%d,", (int)bf->linenum); + printf("%d,", (int)bf->buffer_state); + printf("%d,", (int)bf->hint); + printf("%d,", (int)bf->plannable); + printf("%d,", (int)bf->iterations); - printf ("%1.2f,", bf->block_time_ms); - printf ("%1.2f,", bf->plannable_time_ms); - printf ("%1.3f,", bf->override_factor); - printf ("%1.3f,", bf->throttle); - printf ("%1.5f,", bf->length); - printf ("%1.0f,", bf->pv->exit_velocity); - printf ("%1.0f,", bf->cruise_velocity); - printf ("%1.0f,", bf->exit_velocity); - printf ("%1.0f,", bf->pv->exit_vmax); - printf ("%1.0f,", bf->cruise_vset); - printf ("%1.0f,", bf->cruise_vmax); - printf ("%1.0f,", bf->exit_vmax); - printf ("%1.0f\n", bf->junction_vmax); + printf("%1.2f,", bf->block_time_ms); + printf("%1.2f,", bf->plannable_time_ms); + printf("%1.3f,", bf->override_factor); + printf("%1.3f,", bf->throttle); + printf("%1.5f,", bf->length); + printf("%1.0f,", bf->pv->exit_velocity); + printf("%1.0f,", bf->cruise_velocity); + printf("%1.0f,", bf->exit_velocity); + printf("%1.0f,", bf->pv->exit_vmax); + printf("%1.0f,", bf->cruise_vset); + printf("%1.0f,", bf->cruise_vmax); + printf("%1.0f,", bf->exit_vmax); + printf("%1.0f\n", bf->junction_vmax); bf = bf->nx; } while (bf != bf_start); } -#endif // __DUMP_PLANNER +#endif // __DUMP_PLANNER //#if 0 && defined(DEBUG) //#warning DEBUG TRAPS ENABLED @@ -987,34 +960,30 @@ void mp_dump_planner(mpBuf_t *bf_start) // starting at bf #ifndef __AUDIT_BUFFERS -static void _audit_buffers() -{ +static void _audit_buffers() { // empty stub } #else -static void _planner_report(const char *msg) -{ - #ifdef __PLANNER_REPORT_ENABLED +static void _planner_report(const char *msg) { +#ifdef __PLANNER_REPORT_ENABLED rpt_exception(STAT_PLANNER_ASSERTION_FAILURE, msg); - for (uint8_t i=0; ipv->nx != mb.r || mb.r->nx->pv != mb.r){ + if (mb.r->pv->nx != mb.r || mb.r->nx->pv != mb.r) { _planner_report("buffer audit2"); debug_trap("buffer audit2"); } @@ -1034,7 +1003,7 @@ static void _audit_buffers() mpBuf_t *bf = mb.r->nx; while (bf != mb.r) { // Check that the next from the previous is correct. - if (bf->pv->nx != bf || bf->nx->pv != bf){ + if (bf->pv->nx != bf || bf->nx->pv != bf) { _planner_report("buffer audit3"); debug_trap("buffer audit3"); } @@ -1047,12 +1016,9 @@ static void _audit_buffers() // - no more // After RUNNING, we can PREPPED, PLANNED, INITED, IN_PROCESS, or EMPTY - if (bf->pv->buffer_state == MP_BUFFER_RUNNING && - bf->buffer_state != MP_BUFFER_PREPPED && - bf->buffer_state != MP_BUFFER_PLANNED && - bf->buffer_state != MP_BUFFER_INITIALIZING && - bf->buffer_state != MP_BUFFER_IN_PROCESS && - bf->buffer_state != MP_BUFFER_EMPTY) { + if (bf->pv->buffer_state == MP_BUFFER_RUNNING && bf->buffer_state != MP_BUFFER_PREPPED && + bf->buffer_state != MP_BUFFER_PLANNED && bf->buffer_state != MP_BUFFER_INITIALIZING && + bf->buffer_state != MP_BUFFER_IN_PROCESS && bf->buffer_state != MP_BUFFER_EMPTY) { // Exception: MP_BUFFER_INITIALIZING and MP_BUFFER_IN_PROCESS are allowed, but we may want to watch for it: if ((bf->buffer_state == MP_BUFFER_INITIALIZING) || (bf->buffer_state == MP_BUFFER_IN_PROCESS)) { __NOP(); @@ -1063,20 +1029,16 @@ static void _audit_buffers() } // After PLANNED, we can see PREPPED, INITED, IN_PROCESS, or EMPTY - if (bf->pv->buffer_state == MP_BUFFER_PLANNED && - bf->buffer_state != MP_BUFFER_PREPPED && - bf->buffer_state != MP_BUFFER_INITIALIZING && - bf->buffer_state != MP_BUFFER_IN_PROCESS && + if (bf->pv->buffer_state == MP_BUFFER_PLANNED && bf->buffer_state != MP_BUFFER_PREPPED && + bf->buffer_state != MP_BUFFER_INITIALIZING && bf->buffer_state != MP_BUFFER_IN_PROCESS && bf->buffer_state != MP_BUFFER_EMPTY) { _planner_report("buffer audit5"); debug_trap("buffer audit5"); } // After PREPPED, we can see PREPPED, INITED, IN_PROCESS, or EMPTY - if (bf->pv->buffer_state == MP_BUFFER_PREPPED && - bf->buffer_state != MP_BUFFER_PREPPED && - bf->buffer_state != MP_BUFFER_INITIALIZING && - bf->buffer_state != MP_BUFFER_IN_PROCESS && + if (bf->pv->buffer_state == MP_BUFFER_PREPPED && bf->buffer_state != MP_BUFFER_PREPPED && + bf->buffer_state != MP_BUFFER_INITIALIZING && bf->buffer_state != MP_BUFFER_IN_PROCESS && bf->buffer_state != MP_BUFFER_EMPTY) { _planner_report("buffer audit6"); debug_trap("buffer audit6"); @@ -1093,7 +1055,7 @@ static void _audit_buffers() __enable_irq(); } -#endif // __AUDIT_BUFFERS +#endif // __AUDIT_BUFFERS /**************************** * END OF PLANNER FUNCTIONS * diff --git a/g2core/settings/settings_cheapo_laser.h b/g2core/settings/settings_cheapo_laser.h index c25cbe01..6810efe0 100644 --- a/g2core/settings/settings_cheapo_laser.h +++ b/g2core/settings/settings_cheapo_laser.h @@ -47,7 +47,7 @@ #define SPINDLE_DIR_POLARITY 0 // 0=clockwise is low, 1=clockwise is high #define SPINDLE_PAUSE_ON_HOLD true #define SPINDLE_SPINUP_DELAY 1.0 -#define SPINDLE_PWM_NUMBER 6 +#define SPINDLE_PWM_NUMBER 3 #define SECONDARY_PWM_OUTPUT_NUMBER 0 // disabled // #define LASER_FIRE_PIN_NUMBER Motate::kOutput3_PinNumber // note this is a MOTATE pin number, NOT a GPIO pin number diff --git a/g2core/settings/settings_default.h b/g2core/settings/settings_default.h index 013a3588..564e3979 100644 --- a/g2core/settings/settings_default.h +++ b/g2core/settings/settings_default.h @@ -86,7 +86,7 @@ #endif #ifndef SPINDLE_ENABLE_POLARITY -#define SPINDLE_ENABLE_POLARITY SPINDLE_ACTIVE_HIGH // {spep: 0=active low, 1=active high +#define SPINDLE_ENABLE_POLARITY 1 // 0=active low, 1=active high #endif #ifndef SPINDLE_DIR_POLARITY diff --git a/g2core/settings/settings_othermill.h b/g2core/settings/settings_othermill.h index 5032d270..df2e7bc8 100644 --- a/g2core/settings/settings_othermill.h +++ b/g2core/settings/settings_othermill.h @@ -35,6 +35,20 @@ //**** GLOBAL / GENERAL SETTINGS ****************************************************** +#define MIST_ENABLE_OUTPUT_NUMBER 0 +#define FLOOD_ENABLE_OUTPUT_NUMBER 0 + +// #define SPINDLE_ENABLE_OUTPUT_NUMBER 4 +// #define SPINDLE_DIRECTION_OUTPUT_NUMBER 5 +// #define SPINDLE_PWM_NUMBER 6 + +#define SPINDLE_ENABLE_OUTPUT_NUMBER 1 +#define SPINDLE_DIRECTION_OUTPUT_NUMBER 2 +#define SPINDLE_PWM_NUMBER 3 + +// #define FEEDHOLD_Z_LIFT 3 // mm to lift Z on feedhold + + #define JUNCTION_INTEGRATION_TIME 0.1 // cornering - between 0.10 and 2.00 (higher is faster) #define CHORDAL_TOLERANCE 0.01 // chordal accuracy for arc drawing (in mm) @@ -46,7 +60,7 @@ #define SPINDLE_DIR_POLARITY 0 // 0=clockwise is low, 1=clockwise is high #define SPINDLE_PAUSE_ON_HOLD true #define SPINDLE_SPINUP_DELAY 0.1 // after unpausing and turning the spindle on, dwell for 1.5s -#define SPINDLE_SPEED_CHANGE_PER_MS 7.0 +#define SPINDLE_SPEED_CHANGE_PER_MS 7.0 // external non-speed-controlled spindle, but we can use this as a built-in delay #define ESC_BOOT_TIME 5000 // how long the ESC takes to boot, in milliseconds #define ESC_LOCKOUT_TIME 900 // how long the interlock needs to be engaged before killing power... actually 1s, but be conservative diff --git a/g2core/settings/settings_smw3d_r7.h b/g2core/settings/settings_smw3d_r7.h index 86d1a8e4..dfd6c2ec 100644 --- a/g2core/settings/settings_smw3d_r7.h +++ b/g2core/settings/settings_smw3d_r7.h @@ -36,141 +36,143 @@ // Machine configuration settings -#define JUNCTION_INTEGRATION_TIME 0.75 // cornering - between 0.10 and 2.00 (higher is faster) -#define CHORDAL_TOLERANCE 0.01 // chordal tolerance for arcs (in mm) +#define JUNCTION_INTEGRATION_TIME 0.75 // cornering - between 0.10 and 2.00 (higher is faster) +#define CHORDAL_TOLERANCE 0.01 // chordal tolerance for arcs (in mm) -#define SOFT_LIMIT_ENABLE 0 // 0=off, 1=on -#define HARD_LIMIT_ENABLE 0 // 0=off, 1=on -#define SAFETY_INTERLOCK_ENABLE 1 // 0=off, 1=on +#define SOFT_LIMIT_ENABLE 0 // 0=off, 1=on +#define HARD_LIMIT_ENABLE 0 // 0=off, 1=on +#define SAFETY_INTERLOCK_ENABLE 1 // 0=off, 1=on #define SPINDLE_ENABLE_OUTPUT_NUMBER 4 -#define SPINDLE_ENABLE_POLARITY 0 // 1=active low, 0=active high +#define SPINDLE_ENABLE_POLARITY 0 // 1=active low, 0=active high #define SPINDLE_DIRECTION_OUTPUT_NUMBER 5 -#define SPINDLE_DIR_POLARITY 1 // 0=clockwise is low, 1=clockwise is high -#define SPINDLE_PAUSE_ON_HOLD true -#define SPINDLE_SPINUP_DELAY 10.0 -#define SPINDLE_PWM_NUMBER 6 -#define SECONDARY_PWM_OUTPUT_NUMBER 0 // disabled +#define SPINDLE_DIR_POLARITY 0 // 0=clockwise is low, 1=clockwise is high +#define SPINDLE_PAUSE_ON_HOLD true +#define SPINDLE_SPINUP_DELAY 1.0 +#define SPINDLE_PWM_NUMBER 6 +#define SECONDARY_PWM_OUTPUT_NUMBER 0 // disabled -#define COOLANT_MIST_POLARITY 0 // 1=active low, 0=active high -#define COOLANT_FLOOD_POLARITY 0 // 1=active low, 0=active high -#define COOLANT_PAUSE_ON_HOLD false -#define FLOOD_ENABLE_OUTPUT_NUMBER 9 // disabled -#define MIST_ENABLE_OUTPUT_NUMBER 7 // disabled +#define COOLANT_MIST_POLARITY 0 // 1=active low, 0=active high +#define COOLANT_FLOOD_POLARITY 0 // 1=active low, 0=active high +#define COOLANT_PAUSE_ON_HOLD false +#define FLOOD_ENABLE_OUTPUT_NUMBER 9 // disabled +#define MIST_ENABLE_OUTPUT_NUMBER 7 // disabled -#define FEEDHOLD_Z_LIFT -1 // mm to lift Z on feedhold, or -1 to go to Z-max +#define FEEDHOLD_Z_LIFT -1 // mm to lift Z on feedhold, or -1 to go to Z-max // Communications and reporting settings -#define USB_SERIAL_PORTS_EXPOSED 1 // 1=single endpoint usb, 2=dual endpoint usb -#define COMM_MODE JSON_MODE // one of: TEXT_MODE, JSON_MODE -#define XIO_ENABLE_FLOW_CONTROL FLOW_CONTROL_RTS // FLOW_CONTROL_OFF, FLOW_CONTROL_RTS +#define USB_SERIAL_PORTS_EXPOSED 1 // 1=single endpoint usb, 2=dual endpoint usb +#define COMM_MODE JSON_MODE // one of: TEXT_MODE, JSON_MODE +#define XIO_ENABLE_FLOW_CONTROL FLOW_CONTROL_RTS // FLOW_CONTROL_OFF, FLOW_CONTROL_RTS -#define TEXT_VERBOSITY TV_VERBOSE // one of: TV_SILENT, TV_VERBOSE -#define JSON_VERBOSITY JV_MESSAGES // one of: JV_SILENT, JV_FOOTER, JV_CONFIGS, JV_MESSAGES, JV_LINENUM, JV_VERBOSE -#define QUEUE_REPORT_VERBOSITY QR_OFF // one of: QR_OFF, QR_SINGLE, QR_TRIPLE +#define TEXT_VERBOSITY TV_VERBOSE // one of: TV_SILENT, TV_VERBOSE +#define JSON_VERBOSITY JV_MESSAGES // one of: JV_SILENT, JV_FOOTER, JV_CONFIGS, JV_MESSAGES, JV_LINENUM, JV_VERBOSE +#define QUEUE_REPORT_VERBOSITY QR_OFF // one of: QR_OFF, QR_SINGLE, QR_TRIPLE -#define STATUS_REPORT_VERBOSITY SR_FILTERED // one of: SR_OFF, SR_FILTERED, SR_VERBOSE +#define STATUS_REPORT_VERBOSITY SR_FILTERED // one of: SR_OFF, SR_FILTERED, SR_VERBOSE -#define STATUS_REPORT_MIN_MS 100 // milliseconds - enforces a viable minimum -#define STATUS_REPORT_INTERVAL_MS 250 // milliseconds - set $SV=0 to disable +#define STATUS_REPORT_MIN_MS 100 // milliseconds - enforces a viable minimum +#define STATUS_REPORT_INTERVAL_MS 250 // milliseconds - set $SV=0 to disable -//#define STATUS_REPORT_DEFAULTS "line","posx","posy","posz","posa","feed","vel","unit","coor","dist","admo","frmo","momo","stat" -#define STATUS_REPORT_DEFAULTS "line","posx","posy","posz","feed","vel","momo","stat" +// #define STATUS_REPORT_DEFAULTS +// "line","posx","posy","posz","posa","feed","vel","unit","coor","dist","admo","frmo","momo","stat" +#define STATUS_REPORT_DEFAULTS "line", "posx", "posy", "posz", "feed", "vel", "momo", "stat" // Alternate SRs that report in drawable units -//#define STATUS_REPORT_DEFAULTS "line","vel","mpox","mpoy","mpoz","mpoa","coor","ofsa","ofsx","ofsy","ofsz","dist","unit","stat","homz","homy","homx","momo" -//#define STATUS_REPORT_DEFAULTS "_ts1","_cs1","_es1","_xs1","_fe1","line","posx","posy","posz","vel","stat" +// #define STATUS_REPORT_DEFAULTS +// "line","vel","mpox","mpoy","mpoz","mpoa","coor","ofsa","ofsx","ofsy","ofsz","dist","unit","stat","homz","homy","homx","momo" +// #define STATUS_REPORT_DEFAULTS "_ts1","_cs1","_es1","_xs1","_fe1","line","posx","posy","posz","vel","stat" // Gcode startup defaults -#define GCODE_DEFAULT_UNITS MILLIMETERS // MILLIMETERS or INCHES -#define GCODE_DEFAULT_PLANE CANON_PLANE_XY // CANON_PLANE_XY, CANON_PLANE_XZ, or CANON_PLANE_YZ -#define GCODE_DEFAULT_COORD_SYSTEM G54 // G54, G55, G56, G57, G58 or G59 -#define GCODE_DEFAULT_PATH_CONTROL PATH_CONTINUOUS +#define GCODE_DEFAULT_UNITS MILLIMETERS // MILLIMETERS or INCHES +#define GCODE_DEFAULT_PLANE CANON_PLANE_XY // CANON_PLANE_XY, CANON_PLANE_XZ, or CANON_PLANE_YZ +#define GCODE_DEFAULT_COORD_SYSTEM G54 // G54, G55, G56, G57, G58 or G59 +#define GCODE_DEFAULT_PATH_CONTROL PATH_CONTINUOUS #define GCODE_DEFAULT_DISTANCE_MODE ABSOLUTE_DISTANCE_MODE // *** motor settings ************************************************************************************ -#define MOTOR_POWER_MODE MOTOR_POWERED_IN_CYCLE // default motor power mode (see cmMotorPowerMode in stepper.h) -#define MOTOR_POWER_TIMEOUT 2.00 // motor power timeout in seconds +#define MOTOR_POWER_MODE MOTOR_POWERED_IN_CYCLE // default motor power mode (see cmMotorPowerMode in stepper.h) +#define MOTOR_POWER_TIMEOUT 2.00 // motor power timeout in seconds -#define M1_MOTOR_MAP AXIS_X // 1ma -#define M1_STEP_ANGLE 1.8 // 1sa -#define M1_TRAVEL_PER_REV 8.0934060625 // 1tr -#define M1_MICROSTEPS 64 // 1mi 1,2,4,8,16,32 -#define M1_POLARITY 1 // 1po 0=normal, 1=reversed -#define M1_POWER_MODE MOTOR_ALWAYS_POWERED // 1pm TRUE=low power idle enabled -#define M1_POWER_LEVEL 0.500 +#define M1_MOTOR_MAP AXIS_X // 1ma +#define M1_STEP_ANGLE 1.8 // 1sa +#define M1_TRAVEL_PER_REV 8.0934060625 // 1tr +#define M1_MICROSTEPS 64 // 1mi 1,2,4,8,16,32 +#define M1_POLARITY 1 // 1po 0=normal, 1=reversed +#define M1_POWER_MODE MOTOR_ALWAYS_POWERED // 1pm TRUE=low power idle enabled +#define M1_POWER_LEVEL 0.500 -#define M2_MOTOR_MAP AXIS_Y -#define M2_STEP_ANGLE 1.8 -#define M2_TRAVEL_PER_REV 8.0934060625 -#define M2_MICROSTEPS 64 -#define M2_POLARITY 0 -#define M2_POWER_MODE MOTOR_ALWAYS_POWERED -#define M2_POWER_LEVEL 0.500 +#define M2_MOTOR_MAP AXIS_Y +#define M2_STEP_ANGLE 1.8 +#define M2_TRAVEL_PER_REV 8.0934060625 +#define M2_MICROSTEPS 64 +#define M2_POLARITY 0 +#define M2_POWER_MODE MOTOR_ALWAYS_POWERED +#define M2_POWER_LEVEL 0.500 -#define M3_MOTOR_MAP AXIS_Y -#define M3_STEP_ANGLE 1.8 -#define M3_TRAVEL_PER_REV 8.0934060625 -#define M3_MICROSTEPS 64 -#define M3_POLARITY 0 -#define M3_POWER_MODE MOTOR_ALWAYS_POWERED -#define M3_POWER_LEVEL 0.500 +#define M3_MOTOR_MAP AXIS_Y +#define M3_STEP_ANGLE 1.8 +#define M3_TRAVEL_PER_REV 8.0934060625 +#define M3_MICROSTEPS 64 +#define M3_POLARITY 0 +#define M3_POWER_MODE MOTOR_ALWAYS_POWERED +#define M3_POWER_LEVEL 0.500 -#define M4_MOTOR_MAP AXIS_Z -#define M4_STEP_ANGLE 1.8 -#define M4_TRAVEL_PER_REV 8.0934060625 -#define M4_MICROSTEPS 64 -#define M4_POLARITY 1 -#define M4_POWER_MODE MOTOR_ALWAYS_POWERED -#define M4_POWER_LEVEL 0.750 +#define M4_MOTOR_MAP AXIS_Z +#define M4_STEP_ANGLE 1.8 +#define M4_TRAVEL_PER_REV 8.0934060625 +#define M4_MICROSTEPS 64 +#define M4_POLARITY 1 +#define M4_POWER_MODE MOTOR_ALWAYS_POWERED +#define M4_POWER_LEVEL 0.750 // *** axis settings ********************************************************************************** -#define JERK_MAX 5000 +#define JERK_MAX 5000 -#define X_AXIS_MODE AXIS_STANDARD // xam see canonical_machine.h cmAxisMode for valid values -#define X_VELOCITY_MAX 2000 // xvm G0 max velocity in mm/min -#define X_FEEDRATE_MAX X_VELOCITY_MAX // xfr G1 max feed rate in mm/min -#define X_TRAVEL_MIN 0 // xtn minimum travel for soft limits -#define X_TRAVEL_MAX 824 // xtm travel between switches or crashes -#define X_JERK_MAX 3500 // xjm jerk * 1,000,000 -#define X_JERK_HIGH_SPEED 20000 // xjh -#define X_HOMING_INPUT 1 // xhi input used for homing or 0 to disable -#define X_HOMING_DIRECTION 1 // xhd 0=search moves negative, 1= search moves positive -#define X_SEARCH_VELOCITY 1000 // xsv minus means move to minimum switch -#define X_LATCH_VELOCITY 100 // xlv mm/min -#define X_LATCH_BACKOFF 4 // xlb mm -#define X_ZERO_BACKOFF 2 // xzb mm +#define X_AXIS_MODE AXIS_STANDARD // xam see canonical_machine.h cmAxisMode for valid values +#define X_VELOCITY_MAX 2000 // xvm G0 max velocity in mm/min +#define X_FEEDRATE_MAX X_VELOCITY_MAX // xfr G1 max feed rate in mm/min +#define X_TRAVEL_MIN 0 // xtn minimum travel for soft limits +#define X_TRAVEL_MAX 824 // xtm travel between switches or crashes +#define X_JERK_MAX 3500 // xjm jerk * 1,000,000 +#define X_JERK_HIGH_SPEED 20000 // xjh +#define X_HOMING_INPUT 1 // xhi input used for homing or 0 to disable +#define X_HOMING_DIRECTION 1 // xhd 0=search moves negative, 1= search moves positive +#define X_SEARCH_VELOCITY 1000 // xsv minus means move to minimum switch +#define X_LATCH_VELOCITY 100 // xlv mm/min +#define X_LATCH_BACKOFF 4 // xlb mm +#define X_ZERO_BACKOFF 2 // xzb mm -#define Y_AXIS_MODE AXIS_STANDARD -#define Y_VELOCITY_MAX 4000 -#define Y_FEEDRATE_MAX Y_VELOCITY_MAX -#define Y_TRAVEL_MIN 0 -#define Y_TRAVEL_MAX 781 -#define Y_JERK_MAX 3500 -#define Y_JERK_HIGH_SPEED 20000 -#define Y_HOMING_INPUT 2 -#define Y_HOMING_DIRECTION 1 -#define Y_SEARCH_VELOCITY 1000 -#define Y_LATCH_VELOCITY 100 -#define Y_LATCH_BACKOFF 4 -#define Y_ZERO_BACKOFF 2 +#define Y_AXIS_MODE AXIS_STANDARD +#define Y_VELOCITY_MAX 4000 +#define Y_FEEDRATE_MAX Y_VELOCITY_MAX +#define Y_TRAVEL_MIN 0 +#define Y_TRAVEL_MAX 781 +#define Y_JERK_MAX 3500 +#define Y_JERK_HIGH_SPEED 20000 +#define Y_HOMING_INPUT 2 +#define Y_HOMING_DIRECTION 1 +#define Y_SEARCH_VELOCITY 1000 +#define Y_LATCH_VELOCITY 100 +#define Y_LATCH_BACKOFF 4 +#define Y_ZERO_BACKOFF 2 -#define Z_AXIS_MODE AXIS_STANDARD -#define Z_VELOCITY_MAX 1200 -#define Z_FEEDRATE_MAX Z_VELOCITY_MAX -#define Z_TRAVEL_MAX 75 -#define Z_TRAVEL_MIN -15 -#define Z_JERK_MAX 500 -#define Z_JERK_HIGH_SPEED 1000 -#define Z_HOMING_INPUT 3 -#define Z_HOMING_DIRECTION 1 -#define Z_SEARCH_VELOCITY (Z_VELOCITY_MAX * 0.66666) -#define Z_LATCH_VELOCITY 25 -#define Z_LATCH_BACKOFF 4 -#define Z_ZERO_BACKOFF 2 +#define Z_AXIS_MODE AXIS_STANDARD +#define Z_VELOCITY_MAX 1200 +#define Z_FEEDRATE_MAX Z_VELOCITY_MAX +#define Z_TRAVEL_MAX 75 +#define Z_TRAVEL_MIN -15 +#define Z_JERK_MAX 500 +#define Z_JERK_HIGH_SPEED 1000 +#define Z_HOMING_INPUT 3 +#define Z_HOMING_DIRECTION 1 +#define Z_SEARCH_VELOCITY (Z_VELOCITY_MAX * 0.66666) +#define Z_LATCH_VELOCITY 25 +#define Z_LATCH_BACKOFF 4 +#define Z_ZERO_BACKOFF 2 //*** Input / output settings *** /* @@ -194,38 +196,37 @@ #define PROBING_INPUT 5 -#define DI1_POLARITY IO_ACTIVE_HIGH +#define DI1_POLARITY IO_ACTIVE_HIGH // #define DI1_ACTION INPUT_ACTION_LIMIT -#define DI1_ACTION INPUT_ACTION_NONE +#define DI1_ACTION INPUT_ACTION_NONE -#define DI2_POLARITY IO_ACTIVE_HIGH +#define DI2_POLARITY IO_ACTIVE_HIGH // #define DI2_ACTION INPUT_ACTION_LIMIT -#define DI2_ACTION INPUT_ACTION_NONE +#define DI2_ACTION INPUT_ACTION_NONE -#define DI3_POLARITY IO_ACTIVE_HIGH -//#define DI3_ACTION INPUT_ACTION_LIMIT -#define DI3_ACTION INPUT_ACTION_NONE +#define DI3_POLARITY IO_ACTIVE_HIGH +// #define DI3_ACTION INPUT_ACTION_LIMIT +#define DI3_ACTION INPUT_ACTION_NONE -#define DI4_POLARITY IO_ACTIVE_HIGH -//#define DI4_ACTION INPUT_ACTION_LIMIT -#define DI4_ACTION INPUT_ACTION_NONE +#define DI4_POLARITY IO_ACTIVE_HIGH +// #define DI4_ACTION INPUT_ACTION_LIMIT +#define DI4_ACTION INPUT_ACTION_NONE -#define DI5_POLARITY IO_ACTIVE_LOW // Z probe -#define DI5_ACTION INPUT_ACTION_NONE +#define DI5_POLARITY IO_ACTIVE_LOW // Z probe +#define DI5_ACTION INPUT_ACTION_NONE -#define DI6_POLARITY IO_ACTIVE_HIGH -//#define DI6_ACTION INPUT_ACTION_LIMIT -#define DI6_ACTION INPUT_ACTION_NONE +#define DI6_POLARITY IO_ACTIVE_HIGH +// #define DI6_ACTION INPUT_ACTION_LIMIT +#define DI6_ACTION INPUT_ACTION_NONE -#define DI7_ENABLED IO_DISABLED -#define DI7_ACTION INPUT_ACTION_NONE +#define DI7_ENABLED IO_DISABLED +#define DI7_ACTION INPUT_ACTION_NONE -#define DI8_ENABLED IO_DISABLED -#define DI8_ACTION INPUT_ACTION_NONE - -#define DI9_ENABLED IO_DISABLED -#define DI9_ACTION INPUT_ACTION_NONE +#define DI8_ENABLED IO_DISABLED +#define DI8_ACTION INPUT_ACTION_NONE +#define DI9_ENABLED IO_DISABLED +#define DI9_ACTION INPUT_ACTION_NONE // *** PWM SPINDLE CONTROL *** @@ -257,7 +258,7 @@ */ #define P1_PWM_FREQUENCY 100000 // in Hz -#define P1_CW_SPEED_LO 1 // in RPM (arbitrary units) +#define P1_CW_SPEED_LO 1 // in RPM (arbitrary units) #define P1_CW_SPEED_HI 24000 #define P1_CW_PHASE_LO 0.05 // phase [0..1] #define P1_CW_PHASE_HI 1.0 diff --git a/g2core/settings/settings_smw3d_r7_v9k.h b/g2core/settings/settings_smw3d_r7_v9k.h new file mode 100644 index 00000000..d6e062a8 --- /dev/null +++ b/g2core/settings/settings_smw3d_r7_v9k.h @@ -0,0 +1,267 @@ +/* + * settings_smw3d_r7.h - SMW3d r7 machine with VFD + * This file is part of the g2core project + * + * Copyright (c) 2010 - 2016 Alden S. Hart, Jr. + * + * This file ("the software") is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2 as published by the + * Free Software Foundation. You should have received a copy of the GNU General Public + * License, version 2 along with the software. If not, see . + * + * As a special exception, you may use this file as part of a software library without + * restriction. Specifically, if other files instantiate templates or use macros or + * inline functions from this file, or you compile this file and link it with other + * files to produce an executable, this file does not by itself cause the resulting + * executable to be covered by the GNU General Public License. This exception does not + * however invalidate any other reasons why the executable file might be covered by the + * GNU General Public License. + * + * THE SOFTWARE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY + * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT + * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/***********************************************************************/ +/**** Shapeoko2 500mm profile ******************************************/ +/***********************************************************************/ + +// ***> NOTE: The init message must be a single line with no CRs or LFs +#define INIT_MESSAGE "Initializing configs to SMW3d r7" + +//**** GLOBAL / GENERAL SETTINGS ****************************************************** + +// Machine configuration settings + +#define JUNCTION_INTEGRATION_TIME 0.75 // cornering - between 0.10 and 2.00 (higher is faster) +#define CHORDAL_TOLERANCE 0.01 // chordal tolerance for arcs (in mm) + +#define SOFT_LIMIT_ENABLE 0 // 0=off, 1=on +#define HARD_LIMIT_ENABLE 0 // 0=off, 1=on +#define SAFETY_INTERLOCK_ENABLE 1 // 0=off, 1=on + +#define SPINDLE_ENABLE_OUTPUT_NUMBER 1 +#define SPINDLE_ENABLE_POLARITY 1 // 0=active low, 1=active high +#define SPINDLE_DIRECTION_OUTPUT_NUMBER 2 +#define SPINDLE_DIR_POLARITY 0 // 0=clockwise is low, 1=clockwise is high +#define SPINDLE_PAUSE_ON_HOLD true +#define SPINDLE_SPINUP_DELAY 1.0 +#define SPINDLE_PWM_NUMBER 3 +#define SECONDARY_PWM_OUTPUT_NUMBER 0 // disabled + +#define COOLANT_MIST_POLARITY 1 // 0=active low, 1=active high +#define COOLANT_FLOOD_POLARITY 1 // 0=active low, 1=active high +#define COOLANT_PAUSE_ON_HOLD false +#define FLOOD_ENABLE_OUTPUT_NUMBER 0 // disabled +#define MIST_ENABLE_OUTPUT_NUMBER 4 // "coolant enable" + +// Communications and reporting settings + +#define USB_SERIAL_PORTS_EXPOSED 1 // 1=single endpoint usb, 2=dual endpoint usb +#define COMM_MODE JSON_MODE // one of: TEXT_MODE, JSON_MODE +#define XIO_ENABLE_FLOW_CONTROL FLOW_CONTROL_RTS // FLOW_CONTROL_OFF, FLOW_CONTROL_RTS + +#define TEXT_VERBOSITY TV_VERBOSE // one of: TV_SILENT, TV_VERBOSE +#define JSON_VERBOSITY JV_MESSAGES // one of: JV_SILENT, JV_FOOTER, JV_CONFIGS, JV_MESSAGES, JV_LINENUM, JV_VERBOSE +#define QUEUE_REPORT_VERBOSITY QR_OFF // one of: QR_OFF, QR_SINGLE, QR_TRIPLE + +#define STATUS_REPORT_VERBOSITY SR_FILTERED // one of: SR_OFF, SR_FILTERED, SR_VERBOSE + +#define STATUS_REPORT_MIN_MS 100 // milliseconds - enforces a viable minimum +#define STATUS_REPORT_INTERVAL_MS 250 // milliseconds - set $SV=0 to disable + +//#define STATUS_REPORT_DEFAULTS "line","posx","posy","posz","posa","feed","vel","unit","coor","dist","admo","frmo","momo","stat" +#define STATUS_REPORT_DEFAULTS "line","posx","posy","posz","feed","vel","momo","stat" + +// Alternate SRs that report in drawable units +//#define STATUS_REPORT_DEFAULTS "line","vel","mpox","mpoy","mpoz","mpoa","coor","ofsa","ofsx","ofsy","ofsz","dist","unit","stat","homz","homy","homx","momo" +//#define STATUS_REPORT_DEFAULTS "_ts1","_cs1","_es1","_xs1","_fe1","line","posx","posy","posz","vel","stat" + +// Gcode startup defaults +#define GCODE_DEFAULT_UNITS MILLIMETERS // MILLIMETERS or INCHES +#define GCODE_DEFAULT_PLANE CANON_PLANE_XY // CANON_PLANE_XY, CANON_PLANE_XZ, or CANON_PLANE_YZ +#define GCODE_DEFAULT_COORD_SYSTEM G54 // G54, G55, G56, G57, G58 or G59 +#define GCODE_DEFAULT_PATH_CONTROL PATH_CONTINUOUS +#define GCODE_DEFAULT_DISTANCE_MODE ABSOLUTE_DISTANCE_MODE + +// *** motor settings ************************************************************************************ + +#define MOTOR_POWER_MODE MOTOR_POWERED_IN_CYCLE // default motor power mode (see cmMotorPowerMode in stepper.h) +#define MOTOR_POWER_TIMEOUT 2.00 // motor power timeout in seconds + +#define M1_MOTOR_MAP AXIS_X // 1ma +#define M1_STEP_ANGLE 1.8 // 1sa +#define M1_TRAVEL_PER_REV 8.0934060625 // 1tr +#define M1_MICROSTEPS 64 // 1mi 1,2,4,8,16,32 +#define M1_POLARITY 1 // 1po 0=normal, 1=reversed +#define M1_POWER_MODE MOTOR_ALWAYS_POWERED // 1pm TRUE=low power idle enabled +#define M1_POWER_LEVEL 0.500 + +#define M2_MOTOR_MAP AXIS_Y +#define M2_STEP_ANGLE 1.8 +#define M2_TRAVEL_PER_REV 8.0934060625 +#define M2_MICROSTEPS 64 +#define M2_POLARITY 0 +#define M2_POWER_MODE MOTOR_ALWAYS_POWERED +#define M2_POWER_LEVEL 0.500 + +#define M3_MOTOR_MAP AXIS_Y +#define M3_STEP_ANGLE 1.8 +#define M3_TRAVEL_PER_REV 8.0934060625 +#define M3_MICROSTEPS 64 +#define M3_POLARITY 0 +#define M3_POWER_MODE MOTOR_ALWAYS_POWERED +#define M3_POWER_LEVEL 0.500 + +#define M4_MOTOR_MAP AXIS_Z +#define M4_STEP_ANGLE 1.8 +#define M4_TRAVEL_PER_REV 8.0934060625 +#define M4_MICROSTEPS 64 +#define M4_POLARITY 1 +#define M4_POWER_MODE MOTOR_ALWAYS_POWERED +#define M4_POWER_LEVEL 0.750 + +// *** axis settings ********************************************************************************** + +#define JERK_MAX 5000 + +#define X_AXIS_MODE AXIS_STANDARD // xam see canonical_machine.h cmAxisMode for valid values +#define X_VELOCITY_MAX 5000 // xvm G0 max velocity in mm/min +#define X_FEEDRATE_MAX X_VELOCITY_MAX // xfr G1 max feed rate in mm/min +#define X_TRAVEL_MIN 0 // xtn minimum travel for soft limits +#define X_TRAVEL_MAX 824 // xtm travel between switches or crashes +#define X_JERK_MAX 3500 // xjm jerk * 1,000,000 +#define X_JERK_HIGH_SPEED 20000 // xjh +#define X_HOMING_INPUT 1 // xhi input used for homing or 0 to disable +#define X_HOMING_DIRECTION 1 // xhd 0=search moves negative, 1= search moves positive +#define X_SEARCH_VELOCITY 2000 // xsv minus means move to minimum switch +#define X_LATCH_VELOCITY 100 // xlv mm/min +#define X_LATCH_BACKOFF 4 // xlb mm +#define X_ZERO_BACKOFF 2 // xzb mm + +#define Y_AXIS_MODE AXIS_STANDARD +#define Y_VELOCITY_MAX 5000 +#define Y_FEEDRATE_MAX Y_VELOCITY_MAX +#define Y_TRAVEL_MIN 0 +#define Y_TRAVEL_MAX 781 +#define Y_JERK_MAX 3500 +#define Y_JERK_HIGH_SPEED 20000 +#define Y_HOMING_INPUT 2 +#define Y_HOMING_DIRECTION 1 +#define Y_SEARCH_VELOCITY 2000 +#define Y_LATCH_VELOCITY 100 +#define Y_LATCH_BACKOFF 4 +#define Y_ZERO_BACKOFF 2 + +#define Z_AXIS_MODE AXIS_STANDARD +#define Z_VELOCITY_MAX 1200 +#define Z_FEEDRATE_MAX Z_VELOCITY_MAX +#define Z_TRAVEL_MAX 75 +#define Z_TRAVEL_MIN -15 +#define Z_JERK_MAX 500 +#define Z_JERK_HIGH_SPEED 1000 +#define Z_HOMING_INPUT 3 +#define Z_HOMING_DIRECTION 1 +#define Z_SEARCH_VELOCITY (Z_VELOCITY_MAX * 0.66666) +#define Z_LATCH_VELOCITY 25 +#define Z_LATCH_BACKOFF 4 +#define Z_ZERO_BACKOFF 2 + +//*** Input / output settings *** +/* + IO_MODE_DISABLED + IO_ACTIVE_LOW aka NORMALLY_OPEN + IO_ACTIVE_HIGH aka NORMALLY_CLOSED + + INPUT_ACTION_NONE + INPUT_ACTION_STOP = 1 - stop at normal jerk - preserves positional accuracy + INPUT_ACTION_FAST_STOP = 2 - stop at high jerk - preserves positional accuracy + INPUT_ACTION_HALT = 3 - stop immediately - not guaranteed to preserve position + INPUT_ACTION_CYCLE_START = 4 - start / restart cycle after feedhold (RESERVED) + INPUT_ACTION_ALARM = 5 - initiate an alarm. stops everything immediately - preserves position + INPUT_ACTION_SHUTDOWN = 6 - initiate a shutdown. stops everything immediately - does not preserve position + INPUT_ACTION_PANIC = 7 - initiate a panic. stops everything immediately - does not preserve position + INPUT_ACTION_RESET = 8 - reset system + + INPUT_ACTION_LIMIT = 9 - limit switch processing + INPUT_ACTION_INTERLOCK = 10 - interlock processing +*/ + +#define PROBING_INPUT 5 + +#define DI1_POLARITY IO_ACTIVE_HIGH +// #define DI1_ACTION INPUT_ACTION_LIMIT +#define DI1_ACTION INPUT_ACTION_NONE + +#define DI2_POLARITY IO_ACTIVE_HIGH +// #define DI2_ACTION INPUT_ACTION_LIMIT +#define DI2_ACTION INPUT_ACTION_NONE + +#define DI3_POLARITY IO_ACTIVE_HIGH +//#define DI3_ACTION INPUT_ACTION_LIMIT +#define DI3_ACTION INPUT_ACTION_NONE + +#define DI4_POLARITY IO_ACTIVE_HIGH +//#define DI4_ACTION INPUT_ACTION_LIMIT +#define DI4_ACTION INPUT_ACTION_NONE + +#define DI5_POLARITY IO_ACTIVE_HIGH // Z probe +#define DI5_ACTION INPUT_ACTION_NONE + +#define DI6_POLARITY IO_ACTIVE_HIGH +//#define DI6_ACTION INPUT_ACTION_LIMIT +#define DI6_ACTION INPUT_ACTION_NONE + +#define DI7_ENABLED IO_DISABLED +#define DI7_ACTION INPUT_ACTION_NONE + +#define DI8_ENABLED IO_DISABLED +#define DI8_ACTION INPUT_ACTION_NONE + +#define DI9_ENABLED IO_DISABLED +#define DI9_ACTION INPUT_ACTION_NONE + + +// *** PWM SPINDLE CONTROL *** + +/* VFD settings: + P0 settings need to be changed: + P0-000 = 1 (Select command source = Analog terminal control) + P0-001 = 3 (Select frequency source = max(Main frequency source x,Assistant frequency source y)) + P0-002 = 2 (Main frequency source x selection = AIN1) + + P0-007 = 400 + P0-024 = 400 (set maximum frequency at 100%) + + For run/stop and direction control: + P0-016 = 1 (factory) (X1 terminal function = forward run) + P0-017 = 2 (factory was 24) (X2 terminal function = reverse run) + P0-020 = 1 (2-wire mode = 2) + P0-021 = 0 (set minimum input) + P0-022 = 0 (set minimum speed) + + Disconnect X1, X2, set P0-24 to 10, and P0-023 to 10, and read the monitor, + then set the g2 to 100% output (via M3 or direct json), then use the shown value for P0-23 + + P0-023 = 9.22 for me (set maximum input voltage) + + + X1 = running + X2 = reverse direction (low = forward) + +*/ + +#define SPINDLE_SPEED_CHANGE_PER_MS 4 // 20k RPM in 5 seconds +#define P1_PWM_FREQUENCY 100000 // in Hz +#define P1_CW_SPEED_LO 1 // in RPM (arbitrary units) +#define P1_CW_SPEED_HI 24000 +#define P1_CW_PHASE_LO 0.05 // phase [0..1] +#define P1_CW_PHASE_HI 1.0 +#define P1_CCW_SPEED_LO 1 +#define P1_CCW_SPEED_HI 24000.0 +#define P1_CCW_PHASE_LO 0.05 +#define P1_CCW_PHASE_HI 1.0 +#define P1_PWM_PHASE_OFF 0.0 diff --git a/g2core/utils/enter_bootloader.sh b/g2core/utils/enter_bootloader.sh new file mode 100755 index 00000000..858df1a6 --- /dev/null +++ b/g2core/utils/enter_bootloader.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Define function to print colored text +print_message () { + if [ $# -eq 2 ]; then + color=$1 + message=$2 + else + color="default" + message=$1 + fi + + case $color in + "red") + echo -e "\033[0;31m$message\033[0m" + ;; + "green") + echo -e "\033[0;32m$message\033[0m" + ;; + *) + echo $message + ;; + esac +} + +# Print message to indicate entering bootloader mode +print_message "green" "Entering G2Core into bootloader mode..." + +# List available serial ports and prompt user to select a port +serial_ports=($(ls /dev/ttyACM*)) +if [ ${#serial_ports[@]} -eq 0 ]; then + print_message "red" "No serial ports found. Make sure your device is connected and try again." + exit 1 +fi + +while true; do + print_message "default" "Select the serial port to use:" + for i in "${!serial_ports[@]}"; do + echo "$((i+1)). ${serial_ports[$i]}" + done + echo -n "Enter the number of the serial port to use: " + read port_number + + # Check that the user entered a valid number + if [[ ! "$port_number" =~ ^[0-9]+$ ]]; then + print_message "red" "Invalid port number: $port_number" + elif [ $port_number -lt 1 ] || [ $port_number -gt ${#serial_ports[@]} ]; then + print_message "red" "Invalid port number: $port_number" + else + break + fi +done + +# Construct the serial port path from the selected number +serial_port=${serial_ports[$((port_number-1))]} + +# Set the baud rate on the selected serial port +stty -F "$serial_port" 1200 hup +stty -F "$serial_port" 9600 + +# Print message to flash the board +print_message "green" "G2core on port $serial_port should now be in bootloader mode. Execute this command:" +print_message "green" "bossac --port=$serial_port -u=true -e -w -v -i -b -R /g2core.bin" +print_message "green" "to flash your g2core board."