Skip to content

Commit

Permalink
- tidied up some bugs
Browse files Browse the repository at this point in the history
- removed passing args to a function, gross.
- increased strip visualisation threshold to +50%
  • Loading branch information
TheMariday committed Oct 24, 2024
1 parent 6b9ca38 commit 8b732bf
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion marimapper/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def eat(self, count=30):
for _ in range(count):
self.read()

def read(self, color=False):
def read(self):
ret_val, image = self.device.read()
if not ret_val:
raise Exception("Failed to read image")
Expand Down
22 changes: 14 additions & 8 deletions marimapper/file_writer_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import time
from marimapper.file_tools import write_3d_leds_to_file, write_2d_leds_to_file
from pathlib import Path
import os

from marimapper.led import LED2D


class FileWriterProcess(Process):
Expand All @@ -14,6 +17,7 @@ def __init__(self, base_path: Path):
self._input_queue_3d.cancel_join_thread()
self._exit_event = Event()
self._base_path = base_path
os.makedirs(self._base_path, exist_ok=True)

def stop(self):
self._exit_event.set()
Expand All @@ -28,6 +32,7 @@ def get_new_filename(self) -> Path:
string_time = time.strftime("%Y%m%d-%H%M%S")
return self._base_path / f"led_map_2d_{string_time}.csv"

# This function is a bit gross and needs cleaning up
def run(self):
views = {}
view_id_to_filename = {}
Expand All @@ -37,21 +42,22 @@ def run(self):
while not self._exit_event.is_set():
if not self._input_queue_3d.empty():
leds = self._input_queue_3d.get()
write_3d_leds_to_file(leds, Path("led3d.csv"))
write_3d_leds_to_file(leds, self._base_path / "led_map_3d.csv")

if not self._input_queue_2d.empty():
led = self._input_queue_2d.get()
if led.view_id not in view_id_to_filename:
view_id_to_filename[led.view_id] = self.get_new_filename()
views[led.view_id] = []
led: LED2D = self._input_queue_2d.get()
if led.point is not None:
if led.view_id not in view_id_to_filename:
view_id_to_filename[led.view_id] = self.get_new_filename()
views[led.view_id] = []

views[led.view_id].append(led)
requires_update.add(led.view_id)
views[led.view_id].append(led)
requires_update.add(led.view_id)

else:
for view_id in requires_update:
write_2d_leds_to_file(views[view_id], view_id_to_filename[view_id])
requires_update = []
requires_update = set()
time.sleep(1)

# clear the queues, don't ask why.
Expand Down
28 changes: 18 additions & 10 deletions marimapper/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# FATAL WEIRD CRASH IF THIS ISN'T IMPORTED FIRST DON'T ASK
from marimapper.sfm_process import SFM

import os
from tqdm import tqdm
from pathlib import Path
from marimapper.detector_process import DetectorProcess
Expand All @@ -18,17 +17,26 @@

class Scanner:

def __init__(self, cli_args):
def __init__(
self,
output_dir: Path,
device: str,
exposure: int,
threshold: int,
backend: str,
server: str,
led_start: int,
led_end: int,
):
logger.debug("initialising scanner")
self.output_dir = Path(cli_args.dir)
os.makedirs(self.output_dir, exist_ok=True)
self.output_dir = output_dir

self.detector = DetectorProcess(
cli_args.device,
cli_args.exposure,
cli_args.threshold,
cli_args.backend,
cli_args.server,
device,
exposure,
threshold,
backend,
server,
)

self.sfm = SFM()
Expand Down Expand Up @@ -58,7 +66,7 @@ def __init__(self, cli_args):
self.file_writer.start()

self.led_id_range = range(
cli_args.start, min(cli_args.end, self.detector.get_led_count())
led_start, min(led_end, self.detector.get_led_count())
)

logger.debug("scanner initialised")
Expand Down
15 changes: 12 additions & 3 deletions marimapper/scripts/scanner_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import argparse
import logging
from marimapper.utils import add_camera_args, add_backend_args

from pathlib import Path

logger = log_to_stderr()
logger.setLevel(level=logging.ERROR)
Expand All @@ -21,7 +21,7 @@ def main():
parser.add_argument("-v", "--verbose", action="store_true")

parser.add_argument(
"--dir", type=str, help="The output folder for your capture", default="."
"--dir", type=Path, help="The output folder for your capture", default="."
)

args = parser.parse_args()
Expand All @@ -32,7 +32,16 @@ def main():
if args.verbose:
logger.setLevel(logging.DEBUG)

scanner = Scanner(cli_args=args)
scanner = Scanner(
args.dir,
args.device,
args.exposure,
args.threshold,
args.backend,
args.server,
args.start,
args.end,
)

scanner.mainloop()
scanner.close()
Expand Down
7 changes: 4 additions & 3 deletions marimapper/sfm_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def run(self):
while not self._exit_event.is_set():

if not self._input_queue.empty():
led = self._input_queue.get()
leds_2d.append(led)
update_required = True
led: LED2D = self._input_queue.get()
if led.point is not None:
leds_2d.append(led)
update_required = True

else:
if not update_required:
Expand Down
2 changes: 1 addition & 1 deletion marimapper/visualize_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def reload_geometry__(self, first=False):
for led_index, led in enumerate(leds):
next_led = get_next(led, leds)
if next_led is not None:
if get_distance(led, next_led) < 1.10: # + 10%
if get_distance(led, next_led) < 1.50: # + 50%
strips.append((led_index, leds.index(next_led)))

self.strip_set.lines = open3d.utility.Vector2iVector(strips)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ marimapper_check_camera = "marimapper.scripts.check_camera_cli:main"
marimapper_check_backend ="marimapper.scripts.check_backend_cli:main"
marimapper_upload_to_pixelblaze = "marimapper.scripts.upload_map_to_pixelblaze_cli:main"

# this currently does nothing because of path issues

[tool.coverage.run]
omit = [
"*/__init__.py",
Expand Down

0 comments on commit 8b732bf

Please sign in to comment.