Auto Z with generalized probing move

General Goal:
I’m currently creating a python script to easily add auto z adjustment between my BLTouch probe and nozzle so that I can switch my nozzles easier on my Ender 3 S1 PRO.

Implementation idea:
Although implementations for this kind of thing exists already, they require a lot of changes to the main printer config file and thus conflict with other setups. Such as not being able to use the virtual z bl touch endstop for stepper Z, having to rewrite the homing macro etc.
To avoid this I want to use a general endstop which I’ve added to my PA15 pin and use homing.probing_move(endstop, position, speed), ‘endstop’ being my PA15 endstop and ‘position’ being the nozzle over the PA15 endstop.

Issue:
This currently works fine if I set the PA15 endstop as my stepper Z default endstop (Which I don’t want to do) and pass that to the probing move function. But if I try to grab the PA15 endstop and pass that to the probe move function without setting it that way, I get an error of:

"{'error': 'WebRequestError', 'message': "initializer for ctype 'struct trdispatch_mcu *' must be a cdata pointer, not NoneType"}" from the probing_move function

The code I’m using to get my general PA15 endstop is this

> def get_endstop(self, endstop_pin, gcmd):
>         printer = self.config.get_printer()
>         ppins = printer.lookup_object('pins')
>         endstop = ppins.setup_pin('endstop', endstop_pin)
>         stepper = self.get_z_stepper(gcmd)
>         name = stepper.get_name(short=True)
>         self.query_endstops.register_endstop(endstop, name)
>         endstop.add_stepper(stepper)
>         
>         return endstop

‘endstop_pin’ being a string which contains “PA15”. It seems to retrieve the endstop fine and assign it to the stepper (Which I think is correct, I’m not too sure) but then I seem to be receiving the aforementioned error which I don’t entirely understand.

I’m a bit new to python, but I’m familiar with C#/C/C++ and some other langauges, mainly C# and C++. If I get this issue resolved, I’ll upload the entire code to a github and my personal CAD files to easily attach an autoz endstop to the Ender 3 S1 Pro.

Thanks for any help in advance.

Hi again!

In which context are you using that function? Helping out would be easier (for me at least) with more information.

The log file associated to that error would also be nice.

Cheers

1 Like

Hey, how goes it?

I’m using it straight after homing.

Internal error on command:"TEST_Z_OFFSET"
Internal Error on WebRequest: gcode/script
Traceback (most recent call last):
  File "/home/CircleNine/klipper/klippy/webhooks.py", line 256, in _process_request
    func(web_request)
  File "/home/CircleNine/klipper/klippy/webhooks.py", line 425, in _handle_script
    self.gcode.run_script(web_request.get_str('script'))
  File "/home/CircleNine/klipper/klippy/gcode.py", line 216, in run_script
    self._process_commands(script.split('\n'), need_ack=False)
  File "/home/CircleNine/klipper/klippy/gcode.py", line 198, in _process_commands
    handler(gcmd)
  File "/home/CircleNine/klipper/klippy/gcode.py", line 135, in <lambda>
    func = lambda params: origfunc(self._get_extended_params(params))
  File "/home/CircleNine/klipper/klippy/extras/auto_offset_z.py", line 123, in cmd_Test_Z_Offset
    posNozzle = self._probe(autoZendstop, -20, self.z_hop_speed)
  File "/home/CircleNine/klipper/klippy/extras/auto_offset_z.py", line 183, in _probe
    curpos = phoming.probing_move(mcu_endstop, pos, speed)
  File "/home/CircleNine/klipper/klippy/extras/homing.py", line 246, in probing_move
    epos = hmove.homing_move(pos, speed, probe_pos=True)
  File "/home/CircleNine/klipper/klippy/extras/homing.py", line 85, in homing_move
    wait = mcu_endstop.home_start(print_time, ENDSTOP_SAMPLE_TIME,
  File "/home/CircleNine/klipper/klippy/mcu.py", line 285, in home_start
    trsync.start(print_time, self._trigger_completion, expire_timeout)
  File "/home/CircleNine/klipper/klippy/mcu.py", line 195, in start
    ffi_lib.trdispatch_mcu_setup(self._trdispatch_mcu, clock, expire_clock,
TypeError: initializer for ctype 'struct trdispatch_mcu *' must be a cdata pointer, not NoneType

^^ This seems to be the relevant part of the log,

That’s great, thanks. auto_offset_z.py does not seem to be a standard Klipper extra module.

What I’d propose is to trace the error to see what kind of object _trdispatch_mcu should be, then to what object from _probe it maps, and finally check how the inputs to _probe are setup.

Is there a link to the source of auto_offset_z.py?

I’m writing this module myself as an extension for auto z functionality with the BLTouch.

I’d like to help but it will be very hard for me without the source.

I just googled auto_offset_z and found this instead: GitHub - hawkeyexp/auto_offset_z

Hoping it helps!

I’ve seen that already, sadly it sets the stepper_z endstop to the pin which I don’t want, I still want my endstop to be the bltouch.