Skip to content

Commit 700f37f

Browse files
Ian Dobbieiandobbie
authored andcommitted
Picamera fixes and updates, fixes issue #286
2 parents 231c5a7 + 751e37f commit 700f37f

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

NEWS.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,23 @@ Version 0.7.0 (upcoming)
3232
with the related get/set methods. The setting was been removed.
3333

3434
* New :class:`ValueLogger <microscope.abc.ValueLogger>` ABC for
35-
devices with a series of sensors.
35+
devices with a series of sensors. Simulation and Raspberry Pi
36+
implementations for MCP9808 and TSYS01 temparture sensors.
3637

37-
* New :class:`DigitalIO <microscope.abc.DigitalIO>` ABC.
38+
* New :class:`DigitalIO <microscope.abc.DigitalIO>` ABC. Added
39+
simulation device and Raspberry Pi implmentation.
3840

3941
* New devices supported:
4042

43+
* ASI MS 2000 controller (:class:`microscope.controllers.asi.ASIMS2000`)
44+
45+
* RaspberryPi as a valuelogger (:class:`microscope.valuelogger.RPiValueLogger`)
46+
4147
* RaspberryPi as Digital IO (:class:`microscope.digitalio.raspberrypi.RPiDIO`)
4248

4349
* Hamamatsu cameras (:class:`microscope.cameras.hamamatsu.HamamatsuCamera`)
4450

45-
* Ludl MC 2000 (:class:`microscope.controllers.ludl.LudlMC2000`)
51+
* Ludl MC 2000 controller (:class:`microscope.controllers.ludl.LudlMC2000`)
4652

4753
* RaspberryPi camera (:class:`microscope.cameras.picamera.PiCamera`)
4854

doc/architecture/supported-devices.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Cameras
2626
Controllers
2727
===========
2828

29+
- ASI MS2000 (:class:`microscope.controllers.asi.ASIMS2000`)
2930
- CoolLED (:class:`microscope.controllers.coolled.CoolLED`)
3031
- Ludl MC 2000 (:class:`microscope.controllers.ludl.LudlMC2000`)
3132
- Lumencor Spectra III light engine

microscope/cameras/picamera.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ def HW_trigger(self, channel):
131131
"""Function called by GPIO interupt, needs to trigger image capture"""
132132
with picamera.array.PiYUVArray(self.camera) as output:
133133
self.camera.capture(output, format="yuv", use_video_port=False)
134-
self._queue.put(output.array[:, :, 0])
134+
self._queue.put(
135+
output.array[
136+
self.roi.top : self.roi.top + self.roi.height,
137+
self.roi.left : self.roi.left + self.roi.width,
138+
0,])
135139

136140
def _fetch_data(self):
137141
if self._queue.qsize() is not 0:
@@ -161,7 +165,7 @@ def initialize(self):
161165
self.set_awb_mode(0) # set auto white balance to off
162166
self._get_sensor_shape()
163167
#default to full image at init.
164-
self._set_roi(ROI(0, 0, self.self.camera.resolution.width,
168+
self._set_roi(ROI(0, 0, self.camera.resolution.width,
165169
self.camera.resolution.height))
166170

167171

@@ -239,6 +243,13 @@ def setLED(self, state=False):
239243
GPIO.output(GPIO_CAMLED, state)
240244

241245
def set_exposure_time(self, value):
246+
# frame rate has to be adjusted as well as max exposure time is
247+
# 1/framerate.
248+
#picam v1.3 I have has limit 1/6 to 90 fps
249+
#exposure time can be shorter than frame rate bound but not longer
250+
value = min(value, 6.0)
251+
fr = max(value, 1.0/90.0)
252+
self.set_framerate(1.0/fr)
242253
# exposure times are set in us.
243254
self.camera.shutter_speed = int(value * 1.0e6)
244255

@@ -249,8 +260,21 @@ def get_exposure_time(self):
249260
def get_cycle_time(self):
250261
# fudge to make it work initially
251262
# exposure times are in us, so multiple by 1E-6 to get seconds.
252-
return self.camera.exposure_speed * 1.0e-6 + 0.1
263+
# pi 4 camera module v 1.3 minimum reliable time to capture and
264+
# download a frame appears to be .7 s.
265+
return self.camera.exposure_speed * 1.0e-6 + 0.7
253266

267+
268+
def get_framerate(self):
269+
return(float(self.camera.framerate))
270+
271+
272+
def set_framerate(self, rate):
273+
# rate= max (rate, self.camera.framerate_range.low)
274+
# rate= min (rate, self.camera.framerate_range.high)
275+
self.camera.framerate = rate
276+
return(float(self.camera.framerate))
277+
254278
def _get_sensor_shape(self):
255279
if self.camversion == "ov5647": # picam version 1
256280
self.camera.resolution = (2592, 1944)
@@ -292,7 +316,9 @@ def soft_trigger(self):
292316
# should be able to use rotation and hflip to set specific output image
293317
# rotations
294318

295-
# roi's can be set with the zoom function, default is (0,0,1,1) meaning all the data.
319+
# roi's can be set with the zoom function, default is (0,0,1,1)
320+
# meaning all the data. However this is no help as the grab is still
321+
# just as slow
296322

297323
# Need to setup a buffer for harware triggered data aquisition so we can
298324
# call the acquisition and then download the data at our leasure

0 commit comments

Comments
 (0)