Skip to content

Commit

Permalink
various fixes for wall array v2
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Jan 7, 2024
1 parent e5b77f1 commit c429d48
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"flake8.args": [
"--max-line-length=120",
"--ignore=E203"
]
],
"notebook.formatOnSave.enabled": true
}
19 changes: 0 additions & 19 deletions spf/dataset/spf_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,6 @@ def __getitem__(self, idx):
}


class SessionsDatasetTask1(SessionsDataset):
def __getitem__(self, idx):
d = super().__getitem__(idx)
# featurie a really simple way
x = torch.Tensor(
np.hstack(
[
d["receiver_positions_at_t"].reshape(self.snapshots_in_sample, -1),
d["beam_former_outputs_at_t"].reshape(self.snapshots_in_sample, -1),
# d['signal_matrixs'].reshape(self.snapshots_in_sample,-1)
d["time_stamps"].reshape(self.snapshots_in_sample, -1)
- d["time_stamps"][0],
]
)
)
y = torch.Tensor(d["source_positions_at_t"][:, 0])
return x, y


def pos_to_rel(p, width):
return 2 * (p / width - 0.5)

Expand Down
4 changes: 3 additions & 1 deletion spf/grbl/grbl_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def bounce(self, start_p, n_bounces):
) * self.current_direction + percent_random * self.random_direction()
self.current_direction /= np.linalg.norm(self.current_direction)

for _ in range(n_bounces):
n_bounce = 0
while n_bounce < n_bounces or n_bounces == -1:
if not run_grbl:
logging.info("Exiting bounce early")
break
Expand All @@ -236,6 +237,7 @@ def bounce(self, start_p, n_bounces):
yield from to_points
start_p = to_points[-1]
self.current_direction = new_direction
n_bounce += 1
logging.info("Exiting bounce")


Expand Down
35 changes: 21 additions & 14 deletions spf/grbl_sdr_collect_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
setup_rxtx_and_phase_calibration,
shutdown_radios,
)
from spf.wall_array_v2 import get_column_names_v2

faulthandler.enable()

Expand Down Expand Up @@ -70,13 +71,14 @@ def signal_handler(sig, frame):


class ThreadedRX:
def __init__(self, pplus, time_offset):
def __init__(self, pplus, time_offse, nthetas):
self.pplus = pplus
self.read_lock = threading.Lock()
self.ready_lock = threading.Lock()
self.ready_lock.acquire()
self.run = False
self.time_offset = time_offset
self.nthetas = nthetas

def start_read_thread(self):
self.t = threading.Thread(target=self.read_forever)
Expand Down Expand Up @@ -109,6 +111,7 @@ def read_forever(self):
self.pplus.rx_config.rx_pos,
signal_matrix,
self.pplus.rx_config.intermediate,
spacing=self.nthetas,
)

avg_phase_diff = get_avg_phase(signal_matrix)
Expand Down Expand Up @@ -138,7 +141,7 @@ def bounce_grbl(gm):
while run_collection:
logging.info("TRY TO BOUNCE")
try:
direction = gm.bounce(100, direction=direction)
direction = gm.bounce(-1, direction=direction)
except Exception as e:
logging.error(e)
if not run_collection:
Expand Down Expand Up @@ -190,6 +193,19 @@ def bounce_grbl(gm):
with open(args.yaml_config, "r") as stream:
yaml_config = yaml.safe_load(stream)

# record matrix
column_names = get_column_names_v2(nthetas=yaml_config["n-thetas"])
record_matrix = np.memmap(
yaml_config["output-file"].replace("__DATE__", start_logging_at),
dtype="float32",
mode="w+",
shape=(
2, # TODO should be nreceivers
yaml_config["n-records-per-receiver"],
len(column_names),
), # t,tx,ty,rx,ry,rtheta,rspacing / avg1,avg2 / sds
)

logging.info(json.dumps(yaml_config, sort_keys=True, indent=4))

# lets open all the radios
Expand Down Expand Up @@ -236,15 +252,6 @@ def bounce_grbl(gm):
# leave_tx_on=False,
# using_tx_already_on=None,
)
pplus_rx.record_matrix = np.memmap(
receiver["output-file"],
dtype="float32",
mode="w+",
shape=(
yaml_config["n-records-per-receiver"],
7 + 2 + 65,
), # t,tx,ty,rx,ry,rtheta,rspacing / avg1,avg2 / sds
)
logging.info("RX online!")
receiver_pplus.append(pplus_rx)

Expand Down Expand Up @@ -293,7 +300,7 @@ def bounce_grbl(gm):
time_offset = time.time()
read_threads = []
for pplus_rx in receiver_pplus:
read_thread = ThreadedRX(pplus_rx, time_offset)
read_thread = ThreadedRX(pplus_rx, time_offset, nthetas=yaml_config["n-thetas"])
read_thread.start_read_thread()
read_threads.append(read_thread)

Expand All @@ -302,7 +309,7 @@ def bounce_grbl(gm):
if not run_collection:
logging.info("Breaking man loop early")
break
for read_thread in read_threads:
for read_thread_idx, read_thread in enumerate(read_threads):
while run_collection and not read_thread.ready_lock.acquire(timeout=0.5):
pass
###
Expand All @@ -316,7 +323,7 @@ def bounce_grbl(gm):
read_thread.pplus.rx_config.motor_channel
]

read_thread.pplus.record_matrix[record_index] = prepare_record_entry(
record_matrix[read_thread_idx, record_index] = prepare_record_entry(
ds=read_thread.data, rx_pos=rx_pos, tx_pos=tx_pos
)
###
Expand Down
Loading

0 comments on commit c429d48

Please sign in to comment.