Skip to content

Commit

Permalink
leave in ability for image_down to work standalone, and fix exception…
Browse files Browse the repository at this point in the history
… logging
  • Loading branch information
EricPedley committed Jun 26, 2024
1 parent 3a91b97 commit 713895b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions uavf_2024/imaging/perception.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def wrapped_fn(self,*args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception:
self.get_logger().error(traceback.format_exc())
self.log(traceback.format_exc())
return wrapped_fn

class Perception:
Expand Down Expand Up @@ -169,12 +169,12 @@ def get_image_down_async(self) -> Future[list[Target3D]]:
"""

self.log("Received Down Image Request")
self.camera.request_autofocus()
if not self.recording:
self.recording = True
self.camera.start_recording()
img = self.camera.get_latest_image()
timestamp = time.time()
self.log(f"Got image from Camera at time {timestamp}")
return self.processor_pool.submit(self.get_image_down, img, timestamp)

def _log_image_down(
Expand Down Expand Up @@ -213,7 +213,7 @@ def _log_image_down(
json.dump(log_data, open(f"{logs_folder}/data.json", 'w+'), indent=4)

@log_exceptions
def get_image_down(self, img, timestamp) -> list[Target3D]:
def get_image_down(self, img=-1, timestamp=None) -> list[Target3D]:
"""
Blocking implementation of the infrence pipeline.
Expand All @@ -222,16 +222,21 @@ def get_image_down(self, img, timestamp) -> list[Target3D]:
We want to take photo when the attitude is down only.
"""

if img == -1:
self.camera.request_autofocus()
img = self.camera.get_latest_image()
timestamp = time.time()
self.log(f"Got image with timestamp {timestamp}")

if img is None:
self.log("Could not get image from Camera.")
return []
self.camera.request_autofocus()
self.log(f"Got past autofocus")

self.pose_provider.wait_for_data()
self.log(f"Got past pose provider wait")

if abs(self.camera.getAttitude()[1] - -90) > 5: # Allow 5 degrees of error (Arbitrary)
self.point_camera_down()
self.camera.request_down()
self.log(f"Got past point down")

#TODO: Figure out a way to detect when the gimbal is having an aneurism and figure out how to fix it or send msg to groundstation.
Expand Down

0 comments on commit 713895b

Please sign in to comment.