Skip to content

Commit

Permalink
clean up logging; change from theta in pi to just theta
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Jan 7, 2024
1 parent c429d48 commit eb3afb7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
8 changes: 4 additions & 4 deletions spf/grbl_sdr_collect_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
setup_rxtx_and_phase_calibration,
shutdown_radios,
)
from spf.wall_array_v2 import get_column_names_v2
from spf.wall_array_v2 import v2_column_names

faulthandler.enable()

Expand All @@ -47,7 +47,7 @@ def prepare_record_entry(ds: DataSnapshot, rx_pos: np.array, tx_pos: np.array):
ds.timestamp, # 1
tx_pos, # 2
rx_pos, # 2
ds.rx_theta_in_pis, # 1
ds.rx_theta_in_pis * np.pi, # 1
ds.rx_spacing, # 1
ds.avg_phase_diff, # 2
ds.beam_sds, # 65
Expand Down Expand Up @@ -194,7 +194,7 @@ def bounce_grbl(gm):
yaml_config = yaml.safe_load(stream)

# record matrix
column_names = get_column_names_v2(nthetas=yaml_config["n-thetas"])
column_names = v2_column_names(nthetas=yaml_config["n-thetas"])
record_matrix = np.memmap(
yaml_config["output-file"].replace("__DATE__", start_logging_at),
dtype="float32",
Expand Down Expand Up @@ -252,7 +252,7 @@ def bounce_grbl(gm):
# leave_tx_on=False,
# using_tx_already_on=None,
)
logging.info("RX online!")
logging.debug("RX online!")
receiver_pplus.append(pplus_rx)

# setup the emitter
Expand Down
28 changes: 14 additions & 14 deletions spf/sdrpluto/sdr_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_pplus(rx_config=None, tx_config=None, uri=None):
pplus_online[uri] = PPlus(rx_config=rx_config, tx_config=tx_config, uri=uri)
else:
pplus_online[uri].set_config(rx_config=rx_config, tx_config=tx_config)
logging.info(f"{uri}: get_pplus PlutoPlus")
logging.debug(f"{uri}: get_pplus PlutoPlus")
return pplus_online[uri]


Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, rx_config=None, tx_config=None, uri=None):
self.sdr.tx_enabled_channels = []

def set_config(self, rx_config=None, tx_config=None):
logging.info(f"{self.uri} RX{str(rx_config)} TX{str(tx_config)})")
logging.debug(f"{self.uri}: set_config RX{str(rx_config)} TX{str(tx_config)})")
# RX should be setup like this
if rx_config is not None:
assert self.rx_config is None
Expand All @@ -94,17 +94,17 @@ def set_config(self, rx_config=None, tx_config=None):
self.tx_config = tx_config

def close(self):
logging.info(f"{self.uri}: Start close PlutoPlus")
logging.debug(f"{self.uri}: Start close PlutoPlus")
self.close_tx()
logging.info(f"{self.uri}: Done close PlutoPlus")
logging.debug(f"{self.uri}: Done close PlutoPlus")

def __del__(self):
logging.info(f"{self.uri}: Start delete PlutoPlus")
logging.debug(f"{self.uri}: Start delete PlutoPlus")
self.close_tx()
self.sdr.tx_destroy_buffer()
self.sdr.rx_destroy_buffer()
self.sdr.tx_enabled_channels = []
logging.info(f"{self.uri}: Done delete PlutoPlus")
logging.debug(f"{self.uri}: Done delete PlutoPlus")

"""
Setup the Rx part of the pluto
Expand Down Expand Up @@ -134,7 +134,7 @@ def setup_rx(self):
"""

def setup_tx(self):
logging.info(f"{self.tx_config.uri}: Setup TX")
logging.debug(f"{self.tx_config.uri}: Setup TX")
self.sdr.tx_destroy_buffer()
self.sdr.tx_cyclic_buffer = self.tx_config.cyclic # this keeps repeating!

