Skip to content

Commit

Permalink
Optical autocal (MarlinFirmware#2)
Browse files Browse the repository at this point in the history
* add NUCLEO-STM32F746 board def and configs

* add F746ZG to pins

* fix formatting

* add config file changes

* add naive config options and torsk airsystem files

* move more config defines

* tweak some constants

* add flags for door controls, disable features by defautl

* add more feature flags for unimplemented Cellink printer features.

* use ordered pair over separate XYZ

* move air system to features

* add empty lidgripper feature files

* add rough lidgripper class definition

* use signed ints for error reporting, add calibration implementation

* add functions for moving to-from gripper location

* add placeholder Gcodes for lid gripping

* small marlin best practice tweaks

* add naive G501 and G502 implementations

* use instance over static, remove const because overloads aren't const :(

* add more (unused as of now) config options for lid gripper

* fix endstop logic for 2209

* more complex lid gripper construction to check for errors

* add pin names for lid gripper

* tweak axes scaling

* move lid_gripper location up

* add bedlevel, manual probe, and backlash compensation commands

* define extruder flag as constant false if no extruder is defined

* add constructor body

* add measured backlash values as default

* put LG on real pins

* rename address

* add lid gripper stepper functions

* add lid gripper bindings

* tune step widths

* add a serial buffer for smoother communication

* remove templating, temporarily switch to TMC2130 driver

* change pins to use SPI for lid gripper

* add lid gripper initialization

* return of the templates

* fix calibrate implementation

* add calibrate Gcode

* increase stall sensitivity

* decrease max feedrate

* init LG serial

* change move to and from gripper routines, add debugging, extern define necesarry serial port

* change accessory serial pins

* adjust maximum printer moves

* add autocal options

* fix syntax

* add initial optical autocal support

* use absolute coordinates

* return after interrupt detach

* add gcode parameters

* add parameterss and defaults for g510

* use correct position reporting API

* use an instanced ISR for flexibility

* increase float precision

* add adjustable z_increment to Gcode

* const all the things, smarter isr

* const all the things, smarter isr
  • Loading branch information
arades79 authored Oct 21, 2021
1 parent a6320a2 commit beaa410
Show file tree
Hide file tree
Showing 13 changed files with 1,207 additions and 33 deletions.
22 changes: 11 additions & 11 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,14 +920,14 @@
* Override with M92
* X, Y, Z [, I [, J [, K]]], E0 [, E1[, E2...]]
*/
#define DEFAULT_AXIS_STEPS_PER_UNIT { 313, 313, 1200}
#define DEFAULT_AXIS_STEPS_PER_UNIT { 320, 320, 1280}

/**
* Default Max Feed Rate (mm/s)
* Override with M203
* X, Y, Z [, I [, J [, K]]], E0 [, E1[, E2...]]
*/
#define DEFAULT_MAX_FEEDRATE { 600, 600, 100}
#define DEFAULT_MAX_FEEDRATE { 200, 200, 100}

//#define LIMITED_MAX_FR_EDITING // Limit edit via M203 or LCD to DEFAULT_MAX_FEEDRATE * 2
#if ENABLED(LIMITED_MAX_FR_EDITING)
Expand All @@ -940,7 +940,7 @@
* Override with M201
* X, Y, Z [, I [, J [, K]]], E0 [, E1[, E2...]]
*/
#define DEFAULT_MAX_ACCELERATION { 1200, 1200, 100}
#define DEFAULT_MAX_ACCELERATION { 2000, 2000, 100}

//#define LIMITED_MAX_ACCEL_EDITING // Limit edit via M201 or LCD to DEFAULT_MAX_ACCELERATION * 2
#if ENABLED(LIMITED_MAX_ACCEL_EDITING)
Expand Down Expand Up @@ -1057,7 +1057,7 @@
* Use G29 repeatedly, adjusting the Z height at each point with movement commands
* or (with LCD_BED_LEVELING) the LCD controller.
*/
//#define PROBE_MANUALLY
#define PROBE_MANUALLY

/**
* A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
Expand Down Expand Up @@ -1369,8 +1369,8 @@
#define X_MIN_POS 0
#define Y_MIN_POS 0
#define Z_MIN_POS 0
#define X_MAX_POS 300
#define Y_MAX_POS 150
#define X_MAX_POS 350
#define Y_MAX_POS 175
#define Z_MAX_POS 40
//#define I_MIN_POS 0
//#define I_MAX_POS 50
Expand Down Expand Up @@ -1530,7 +1530,7 @@
//#define AUTO_BED_LEVELING_3POINT
//#define AUTO_BED_LEVELING_LINEAR
//#define AUTO_BED_LEVELING_BILINEAR
//#define AUTO_BED_LEVELING_UBL
#define AUTO_BED_LEVELING_UBL
//#define MESH_BED_LEVELING

/**
Expand Down Expand Up @@ -1738,7 +1738,7 @@
#endif

// Homing speeds (mm/min)
#define HOMING_FEEDRATE_MM_M { (20*60), (36*20), (15*60) }
#define HOMING_FEEDRATE_MM_M { (20*60), (35*20), (15*60) }

// Validate that endstops are triggered on homing moves
#define VALIDATE_HOMING_ENDSTOPS
Expand Down Expand Up @@ -1797,7 +1797,7 @@
#endif

// Enable this option for M852 to set skew at runtime
//#define SKEW_CORRECTION_GCODE
#define SKEW_CORRECTION_GCODE
#endif

//=============================================================================
Expand All @@ -1815,12 +1815,12 @@
* M501 - Read settings from EEPROM. (i.e., Throw away unsaved changes)
* M502 - Revert settings to "factory" defaults. (Follow with M500 to init the EEPROM.)
*/
//#define EEPROM_SETTINGS // Persistent storage with M500 and M501
#define EEPROM_SETTINGS // Persistent storage with M500 and M501
//#define DISABLE_M503 // Saves ~2700 bytes of PROGMEM. Disable for release!
#define EEPROM_CHITCHAT // Give feedback on EEPROM commands. Disable to save PROGMEM.
//#define EEPROM_BOOT_SILENT // Keep M503 quiet and only give errors during first load
#if ENABLED(EEPROM_SETTINGS)
#define EEPROM_AUTO_INIT // Init EEPROM automatically on any errors.
//#define EEPROM_AUTO_INIT // Init EEPROM automatically on any errors.
#endif

//
Expand Down
145 changes: 130 additions & 15 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,12 @@
// Backlash Compensation
// Adds extra movement to axes on direction-changes to account for backlash.
//
//#define BACKLASH_COMPENSATION
#define BACKLASH_COMPENSATION
#if ENABLED(BACKLASH_COMPENSATION)
// Define values for backlash distance and correction.
// If BACKLASH_GCODE is enabled these values are the defaults.
#define BACKLASH_DISTANCE_MM { 0, 0, 0 } // (mm) One value for each linear axis
#define BACKLASH_CORRECTION 0.0 // 0.0 = no correction; 1.0 = full correction
#define BACKLASH_DISTANCE_MM { 0.06, 0, 0 } // (mm) One value for each linear axis
#define BACKLASH_CORRECTION 1.0 // 0.0 = no correction; 1.0 = full correction

// Add steps for motor direction changes on CORE kinematics
//#define CORE_BACKLASH
Expand All @@ -1014,11 +1014,11 @@
//#define BACKLASH_SMOOTHING_MM 3 // (mm)

// Add runtime configuration and tuning of backlash values (M425)
//#define BACKLASH_GCODE
#define BACKLASH_GCODE

#if ENABLED(BACKLASH_GCODE)
// Measure the Z backlash when probing (G29) and set with "M425 Z"
#define MEASURE_BACKLASH_WHEN_PROBING
//#define MEASURE_BACKLASH_WHEN_PROBING

#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
// When measuring, the probe will move up to BACKLASH_MEASUREMENT_LIMIT
Expand All @@ -1044,7 +1044,7 @@
* Note: HOTEND_OFFSET and CALIBRATION_OBJECT_CENTER must be set to within
* ±5mm of true values for G425 to succeed.
*/
//#define CALIBRATION_GCODE
#define CALIBRATION_GCODE
#if ENABLED(CALIBRATION_GCODE)

//#define CALIBRATION_SCRIPT_PRE "M117 Starting Auto-Calibration\nT0\nG28\nG12\nM117 Calibrating..."
Expand Down Expand Up @@ -2146,13 +2146,13 @@
// For debug-echo: 128 bytes for the optimal speed.
// Other output doesn't need to be that speedy.
// :[0, 2, 4, 8, 16, 32, 64, 128, 256]
#define TX_BUFFER_SIZE 0
#define TX_BUFFER_SIZE 256

// Host Receive Buffer Size
// Without XON/XOFF flow control (see SERIAL_XON_XOFF below) 32 bytes should be enough.
// To use flow control, set this buffer size to at least 1024 bytes.
// :[0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]
//#define RX_BUFFER_SIZE 1024
#define RX_BUFFER_SIZE 1024

#if RX_BUFFER_SIZE >= 1024
// Enable to have the controller send XON/XOFF control characters to
Expand Down Expand Up @@ -2220,7 +2220,7 @@
#define SERIAL_OVERRUN_PROTECTION

// For serial echo, the number of digits after the decimal point
//#define SERIAL_FLOAT_PRECISION 4
#define SERIAL_FLOAT_PRECISION 4

// @section extras

Expand Down Expand Up @@ -2919,11 +2919,11 @@

#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING)
// TMC2209: 0...255. TMC2130: -64...63
#define X_STALL_SENSITIVITY 45
#define X_STALL_SENSITIVITY 50
//#define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY
#define Y_STALL_SENSITIVITY 32
#define Y_STALL_SENSITIVITY 50
#define Y2_STALL_SENSITIVITY Y_STALL_SENSITIVITY
#define Z_STALL_SENSITIVITY 51
#define Z_STALL_SENSITIVITY 55
//#define Z2_STALL_SENSITIVITY Z_STALL_SENSITIVITY
//#define Z3_STALL_SENSITIVITY Z_STALL_SENSITIVITY
//#define Z4_STALL_SENSITIVITY Z_STALL_SENSITIVITY
Expand Down Expand Up @@ -4135,6 +4135,121 @@
//#define SERVICE_INTERVAL_3 1 // print hours
#endif

// @section bioprinting features

// enables support for modular printheads
// addressed and controlled via UART/RS285
// and using an interrupt trigger pin
//#define MODULAR_PRINTHEADS
#if ENABLED(MODULAR_PRINTHEADS)

#define NUMBER_MODULAR_PRINHEADS 3



#endif // MODULAR_PRINTHEADS

// enbables support for pneumatic/pressure systems
//#define PNEUMATIC_SYSTEM
#if ENABLED(PNEUMATIC_SYSTEM)

//The maximum pressure we can use for extrusion in kPa
#define MAXIMUM_EXTRUDE_PRESSURE 700
//in Kpa. This is the minimum pressure required to be maintained in the tank.
#define TANK_REQUIRED_PRESSURE_DEFAULT 260
//Dictates how much more the tank needs to be filled
#define TANK_FULL_PRESSURE_DEFAULT 310
// polarity pneumatic pins
#define AIR_RELEASE_PUMP_OPEN false
#define AIR_RELEASE_TANK_OPEN false
#define AIR_SOURCE_EXTERNAL true

#define AIRTANK_FULL_PRESSURE (REQUIRED_TANK_PRESSURE*TANK_PRESSURE_BUFFER_FACTOR)

#define PRESSURE_PWM_BITS 12
#define PRESSURE_PWM_TOP ((1<<PRESSURE_PWM_BITS)-1)
//PWM-frewuency: 16000000/((2^12)*2) = 1953Hz
//Pressure-resolution= FULLSCALE/(2^12)

//The max voltage the control signal can have
#define PRESSURE_MAX_CTRL_VOLTAGE 5000
//The smallest control voltage that should be used (it's technically possible ot use smaller, but not meaningful)
#define PRESSURE_MIN_CTRL_VOLTAGE 10
//The maximum feedback voltage from the regulator output sensor. This will correspond to PRESSURE_FULL_SCALE
#define PRESSURE_FEEDBACK_MAX_VOLT 5000
//The minimum feedback voltage from the regulator output sensor. This corresponds to 0 pressure
#define PRESSURE_FEEDBACK_MIN_VOLT 1000

//The cycle time for the pump control task (ms)
#define PUMP_TASK_TIME 95
//Startup time for the pump (it cannot start under pressure). (ms)
#define PUMP_STARTUP_HOLDOFF 150

//Maximum pressure sensor pressure (for MPX5700AP). Unit is kPa
#define PRESSURE_SENSOR_MAX_PRESSURE 700
//The pressure sensor has some kind of offset when reading atmosphere pressure. This is in ADC ticks. Empirically measured.
#define PRESSURE_SENSOR_OFFSET 168

//The maximum number of regulators we can have
#define NOF_MAX_REGULATORS 2

//Defines which printheads are supplied by which regulator

#define REGULATOR_1_PHS {1,3,5}
#if NOF_MAX_REGULATORS > 1
#define REGULATOR_2_PHS {2,4,6}
#endif

#endif // PNEUMATIC_SYSTEM

// Enables the untrasonic auto calibration system.
//#define ULTRASONIC_AUTOCALIBRATION


// Enable door sensor feature
//#define DOOR_OPEN_SENSOR
#if ENABLED(DOOR_OPEN_SENSOR)
// override pin for door sensor, or definition place if no
// door sensor pin is defined for your board (interrupt capable input)
#define DOOR_OPEN_PIN_OVERIDE 0
#endif

// Enable power door opening feature
//#define POWER_DOOR_OPENER

// options for lid gripping station
#define LID_GRIPPER_STATION
#if ENABLED(LID_GRIPPER_STATION)

// Position to move printbed before the lid gripper
// attempts to grip a lid {x,y,z}
#define LID_GRIPPER_COORDS {400,51,50}

// define stall sensitivity to use sensorless lid detection and
// gripping ability, and to adjust the force needed to stop the
// lid gripper. (0-255)
#define LID_GRIPPER_STALL_SENSITIVITY 50

// RMS current for driver to supply to motor (mA)
#define LID_GRIPPER_CURRENT 400

#define LID_GRIPPER_STEPS_PER_MM 140

// if using stallguard lid detection and gripping, this value is
// the maximum number of mm the gripper should close before we
// know for sure there is no lid present.
#define LID_GRIPPER_DETECTION_THRESHOLD 50000
#endif

// enable optical autocalibration routines
#define OPTICAL_AUTOCAL
#if ENABLED(OPTICAL_AUTOCAL)
#define AUTOCAL_START_POSITION {242.0, 150.0, 19.0}
#define AUTOCAL_DEFAULT_FEEDRATE 1.0
#define AUTOCAL_DEFAULT_CYCLES 100
#define AUTOCAL_DEFAULT_Z_INCREMENT 0.025
#endif

// @section develop

//
Expand All @@ -4145,15 +4260,15 @@
//
// M42 - Set pin states
//
//#define DIRECT_PIN_CONTROL
#define DIRECT_PIN_CONTROL

//
// M43 - display pin status, toggle pins, watch pins, watch endstops & toggle LED, test servo probe
//
//#define PINS_DEBUGGING
// #define PINS_DEBUGGING

// Enable Marlin dev mode which adds some special commands
//#define MARLIN_DEV_MODE
#define MARLIN_DEV_MODE

/**
* Postmortem Debugging captures misbehavior and outputs the CPU status and backtrace to serial.
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
bool G38_did_trigger; // = false
#endif

#if ENABLED(LID_GRIPPER_STATION)
#include "feature/lidgripper.h"
#endif

#if ENABLED(DELTA)
#include "module/delta.h"
#elif IS_SCARA
Expand Down Expand Up @@ -1627,6 +1631,11 @@ void setup() {
ui.check_touch_calibration();
#endif

#if ENABLED(LID_GRIPPER_STATION)
LGSerial.begin(115200);
SETUP_RUN(lid_gripper.init_pins());
#endif

marlin_state = MF_RUNNING;

SETUP_LOG("setup() completed.");
Expand Down
Loading

0 comments on commit beaa410

Please sign in to comment.