Custom Control: Z-Offset

Hello,
I have added a costum command to read and set the Z offset. But the problem is, that reading does not work (setting the value works).
When I press "Get" no value appears.

I use pure marlin. I think that the line starting with " regex:" is not correct. Anyone can explain how to set this correcty?

Output of M851 is:

Send: M851
Recv: echo:Probe Z Offset: -4.20
Recv: ok P15 B3

Anyone can have a look at my code?
Thank you!

controls:
- children:
  - command: M851
    default: ''
    name: Get
    regex: z zero offset value:(?P<offset>\d+(\.\d*))
    template: 'Current: {offset} mm'
    width: '5'
  - command: M851 Z%(offset)s
    input:
    - default: '0.00'
      name: New (mm)
      parameter: offset
      slider: false
    name: Set
    width: '5'
  - command: G28 Z0
    name: Home Z
    width: '2'
  collapsed: true
  layout: horizontal_grid
  name: Adjust Z Offset

Your guess is probably right.

In OSX at a command prompt

echo "Probe Z Offset: -4.20" | sed -En 's/Probe Z Offset:[^\d]?(\d*)/\1/p'
-4.20

Not knowing exactly what's going on behind-the-scenes, you might try:

  • Edit the regex to minimally make the search closer to your reality

I'm not sure if your config.yaml variable means:

  1. Create a json object behind-the-scenes which will read like z zero offset value: -4.20
  2. Look for "z zero offset value:" in the printer response followed by something else
1 Like

I use this site https://www.regexpal.com/ when I have regex's to test. I have noticed though that sometimes regex's work there but not in other software and vise versa, but it seems to work there and octoprint. You could test your regexp to see if it's actually searching properly.

Copy your terminal output into its sample text box, and your regex up into the regex field up top. That's how I create my terminal filters to filter out random stuff. Usually works pretty well.

1 Like

So not sure if you ever got this figured out @homass1, but I just tested the below and it seems to be working for my Marlin 1.1.9 implementation.

controls:
- children:
  - command: M851
    default: ''
    name: Get
    regex: 'Probe Z Offset: (?P<offset>-?\d+(\.\d*))'
    template: 'Current: {offset} mm'
    width: '5'
  - command: M851 Z%(offset)s
    input:
    - default: '0.00'
      name: New (mm)
      parameter: offset
      slider: false
    name: Set
    width: '5'
  - command: M500
    name: Save
    width: '2'
    confirm: You are about to store your settings using M500 command.
  collapsed: true
  layout: horizontal_grid
  name: Adjust Z Offset

Anyone coming here using newer Marlin 2.0.X versions will find the following updated control working for the regex template.

controls:
-   children:
    -   command: M851
        default: ''
        name: GET
        regex: Probe Offset.+Z(?P<offset>-?\d+(\.\d*))
        template: '{offset}mm'
    layout: horizontal_grid
    name: M851
1 Like

Another variant of the M851 response has been seen on Discord. Adding in this new one for Marlin Bugfix 2.1.x in case someone else stumbles across it. Response from printer to the M851 command in terminal is as follows: Recv: M851 X8.00 Y21.00 Z-2.90 ; (mm)

controls:
-   children:
    -   command: M851
        default: ''
        name: GET
        regex: M851.+Z(?P<offset>-?\d+(\.\d*)).*
        template: '{offset}mm'
    layout: horizontal_grid
    name: M851