-
Notifications
You must be signed in to change notification settings - Fork 0
Endstops
This document describes the endstop implementation in Gopper, which provides comprehensive support for various types of endstop sensors used in 3D printers.
Gopper implements Klipper-compatible endstop functionality with support for:
- GPIO-based endstops (mechanical switches, hall effect sensors with digital output)
- Analog endstops (ADC-based sensors, analog hall effect sensors)
- I2C endstops (Time-of-Flight sensors like VL53L0X, VL53L1X, VL53L4CD)
-
Trigger Synchronization (trsync) (
core/trsync.go)- Coordinates multiple endstops during homing operations
- Manages trigger callbacks and timeouts
- Reports trigger events to the host
-
GPIO Endstops (
core/endstop.go)- Traditional mechanical switches
- Hall effect sensors with digital output
- Optical sensors with digital output
- Uses timer-based sampling with oversampling to prevent false triggers
-
Analog Endstops (
core/endstop_analog.go)- Hall effect sensors with analog output
- Pressure-sensitive sensors
- Threshold-based triggering with hysteresis
-
I2C Endstops (
core/endstop_i2c.go)- Time-of-Flight (TOF) sensors (VL53L0X, VL53L1X, VL53L4CD)
- Distance-based triggering with hysteresis
Format: trsync_start oid=%c report_clock=%u report_ticks=%u expire_reason=%c
Starts a trigger synchronization session for coordinated homing.
Parameters:
-
oid: Object ID of the trigger sync object -
report_clock: Initial clock time for status reports -
report_ticks: Interval between status reports (in timer ticks) -
expire_reason: Reason code to report if timeout expires
Format: trsync_set_timeout oid=%c clock=%u
Sets a timeout for the trigger synchronization.
Parameters:
-
oid: Object ID of the trigger sync object -
clock: Clock time when timeout expires
Format: trsync_trigger oid=%c reason=%c
Manually triggers a trsync object.
Parameters:
-
oid: Object ID of the trigger sync object -
reason: Reason code for the trigger
Format: trsync_state oid=%c can_trigger=%c trigger_reason=%c clock=%u
Reports the current state of a trigger sync object.
Format: config_endstop oid=%c pin=%u pull_up=%c
Configures a GPIO pin as an endstop input.
Parameters:
-
oid: Object ID for the endstop -
pin: GPIO pin number -
pull_up: 1 to enable pull-up resistor, 0 for pull-down
Format: endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c rest_ticks=%u pin_value=%c trsync_oid=%c trigger_reason=%c
Starts homing with a GPIO endstop.
Parameters:
-
oid: Object ID of the endstop -
clock: Clock time to start checking -
sample_ticks: Time between consecutive samples during oversampling -
sample_count: Number of consecutive samples required to confirm trigger (0 to disable) -
rest_ticks: Time between check cycles -
pin_value: Expected pin value when triggered (1=high, 0=low) -
trsync_oid: Object ID of the associated trigger sync -
trigger_reason: Reason code to report when triggered
Format: endstop_query_state oid=%c
Queries the current state of an endstop.
Format: endstop_state oid=%c homing=%c next_clock=%u pin_value=%c
Reports the current state of a GPIO endstop.
Format: config_analog_endstop oid=%c adc_oid=%c threshold=%u trigger_above=%c hysteresis=%u
Configures an analog (ADC-based) endstop.
Parameters:
-
oid: Object ID for the endstop -
adc_oid: Object ID of the associated ADC channel -
threshold: ADC value threshold for triggering -
trigger_above: 1 to trigger when value > threshold, 0 when value < threshold -
hysteresis: Hysteresis value to prevent oscillation
Format: analog_endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c rest_ticks=%u trsync_oid=%c trigger_reason=%c
Starts homing with an analog endstop.
Format: analog_endstop_query_state oid=%c
Queries the current state of an analog endstop.
Format: analog_endstop_state oid=%c homing=%c next_clock=%u value=%u
Reports the current state of an analog endstop, including the latest ADC value.
Format: config_i2c_endstop oid=%c i2c_oid=%c addr=%c sensor_type=%c distance_threshold=%u trigger_below=%c hysteresis=%u
Configures an I2C-based endstop (e.g., TOF sensor).
Parameters:
-
oid: Object ID for the endstop -
i2c_oid: Object ID of the associated I2C device -
addr: I2C device address -
sensor_type: Sensor type (0=VL53L0X, 1=VL53L1X, 2=VL53L4CD) -
distance_threshold: Distance threshold for triggering (in mm) -
trigger_below: 1 to trigger when distance < threshold, 0 when distance > threshold -
hysteresis: Hysteresis value to prevent oscillation (in mm)
Format: i2c_endstop_home oid=%c clock=%u sample_ticks=%u sample_count=%c rest_ticks=%u trsync_oid=%c trigger_reason=%c
Starts homing with an I2C endstop.
Format: i2c_endstop_query_state oid=%c
Queries the current state of an I2C endstop.
Format: i2c_endstop_state oid=%c homing=%c next_clock=%u distance=%u
Reports the current state of an I2C endstop, including the latest distance reading (in mm).
All endstop types implement a two-stage detection mechanism to prevent false triggers:
-
Initial Detection: The endstop is checked periodically (every
rest_ticks) -
Oversampling: When a potential trigger is detected, the endstop is sampled multiple times consecutively (every
sample_ticks) to confirm the trigger
This approach, borrowed from Klipper, prevents false triggers caused by electrical noise or mechanical bounce.
The trsync system coordinates multiple endstops during homing operations:
- Multiple endstops can be registered with the same
trsyncobject - When any endstop triggers, all registered callbacks are invoked
- The first trigger wins - subsequent triggers are ignored
- Timeout mechanism provides fallback if no endstop triggers
The endstop implementation is platform-agnostic and relies on HAL (Hardware Abstraction Layer) interfaces:
- GPIO HAL: Provides pin configuration and reading
- ADC HAL: Provides analog-to-digital conversion
- I2C HAL: Provides I2C communication
Currently supported platforms:
- RP2040 (Raspberry Pi Pico)
- RP2350 (Raspberry Pi Pico 2)
# Klipper configuration example
[stepper_x]
endstop_pin: ^gpio25 # Pull-up enabledThe firmware will:
- Configure GPIO25 as input with pull-up
- During homing, sample the pin multiple times to confirm trigger
- Report trigger to the host via trsync
# Klipper configuration example
[stepper_y]
endstop_pin: analog_endstop:ADC0The firmware will:
- Configure ADC0 for analog sampling
- Monitor ADC value against threshold
- Use hysteresis to prevent oscillation
- Report trigger when threshold is crossed consistently
# Klipper configuration example
[stepper_z]
endstop_pin: i2c_endstop:VL53L0XThe firmware will:
- Initialize VL53L0X sensor via I2C
- Periodically read distance measurements
- Trigger when distance crosses threshold
- Use hysteresis to prevent oscillation
Potential improvements for future releases:
- Sensorless Homing: Detect motor stall current for endstop detection
- Encoder-based Endstops: Use rotary encoders for position detection
- Multiple Sensor Fusion: Combine data from multiple sensor types
- Dynamic Threshold Adjustment: Auto-tune thresholds based on environmental conditions
- Advanced Filtering: Implement Kalman filtering for noisy sensors
- Klipper endstop implementation: src/endstop.c
- Klipper trsync implementation: src/trsync.c
- Klipper endstop phase: docs/Endstop_Phase.md