def update( self ): while not self.statusQueue.empty(): statusData = self.statusQueue.get_nowait() if statusData[ 0 ] == "s": sensorReadingTimestamp = statusData[ 1 ] self.sensorConfiguration = statusData[ 2 ] self.batteryVoltageReading = sensors.SensorReading( statusData[ 3 ], sensorReadingTimestamp ) self.digitalReadings = sensors.SensorReading( statusData[ 4 ], sensorReadingTimestamp ) self.analogReadings = sensors.SensorReading( statusData[ 5 ], sensorReadingTimestamp ) self.ultrasonicReading = sensors.SensorReading( statusData[ 6 ], sensorReadingTimestamp ) self.encodersReading = sensors.SensorReading( ( statusData[ 7 ], statusData[ 8 ] ), sensorReadingTimestamp )
def __init__( self, serialPortName, baudRate ): self.serialPort = serial.Serial( serialPortName, baudRate, timeout=0 ) self.responseQueue = Queue.Queue() self.statusQueue = Queue.Queue() self.serialReadProcess = SerialReadProcess( self.serialPort, self.responseQueue, self.statusQueue ) self.serialReadProcess.start() self.sensorConfiguration = SensorConfiguration() self.batteryVoltageReading = sensors.SensorReading( 0.0 ) self.digitalReadings = sensors.SensorReading( 0 ) self.analogReadings = sensors.SensorReading( [0] * NUM_ANALOG_PINS ) self.ultrasonicReading = sensors.SensorReading( 0 ) self.encodersReading = sensors.SensorReading( ( 0, 0 ) ) time.sleep( self.STARTUP_DELAY )
def getBatteryVoltageReading(self): """:return: A :py:class:`SensorReading` containing the most recent battery voltage read from the Mini Driver as a float :rtype: :py:class:`SensorReading`""" result = sensors.SensorReading(0.0) if self.connection != None: result = self.connection.getBatteryVoltageReading() return result
def getEncodersReading(self): """:return: A :py:class:`SensorReading` containing the most recent reading from the Mini Driver encoders. :rtype: :py:class:`SensorReading`""" result = sensors.SensorReading((0, 0)) if self.connection != None: result = self.connection.getEncodersReading() return result
def getAnalogReadings(self): """:return: A :py:class:`SensorReading` containing the most recent set of analog readings read from the Mini Driver. There are 6 analog pins that can be read on the Mini Driver and so the :py:class:`SensorReading` contains a list of 6 floats. :rtype: :py:class:`SensorReading`""" result = sensors.SensorReading([0] * NUM_ANALOG_PINS) if self.connection != None: result = self.connection.getAnalogReadings() return result
def getUltrasonicReading(self): """:return: A :py:class:`SensorReading` containing the most recent ultrasonic distance reading from the Mini Driver. The distance is in centimetres and the maximum range is MAX_ULTRASONIC_RANGE_CM. If it looks as if no ultrasonic sensor is attached then NO_ULTRASONIC_SENSOR_PRESENT will be set as the distance. :rtype: :py:class:`SensorReading`""" result = sensors.SensorReading(0) if self.connection != None: result = self.connection.getUltrasonicReading() return result
def getDigitalReadings(self): """:return: A :py:class:`SensorReading` containing the most recent set of digital readings read from the Mini Driver. The digital readings are returned as a byte with the bits corresponding to the digital readings from the following pins pin A5 | A4 | A3 | A2 | A1 | A0 | D13 | D12 bit 7 0 :rtype: :py:class:`SensorReading`""" result = sensors.SensorReading(0) if self.connection != None: result = self.connection.getDigitalReadings() return result