[docs]classPhotodiode(Component,Measurable):"""Abstract class to represent a photodiode as a device to measure light power """def__init__(self,*args,**kwargs):Component.__init__(self,*args,**kwargs)Measurable.__init__(self,["power"])
@kerneldef_measure(self)->TFloat:raiseNotImplementedError("Implement get_power for your photodiode "+self.identifier)
[docs]classAnalogPhotodiode(Photodiode):"""An analog photodiode that gives a voltage proportional to the incidend light power. Args: adc_channel: The ADC channel that reads the analog voltage of the photodiode """kernel_invariants={"adc_channel"}def__init__(self,adc_channel:ADCChannel,*args,**kwargs):Photodiode.__init__(self,*args,**kwargs)self.adc_channel=adc_channel
[docs]classCalibratedPhotodiode(AnalogPhotodiode):"""An analog photodiode with a power calibration Args: adc_channel: The ADC channel that reads the analog voltage of the photodiode calibration: calibration of the photodiode """kernel_invariants={"calibration"}def__init__(self,calibration:Calibration,*args,**kwargs):AnalogPhotodiode.__init__(self,*args,**kwargs)self.calibration=calibration@kerneldef_measure(self,samples:TInt32=1,cached:TBool=False)->TFloat:""" Get the power incident to the photodiode. Args: samples: number of samples to take and average before returning the result (default 1) cached: If true, the result of the last measurement is returned, otherwise new measurements are taken (default False) Returns: TFloat: Result of the measurement (possibly averaged over several samples) """returnself.calibration.transform(self.adc_channel.measure(samples=samples,cached=cached))