-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrent.py
35 lines (30 loc) · 1007 Bytes
/
Current.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
from saleae.range_measurements import AnalogMeasurer
import numpy as np
from numpy import trapz
class Current(AnalogMeasurer):
supported_measurements = ["area"]
"""
Class initialisation
"""
def __init__(self, requested_measurements):
super().__init__(requested_measurements)
self.batches = []
"""
Does not process data. Simply attaches
samples to be processed later.
"""
def process_data(self, data):
self.batches.append(data.samples)
"""
Calculates Average Voltage and Divide by 5.6 Ohm Resistor.
"""
def measure(self):
data = np.concatenate(self.batches)
averageVoltage = np.mean(data)
averageCurrent = averageVoltage / 18
maxVoltage = np.amax(data)
maxCurrent = maxVoltage / 18
return {"Iavg" : round(averageCurrent,6),
"Vavg": round(averageVoltage,6),
"Vmax" : round(maxVoltage,6),
"Imax" : round(maxCurrent,6)}