From 753d91457a07a9f559c01353181641f6f68b371f Mon Sep 17 00:00:00 2001 From: klaute Date: Wed, 21 Sep 2016 18:07:56 +0200 Subject: [PATCH] Floating point operation fixed - previous calculation result type was integer. --- tools/meas.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/meas.py b/tools/meas.py index 7172576..8a94daa 100644 --- a/tools/meas.py +++ b/tools/meas.py @@ -8,6 +8,7 @@ import serial import copy import binascii import matplotlib.pyplot as plt +import math ############################################################################### @@ -488,7 +489,7 @@ if __name__ == "__main__": meas_r = [] meas_p = [] - i = ((drive_str + 1) * 2) / 1000 + i = ((drive_str + 1) * 2.0) / 1000.0 if args.output_file != None or args.show_graph == True: for m in meas_data: @@ -503,12 +504,12 @@ if __name__ == "__main__": meas_ratio.append(1) # R = meas_data[0] * 5V / 1023 * I - r = (m[1] * 5 / 1023) / i + r = (m[1] * 5.0 / 1023.0) / i meas_r.append(r) # P = meas_data[0] * 5V ^ 2 / r if r > 0: - meas_p.append(i**2 * r) + meas_p.append(math.pow(i, 2) * r) else: meas_p.append(0) @@ -519,8 +520,8 @@ if __name__ == "__main__": plt.plot(meas_freq, meas_ratio) plt.plot(meas_freq, meas_r) plt.plot(meas_freq, meas_p) + print meas_r - print meas_ratio print "Please close the mathplot window to exit..." plt.show()