My fully automated delta calibration.

I use the below script to automate calibration of my bid delta.
My nozzle is uses as touch sensor (it opens closed switch)

custom_menu.g31.enable               true                        #
custom_menu.g31.name                bed_leveling_full           #
custom_menu.g31.command              M206_Z0|M666_X0_Y0_Z0|G32|G31|G1_Z0_F2000|G30|M374|M500|G28              #

Description:
For unknown reason G32 (or G31) ends with nozzle abobe the bed a few millimeters( M114 returns z=0) and I need to add Z offset manually.
So I started to use G1_Z0_F2000|G30 but G30 does not save the result. I modified the code to improve G30 and now it saves the result as Z-offset.
On small delta I added 0.2 (hardcoded) to Z-offset and now able to print just after menu Calib. pressing without any additional steps.
I have a feeling that there is more simple and efficient way to do the above.

on small delta I found G31 is not nessary so the script is
custom_menu.g31.command M206_Z0|M666_X0_Y0_Z0|G32|G1_Z0_F2000|G30|M500|G28 #

What do you think?

Here is my mod of ZProbe.cpp :

if( gcode->g == 30 ) { // simple Z probe
            // first wait for an empty queue i.e. no moves left
            THEKERNEL->conveyor->wait_for_empty_queue();
        int steps;
        bool probe_result;
        bool reverse= (gcode->has_letter('R') && gcode->get_value('R') != 0); // specify to probe in reverse direction
        float rate= gcode->has_letter('F') ? gcode->get_value('F') / 60 : this->slow_feedrate;
        probe_result = run_probe(steps, rate, -1, reverse);

        if(probe_result) {
            // the result is in actuator coordinates and raw steps
            gcode->stream->printf("Z:%1.4f C:%d\n", zsteps_to_mm(steps), steps);

//////// auto save Z offset for delta autocalibration sequence
char buf[10];
char cmd[10];
strcpy (cmd,"M206 ");
int n = snprintf(buf, sizeof(buf),“Z%1.4f\n”, zsteps_to_mm(steps) - 0.2 ); // 0.2 z-probe Z-offset
strncat(cmd, buf, n);
Gcode gc(cmd, &(StreamOutput::NullStream));
THEKERNEL->call_event(ON_GCODE_RECEIVED, &gc);
////////


Imported from wikidot