• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

Z calibration - Need programming advice

Scheduled Pinned Locked Moved Unsolved
Duet Hardware and wiring
2
6
223
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    RockB
    last edited by RockB 23 Jul 2024, 06:13

    Hello,

    I am building a custom multi-tool tool changer system and now working on the Z calibration process. I am using a precision tool setter-type switch where each tool will come down touch the tool setter and register the machine Z coordinate. I am thinking of the following sequence of actions:

    1. Create a macro/job file called calibrateZ.g
    2. Select Tool, heat to 215C
    3. Move tool to XY position above the tool setter sensor. Note: I have already done XY calibration of each tool and have stored XY offsets for all tools in tpre#.g using G10 P# Xnn Ynn Z0.0
    4. Using G30 S-1 come down in Z and touch off the sensor to determine machine Z position at which sensor was triggered
    5. Do #4 for five times and store values in an array and compute the average and standard deviation
    6. Update Z offset for the tool using G10 P# Z{average_value}
    7. Turn of heater for tool
    8. Select next tool and repeat 2 to 6

    rough attempt at trying to code this

    ; calibrateZ.g
    T1; Select and load tool 1
    M109 P1 S215; Set temp (can also use M568??)
    M116 P1; Wait to reach temp
    G1 X0.0 Y0.0 F1000; move to HRP set to above Z tool setter sensor. X and Y offsets for tool stored in tpre#.g using G10 P1 Xnnn Ynnn Z0.0
    var zPos = {}; 5 element array - not sure how to define this
    for(i=1;i<=5;i++)
    {
    G30 S-1;
    zPos(i) = move.axes[2].machinePosition;
    G1 Zxx F100; relative move up
    }
    ; compute the average of zPos array
    ; compute std dev of zPos array
    if (stddev(zPos) > threshold)
    alert user
    stop
    else
    ;set Z offset G10 P1 Z{avg(zPos)} - need to check sign
    M109 P1 S0; Set temp (can also use M568??)
    T-1 P1; unload tool 1
    ; repeat for remaining tools

    Questions:

    1. Are there readily available G/M codes that can do this automatically? Don't want to re-invent the wheel. M585 seems to do this but although only once
    2. What is the right syntax to define the array, store value within the for loop and compute avg and std dev?
    3. Where would be the best place to store and use the calibrated Z position - tpre#.g or tpost#.g?
    4. Any other considerations I need to be aware of?
    undefined 1 Reply Last reply 23 Jul 2024, 10:52 Reply Quote 0
    • undefined
      droftarts administrators @RockB
      last edited by 23 Jul 2024, 10:52

      @RockB If the tool setter is defined as a probe with M558 (rather than an endstop), you can use the M558 A and S parameters to control multiple probing:

      Annn Maximum number of times to probe each point, default 1. Maximum, as of 2.03, is 31. Setting M558 A parameter to anything >31 set it to 0 instead of to 31
      Snnn Tolerance when probing multiple times, default 0.03mm

      The A and S parameters control multiple probing. Probing is repeated until two consecutive probe attempts produce results that differ by no more than the S parameter; then the average of those two results is used. For example, S-1 would force averaging. However, if the number of attempts specified by the A parameter is reached without getting two consecutive results within tolerance of each other, no further probe attempts are made and the average result of all the attempts is used.

      So setting M558 S-1 A5 would force it to average 5 contacts with the probe.

      With that set, you can use M585 to probe the tool (with the M558 settings it should do it multiple times) and calculate the offset.

      Ian

      Bed-slinger - Mini5+ WiFi/1LC | RRP Fisher v1 - D2 WiFi | Polargraph - D2 WiFi | TronXY X5S - 6HC/Roto | CNC router - 6HC | Tractus3D T1250 - D2 Eth

      undefined 1 Reply Last reply 23 Jul 2024, 16:54 Reply Quote 0
      • undefined
        RockB @droftarts
        last edited by RockB 23 Jul 2024, 16:54

        @droftarts Thanks for pointing me to M558 A and S parameters

        in my config.g, I have defined a Z probe as follows:

        ; Z Probe
        M558 K0 P5 C"!io3.in" A5 S-1 F130:100 T100 ; Z-probe tool setter connected to io3.in pin, Type 5 (switch- NC), Probe 5 times and average the results

        I move the nozzle about 5 mm above the tool setter and issue the following command in DWC

        M585 Z5 P0 S1 F100
        

        The probing just happens once and stops. I see the Z offset value automatically updated (Current Z position under axis name in DWC changes), However, probing is not happening 5 times as defined in M558. Any suggestions as to why this may be happening?

        undefined 1 Reply Last reply 23 Jul 2024, 17:38 Reply Quote 0
        • undefined
          droftarts administrators @RockB
          last edited by 23 Jul 2024, 17:38

          @RockB I’ll check with @dc42 if that’s the expected behaviour.

          Ian

          Bed-slinger - Mini5+ WiFi/1LC | RRP Fisher v1 - D2 WiFi | Polargraph - D2 WiFi | TronXY X5S - 6HC/Roto | CNC router - 6HC | Tractus3D T1250 - D2 Eth

          undefined 1 Reply Last reply 24 Jul 2024, 00:07 Reply Quote 0
          • undefined
            RockB @droftarts
            last edited by 24 Jul 2024, 00:07

            @droftarts Thank you. Also, When I try to save the machine Z position at which the Z probe was triggered as the Z offset using G10, nothing happens

            G10 P1 X{-move.axes[2].machinePosition}

            What is the correct way to update the Z offset after M585? I have noticed the Z offset is not retained after the tool change.

            undefined 1 Reply Last reply 24 Jul 2024, 21:14 Reply Quote 0
            • undefined
              RockB @RockB
              last edited by 24 Jul 2024, 21:14

              @RockB @droftarts @dc42 any suggestions?

              1 Reply Last reply Reply Quote 0
              • undefined Phaedrux marked this topic as a question 31 Jul 2024, 05:21
              4 out of 6
              • First post
                4/6
                Last post
              Unless otherwise noted, all forum content is licensed under CC-BY-SA