diff --git a/utils/plotter/adc_muxed_data_live_plotter_main.py b/utils/plotter/adc_muxed_data_live_plotter_main.py index 587e751..235612d 100644 --- a/utils/plotter/adc_muxed_data_live_plotter_main.py +++ b/utils/plotter/adc_muxed_data_live_plotter_main.py @@ -19,10 +19,13 @@ def _parse_adc_data(read_data: str, num_sensors: int) -> tuple[float]: # The OpenMote prints (sequence number, channel, coarse code, medium # code, fine code, ADC output for each sensor, RSSI). adc_output = read_data.split(" ")[5:5 + num_sensors] - return [float(data) for data in adc_output] + adc_output_float = [float(data) for data in adc_output] + for i in range(2, num_sensors): + adc_output_float[i] /= 16384 + return adc_output_float except: logging.error("Failed to parse ADC data.") - return [0] * num_sensorss + return [0] * num_sensors def main(argv): @@ -34,11 +37,15 @@ def main(argv): FLAGS.max_duration, lambda read_data: _parse_adc_data(read_data, FLAGS.num_sensors), num_traces=FLAGS.num_sensors, + secindices=list(range(2, FLAGS.num_sensors)), title="ADC data", xlabel="Time [s]", ylabel="ADC output [LSB]", ymin=0, - ymax=512) + ymax=512, + secylabel="Time constant [s]", + secymin=0, + secymax=1) plotter.run() diff --git a/utils/plotter/live_plotter.py b/utils/plotter/live_plotter.py index b4f536c..6b4bb82 100644 --- a/utils/plotter/live_plotter.py +++ b/utils/plotter/live_plotter.py @@ -23,7 +23,11 @@ def __init__(self, xmax: float, ymin: float, ymax: float, - num_traces: int = 1) -> None: + num_traces: int = 1, + secindices: tuple[int] = None, + secylabel: str = None, + secymin: float = None, + secymax: float = None) -> None: self.num_traces = num_traces self.xmax = xmax @@ -35,6 +39,10 @@ def __init__(self, self.ax.set_ylabel(ylabel) self.ax.set_xlim((0, xmax)) self.ax.set_ylim((ymin, ymax)) + if secindices is not None: + self.secax = self.ax.twinx() + self.secax.set_ylabel(secylabel) + self.secax.set_ylim((secymin, secymax)) # Initialize the data and the traces. If the live plot is continuous, # the x-axis is the time in seconds. Otherwise, the x-axis is the @@ -42,8 +50,19 @@ def __init__(self, self.x = np.zeros(1) self.y = np.zeros((1, num_traces)) self.data_lock = Lock() - self.traces = self.ax.plot(self.x, self.y) - self.ax.legend([f"Trace {i + 1}" for i in range(num_traces)]) + self.traces = [] + for i in range(num_traces): + args = { + "color": f"C{i}", + "marker": "^", + "label": f"Trace {i}", + } + if secindices is None or i not in secindices: + trace, = self.ax.plot(self.x, self.y[:, i], **args) + else: + trace, = self.secax.plot(self.x, self.y[:, i], **args) + self.traces.append(trace) + self.ax.legend(handles=self.traces) # Create a thread for updating the data. self.data_thread = Thread(target=self._update_data) @@ -121,9 +140,22 @@ def __init__(self, ylabel: str, ymin: float, ymax: float, - num_traces: int = 1) -> None: - super().__init__(title, xlabel, ylabel, max_num_points, ymin, ymax, - num_traces) + num_traces: int = 1, + secindices: tuple[int] = None, + secylabel: str = None, + secymin: float = None, + secymax: float = None) -> None: + super().__init__(title, + xlabel, + ylabel, + max_num_points, + ymin, + ymax, + num_traces=num_traces, + secindices=secindices, + secylabel=secylabel, + secymin=secymin, + secymax=secymax) def next_data(self) -> tuple[float, float | tuple[float]]: """Returns the next data to plot. @@ -148,9 +180,22 @@ def __init__(self, ylabel: str, ymin: float, ymax: float, - num_traces: int = 1) -> None: - super().__init__(title, xlabel, ylabel, max_duration, ymin, ymax, - num_traces) + num_traces: int = 1, + secindices: tuple[int] = None, + secylabel: str = None, + secymin: float = None, + secymax: float = None) -> None: + super().__init__(title, + xlabel, + ylabel, + max_duration, + ymin, + ymax, + num_traces=num_traces, + secindices=secindices, + secylabel=secylabel, + secymin=secymin, + secymax=secymax) self.last_data_time = 0 def next_data(self) -> tuple[float, float | tuple[float]]: diff --git a/utils/plotter/serial_live_plotter.py b/utils/plotter/serial_live_plotter.py index b58cf39..4e120b6 100644 --- a/utils/plotter/serial_live_plotter.py +++ b/utils/plotter/serial_live_plotter.py @@ -21,9 +21,22 @@ def __init__(self, ylabel: str, ymin: float, ymax: float, - num_traces: int = 1) -> None: - super().__init__(max_duration, title, xlabel, ylabel, ymin, ymax, - num_traces) + num_traces: int = 1, + secindices: tuple[int] = None, + secylabel: str = None, + secymin: float = None, + secymax: float = None) -> None: + super().__init__(max_duration, + title, + xlabel, + ylabel, + ymin, + ymax, + num_traces=num_traces, + secindices=secindices, + secylabel=secylabel, + secymin=secymin, + secymax=secymax) self.parse_data = parse_data # Open the serial port.