Skip to content

Commit

Permalink
Merge branch 'main' of github.com:misko/spf
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Feb 24, 2024
2 parents b1a0213 + 4c10e8b commit a01707f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 80 deletions.
111 changes: 39 additions & 72 deletions spf/grbl_sdr_collect_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
plot_recv_signal,
setup_rx,
setup_rxtx,
setup_rxtx_and_phase_calibration,
shutdown_radios,
)
from spf.wall_array_v2 import v2_column_names
Expand Down Expand Up @@ -298,67 +297,6 @@ def grbl_thread_runner(gm, routine):

time.sleep(0.1)

# get radios online
receiver_pplus = {}
pplus_rx, pplus_tx = (None, None)
for receiver in yaml_config["receivers"]:
if run_collection:
rx_config = ReceiverConfig(
lo=receiver["f-carrier"],
rf_bandwidth=receiver["bandwidth"],
sample_rate=receiver["f-sampling"],
gains=[receiver["rx-gain"], receiver["rx-gain"]],
gain_control_modes=[receiver["rx-gain-mode"], receiver["rx-gain-mode"]],
enabled_channels=[0, 1],
buffer_size=receiver["buffer-size"],
intermediate=receiver["f-intermediate"],
uri="ip:%s" % receiver["receiver-ip"],
rx_spacing=receiver["antenna-spacing-m"],
rx_theta_in_pis=receiver["theta-in-pis"],
motor_channel=receiver["motor_channel"],
rx_buffers=receiver["rx-buffers"],
)
if "emitter-ip" in receiver:
tx_config = EmitterConfig(
lo=receiver["f-carrier"],
rf_bandwidth=receiver["bandwidth"],
sample_rate=receiver["f-sampling"],
intermediate=receiver["f-intermediate"],
gains=[-30, -80],
enabled_channels=[0],
cyclic=True,
uri="ip:%s" % receiver["emitter-ip"],
)
if args.skip_phase_calibration or (
"skip_phase_calibration" in yaml_config
and yaml_config["skip_phase_calibration"]
):
pplus_rx, pplus_tx = setup_rxtx(
rx_config=rx_config, tx_config=tx_config
)
else:
pplus_rx, pplus_tx = setup_rxtx_and_phase_calibration(
rx_config=rx_config,
tx_config=tx_config,
n_calibration_frames=yaml_config["calibration-frames"],
)
else:
assert args.skip_phase_calibration or (
"skip_phase_calibration" in yaml_config
and yaml_config["skip_phase_calibration"]
)
# there is no emitter to setup, its already blasting
pplus_rx = setup_rx(rx_config=rx_config)

if pplus_rx is None:
logging.info("Failed to bring RXTX online, shuttingdown")
run_collection = False
break
else:
logging.debug("RX online!")
receiver_pplus[pplus_rx.uri] = pplus_rx
assert pplus_rx.rx_config.rx_pos is not None

target_yaml_config = yaml_config["emitter"]
if run_collection and target_yaml_config["type"] == "sdr":
# setup the emitter
Expand Down Expand Up @@ -388,18 +326,47 @@ def grbl_thread_runner(gm, routine):
motor_channel=target_yaml_config["motor_channel"],
)

if target_rx_config.uri not in receiver_pplus:
setup_rxtx(
rx_config=target_rx_config, tx_config=target_tx_config, leave_tx_on=True
pplus_rx, _ = setup_rxtx(
rx_config=target_rx_config, tx_config=target_tx_config, leave_tx_on=True
)
pplus_rx.close_rx()

# get radios online
receiver_pplus = {}
pplus_rx, pplus_tx = (None, None)
for receiver in yaml_config["receivers"]:
if run_collection:
rx_config = ReceiverConfig(
lo=receiver["f-carrier"],
rf_bandwidth=receiver["bandwidth"],
sample_rate=receiver["f-sampling"],
gains=[receiver["rx-gain"], receiver["rx-gain"]],
gain_control_modes=[receiver["rx-gain-mode"], receiver["rx-gain-mode"]],
enabled_channels=[0, 1],
buffer_size=receiver["buffer-size"],
intermediate=receiver["f-intermediate"],
uri="ip:%s" % receiver["receiver-ip"],
rx_spacing=receiver["antenna-spacing-m"],
rx_theta_in_pis=receiver["theta-in-pis"],
motor_channel=receiver["motor_channel"],
rx_buffers=receiver["rx-buffers"],
)
else:
logging.info(f"Re-using {target_rx_config.uri} as RX for TX")
setup_rxtx(
rx_config=target_rx_config,
tx_config=target_tx_config,
leave_tx_on=True,
provided_pplus_rx=receiver_pplus[target_rx_config.uri],
assert "emitter-ip" not in receiver
assert args.skip_phase_calibration or (
"skip_phase_calibration" in yaml_config
and yaml_config["skip_phase_calibration"]
)
# there is no emitter to setup, its already blasting
pplus_rx = setup_rx(rx_config=rx_config)

if pplus_rx is None:
logging.info("Failed to bring RXTX online, shuttingdown")
run_collection = False
break
else:
logging.debug("RX online!")
receiver_pplus[pplus_rx.uri] = pplus_rx
assert pplus_rx.rx_config.rx_pos is not None

# setup GRBL
gm = None
Expand Down
16 changes: 10 additions & 6 deletions spf/sdrpluto/sdr_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ def close(self):
logging.info(f"{self.uri}: Done close PlutoPlus")

def __del__(self):
logging.debug(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_destroy_buffer()
# self.sdr.rx_destroy_buffer()
self.sdr.tx_enabled_channels = []
logging.debug(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 @@ -231,8 +231,9 @@ def close_tx(self):
self.sdr.tx_hardwaregain_chan1 = -80
self.sdr.tx_enabled_channels = []
self.sdr.tx_destroy_buffer()
self.sdr.tx_cyclic_buffer = False
self.tx_config = None
time.sleep(1.0)
# time.sleep(1.0)

def close_rx(self):
self.rx_config = None
Expand Down Expand Up @@ -418,6 +419,10 @@ def setup_rxtx(rx_config, tx_config, leave_tx_on=False, provided_pplus_rx=None):
else:
pplus_rx = provided_pplus_rx
time.sleep(1)
# get RX and drop it
for _ in range(400):
pplus_rx.sdr.rx()

while run_radios and retries < 15:
logging.info(f"setup_rxtx({rx_config.uri}, {tx_config.uri}) retry {retries}")
# sdr_rx = adi.ad9361(uri=receiver_uri)
Expand Down Expand Up @@ -764,4 +769,3 @@ def plot_recv_signal(
logging.info(f"{emitter_uri}: Emitter online verified by {receiver_uri}")
# apply the previous calibration
time.sleep(1800)

2 changes: 0 additions & 2 deletions spf/v2_configs/wall_array_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ emitter:
# multiples of pi
receivers:
- receiver-ip: 192.168.1.17
emitter-ip: 192.168.1.15
theta-in-pis: -0.25
antenna-spacing-m: 0.05075 # 50.75 mm
nelements: 2
Expand All @@ -38,7 +37,6 @@ receivers:
bandwidth: 300000 #3.0e5
motor_channel: 0
- receiver-ip: 192.168.1.18
emitter-ip: 192.168.1.15
theta-in-pis: 1.25
antenna-spacing-m: 0.05075 # 50.75 mm
nelements: 2
Expand Down

0 comments on commit a01707f

Please sign in to comment.