Expand Down Expand Up @@ -308,13 +308,13 @@ def setup_rxtx(rx_config, tx_config, leave_tx_on=False):
logging.info(f"setup_rxtx({rx_config.uri}, {tx_config.uri}) retry {retries}")
# sdr_rx = adi.ad9361(uri=receiver_uri)
if rx_config.uri == tx_config.uri:
logging.info(f"{rx_config.uri} RX TX are same")
logging.debug(f"{rx_config.uri} RX TX are same")
pplus_rx = get_pplus(rx_config=rx_config, tx_config=tx_config)
pplus_tx = pplus_rx
else:
logging.info(f"{rx_config.uri}(RX) TX are different")
logging.debug(f"{rx_config.uri}(RX) TX are different")
pplus_rx = get_pplus(rx_config=rx_config)
logging.info(f"{tx_config.uri} RX (TX) are different")
logging.debug(f"{tx_config.uri} RX (TX) are different")
pplus_tx = get_pplus(tx_config=tx_config)

pplus_rx.setup_rx()
Expand Down Expand Up @@ -364,12 +364,12 @@ def setup_rxtx_and_phase_calibration(

# its important to not use the emitter uri when calibrating!
if using_tx_already_on is not None:
logging.info(f"{rx_config.uri}: TX already on!")
logging.debug(f"{rx_config.uri}: TX already on!")
pplus_rx = get_pplus(rx_config=rx_config)
pplus_rx.setup_rx()
pplus_tx = using_tx_already_on
else:
logging.info(f"{rx_config.uri}: TX not on!")
logging.debug(f"{rx_config.uri}: TX not on!")
pplus_rx, pplus_tx = setup_rxtx(
rx_config=rx_config, tx_config=tx_config, leave_tx_on=True
)
Expand All @@ -387,7 +387,7 @@ def setup_rxtx_and_phase_calibration(
)
retries = 0
while run_radios and retries < 20:
logging.info(f"{rx_config.uri} RETRY {retries}")
logging.debug(f"{rx_config.uri} RETRY {retries}")
phase_calibrations = np.zeros(n_calibration_frames)
phase_calibrations_cm = np.zeros(n_calibration_frames)
for idx in range(n_calibration_frames):
Expand Down Expand Up @@ -423,7 +423,7 @@ def setup_rxtx_and_phase_calibration(
pplus_rx.phase_calibration = phase_calibrations.mean()
return pplus_rx, pplus_tx
pplus_tx.close()
logging.info(f"{rx_config.uri}: Phase calibration failed")
logging.error(f"{rx_config.uri}: Phase calibration failed")
return None, None


Expand Down
29 changes: 27 additions & 2 deletions spf/wall_array_v2.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
from functools import cache

import numpy as np


def get_column_names_v2(nthetas=65):
def v2_column_names(nthetas=65):
thetas = np.linspace(-np.pi, np.pi, nthetas)
return [
"timestamp",
"tx_pos_x",
"tx_pos_y",
"rx_pos_x",
"rx_pos_y",
"rx_theta_in_pis",
"rx_theta",
"rx_spacing",
"avg_phase_diff_1",
"avg_phase_diff_2",
] + ["beamformer_angle_%0.4f" % theta for theta in thetas]


@cache
def v2_rx_pos_idxs():
return [
v2_column_names().index("rx_pos_x"),
v2_column_names().index("rx_pos_y"),
]


@cache
def v2_rx_theta_idxs():
return [
v2_column_names().index("rx_theta"),
]


@cache
def v2_tx_pos_idxs():
return [
v2_column_names().index("tx_pos_x"),
v2_column_names().index("tx_pos_y"),
]
2 changes: 1 addition & 1 deletion spf/wall_array_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ receivers:
motor_channel: 0


output-file: wallarrayv2___DATE___.npy
output-file: wallarrayv2___DATE__.npy
n-thetas: 65
n-records-per-receiver: 300000

Expand Down

0 comments on commit eb3afb7

Please sign in to comment.