Display default phase memory for 3-phase motorΒΆ
This Python code graphs the default phase memory for visualization.
# note: excluding code for configuring 3-phase motor
# write default phase memory to numpy buffer
buf = np.arange(pilib.PHASE_MEMORY_SIZE, dtype=np.uint32)
phase_size,shift_value = pm.mtr_write_phase_mem_default_buffer(phases, poles, encoder_cnts, buf)
buf = buf[:phase_size]
#read phase offset (after reset)
phase_offset = pm.mtr_get_phase_offset()
encoder = pm.mtr_get_enc_pos()
# display plot
x = np.linspace(0, phase_size-1, phase_size)
a = np.array(buf & 0xffff, dtype=np.int16)
b = np.array(buf >> 16 & 0xffff, dtype=np.int16)
c = -(a + b)
plt.plot(x, a, 'b')
plt.plot(x, b, 'g')
plt.plot(x, c, 'r')
plt.axvline(((phase_offset + encoder)>>shift_value) % phase_size,color='r')
plt.show()