From 754f550651d3038b9d16343e212d6e7931bb5767 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Sat, 14 Jun 2014 20:31:51 +0900 Subject: [PATCH] balloon_strategy: integrate background image capture --- scripts/balloon_strategy.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/balloon_strategy.py b/scripts/balloon_strategy.py index c21058b..d3b76f7 100644 --- a/scripts/balloon_strategy.py +++ b/scripts/balloon_strategy.py @@ -102,8 +102,9 @@ def __init__(self): # use the simulator to generate fake balloon images self.use_simulator = balloon_config.config.get_boolean('general','simulate',False) + # start background image grabber if not self.use_simulator: - self.camera = balloon_video.get_camera() + balloon_video.start_background_capture() self.writer = balloon_video.open_video_writer() # horizontal velocity pid controller. maximum effect is 10 degree lean @@ -291,10 +292,10 @@ def get_frame(self): veh_pos = PositionVector.get_from_location(self.vehicle.location) frame = balloon_sim.get_simulated_frame(veh_pos, self.vehicle.attitude.roll, self.vehicle.attitude.pitch, self.vehicle.attitude.yaw) else: - _, frame = self.camera.read() + frame = balloon_video.get_image() return frame - # get image from camera and look for balloon, results are held in the following variables: + # get image from balloon_video class and look for balloon, results are held in the following variables: # self.balloon_found : set to True if balloon is found, False otherwise # self.balloon_pitch : earth frame pitch (in radians) from vehicle to balloon (i.e. takes account of vehicle attitude) # self.balloon_heading : earth frame heading (in radians) from vehicle to balloon @@ -484,13 +485,13 @@ def run(self): # only process images once home has been initialised if self.check_home(): - + # check if we are controlling the vehicle self.check_status() # look for balloon in image self.analyze_image() - + # search or move towards balloon if self.searching: # search for balloon @@ -498,11 +499,12 @@ def run(self): else: # move towards balloon self.move_to_balloon() - + # Don't suck up too much CPU, only process a new image occasionally time.sleep(0.05) - self.camera.release() + if not self.use_simulator: + balloon_video.stop_background_capture() # complete - balloon strategy has somehow completed so return control to the autopilot def complete(self):