]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control-pxmc.git/blob - tools/datavis/pxmc-spimc-curcal.py
RPi PXMC Test: do not use cumulative current computation in currentcal command.
[fpga/rpi-motor-control-pxmc.git] / tools / datavis / pxmc-spimc-curcal.py
1 #! /usr/bin/python
2
3 import numpy as np
4 from numpy import linalg
5 import math
6 from pylab import plot, subplot, figure, show, ylim, yticks
7 from pprint import pprint
8 import argparse
9
10 if __name__ == '__main__':
11   data_fname = 'curcal-out.dat'
12   data_buff = np.loadtxt(data_fname)
13   zero_rows = 1
14
15   phase_ord = [0, 1, 2]
16
17   pwm_val = data_buff[:, np.multiply(phase_ord, 2)]
18   pwm_en  = data_buff[:, np.multiply(phase_ord, 2) + 1]
19   cur_raw = data_buff[:, [6, 7, 8]]
20
21   cur_offs  = cur_raw[0, :]
22   cur_zerob = cur_raw[zero_rows:, :] - cur_offs
23
24   rows = cur_zerob.shape[0]
25   cur_resp = np.ndarray(shape=(rows / 2, 3))
26   cur_resid = np.ndarray(shape=(rows, 3))
27   cur_refall = np.ndarray(shape=(rows, 3))
28   cur_ref = np.ndarray(shape=(rows / 2, 3))
29
30   for i in range(0, rows):
31     pwmen = pwm_en[zero_rows + i, :]
32     pwmv = np.multiply(pwm_val[zero_rows + i, :], pwmen)
33     pwmcent = np.sum(pwmv) / np.sum(pwmen)
34     pwmv = np.multiply(pwmv - pwmcent, pwmen)
35     cur_refall[i, :] = pwmv
36
37   for i in range(0, rows / 2):
38     cur_resp[i, :] = (cur_zerob[2 * i, :] - cur_zerob[2 * i + 1, :]) / 2.0
39     cur_resid[2 * i, :] = cur_zerob[2 * i, :] - cur_resp[i, :]
40     cur_resid[2 * i + 1, :] = cur_zerob[2 * i + 1, :] + cur_resp[i, :]
41     cur_ref[i, :] = (cur_refall[2 * i, :] - cur_refall[2 * i + 1, :]) / 2.0
42
43   print cur_zerob
44   print cur_resid
45   #print cur_resp
46   #print cur_ref
47
48   Y = cur_ref.T
49   U = cur_resp.T
50   C = np.dot(Y, linalg.inv(U))
51
52   print C
53   print Y
54   print np.dot(C, U)
55   for i in range(0, rows):
56     #print cur_zerob[i, :]
57     print np.dot(C, cur_zerob[i, :].T)