The following script demonstrates the jitter of the position reading of a moving motor. A motor (conversion = 4000) is moved to a start position then to an end position. While the motor moves to the end position, the position attribute is constantly read. The plots 14.3 and 14.4 show the distribution of the differences. Both distributions show a discrete spectrum because out motor is a stepping motor and the slew rate is in the order of the loop cycle time.
What do we learn from these plots? Let's assume that we want to open a shutter when the motor reaches a certain position. Looking at 14.3 we see that we can do this with a position error of 0.001 units or better. Notice that the x-axis is scaled. The value of 1000 corresponds to 0.001.
#!/usr/bin/env python import sys, time, math import PyTango import matplotlib matplotlib.use( 'TkAgg') import matplotlib.pyplot as plt import numpy as np try: proxyMotor = PyTango.DeviceProxy( "haspp99:10000/p09/motor/d1.65") except PyTango.DevFailed as e: PyTango.Except.print_exception(e) sys.exit() posStart = 0 posEnd = 10 # # move to the start position # proxyMotor.Position = posStart while proxyMotor.state() == PyTango.DevState.MOVING: print( "moving to start position %g/%g " % (proxyMotor.Position, posStart)) time.sleep(0.1) nMax = 3000. x = np.arange( 0.0, nMax, 1) y = np.zeros( nMax) n = 1000000. posOld = proxyMotor.Position proxyMotor.Position = 10 for i in range(int(n)): pos = proxyMotor.Position posDiff = pos - posOld posOld = pos #print( " %d posDiff %g" % (i, posDiff)) posDiff *= 1000000. if proxyMotor.state() == PyTango.DevState.ON: print( "Motor stopped aborting loop") break if int(posDiff) == 0: continue if posDiff < nMax: y[int(posDiff)] += 1 else: y[int(nMax - 1)] += 1 plt.figtext( 0.8, 0.8, "SlewRate: %d, Zeros are suppressed" % (proxyMotor.SlewRate), va='center', ha = 'right') plt.plot( x, y, 'r') plt.ylabel( 'Frequency') plt.xlabel( 'Difference between consecutive position readings (*1E6)') plt.show()