forked from harvie256/MaynuoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattery_discharge_test.py
55 lines (44 loc) · 1.61 KB
/
Battery_discharge_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#-------------------------------------------------------------------------------
# Name: Battery constant power discharge test script
# Purpose:
#
# Author: Derryn Harvie
#
# Created: 16/04/2014
# Licence: Public Domain
#-------------------------------------------------------------------------------
import Maynuo, time, sys
dischargePower = 2.5
stopVoltage = 3.1
stepDelayTime = 0.5
filename = "C:/temp/testFile.csv"
def getMillis():
return int(round(time.time() * 1000))
def main():
def printAndWrite(fileToWrite, string):
fileToWrite.write(string + '\n')
print(string)
f = open(filename, 'w')
load = Maynuo.Maynuo(19,57600,1)
load.setCPower(dischargePower)
load.setInputOn()
endMillis = startMillis = getMillis()
printAndWrite(f, 'Battery discharge Test @ ' + str(dischargePower))
printAndWrite(f, 'Time (ms), Voltage (V), Current (A)')
while(1):
# get the operating point and write out
opPoint = load.getOperatingPoint()
currentMillis = getMillis() - startMillis
printAndWrite(f, str(currentMillis) + ', ' + "{0:.4f}".format(opPoint.getVoltage()) + ', ' + "{0:.4f}".format(opPoint.getCurrent()))
# test the voltage for the battery cutout voltage
if(opPoint.getVoltage() < stopVoltage):
endMillis = currentMillis
break
time.sleep(stepDelayTime)
load.setInputOff()
print("*** Battery test complete ***")
power = dischargePower * (endMillis/ (1000.0 * 60 * 60))
print("Total power = " + "{0:.4f}".format(power) + 'Wh')
f.close()
if __name__ == '__main__':
main()