+ return (x_contact, y_contact, slope)
+
+def limited_linear_sensitivity(params):
+ """
+ Return the estimated sensitivity to small deflections according to
+ limited_linear fit parameters.
+ """
+ slope = params[2]
+ return slope
+
+def limited_quadratic(x, params):
+ """
+ Model the bump as:
+ flat region (off-surface)
+ quadratic region (in-contact)
+ flat region (high-voltage-rail)
+ Parameters:
+ x_contact (x value for the surface-contact kink)
+ y_contact (y value for the surface-contact kink)
+ slope (dy/dx at the surface-contact kink)
+ quad (d**2 y / dx**2, allow decreasing sensitivity with increased x)
+ """
+ high_voltage_rail = 2**16 - 1 # bits
+ x_contact,y_contact,slope,quad = params
+ y = slope*(x-x_contact) + quad*(x-x_contact)**2+ y_contact
+ y = numpy.clip(y, y_contact, high_voltage_rail)
+ return y
+
+def limited_quadratic_param_guess(x, y) :
+ """
+ Guess rough parameters for a limited_quadratic model. Assumes the
+ bump approaches (raising the deflection as it does so) first.
+ Retracting after the approach is optional. Approximates the contact
+ position and an on-surface (high) position by finding first crossings
+ of thresholds 0.3 and 0.7 of the y value's total range. Not the
+ most efficient algorithm, but it seems fairly robust.
+ """
+ x_contact,y_contact,slope = limited_linear_param_guess(x,y)