Beispiel #1
0
    def start(self):
        insertDebugLog(NOTICE, "Starting. Runtime: %ds, Actuate time: %ds, Max strain: %d, Sampling Freq: %d." % \
            (self.max_time, self.actuate_time, self.max_loadcell, \
             self.heater_period), PAYLOAD, int(time.time()))
        print("Starting payload...")
        print("Runtime: %ds, Actuate time: %ds, Max strain: %d, Sampling period: %ds" % \
            (self.max_time, self.actuate_time, self.max_loadcell, \
             self.heater_period))

        if not self.check_initial_conditions():
            return False
        self.lock.acquire()
        self.set_power(True)
        self.init_sensors()
        start_time = time.time()
        elapsed = 0
        while True:
            heater_temp = 0
            if elapsed <= self.actuate_time or heater_temp < self.max_temp:
                self.set_heaters(self.experiment, True)
                time.sleep(self.heater_period)
            else:
                print("No longer turning heaters on")
                time.sleep(self.heater_period)
                self.set_heaters(self.experiment, False)
            self.set_heaters(self.experiment, False)
            elapsed = time.time() - start_time
            off_time = time.time()
            print("[" + str(round(elapsed, 3)) + " s] ", end='')
            strain, force, adc_temp = SensorManager.read_adc(self.experiment, ADC)
            heater_temp = SensorManager.read_temp_sensor(self.temp_sensor)
            print(strain, force, adc_temp, heater_temp)
            sleep_time = time.time() - off_time
            elapsed = time.time() - start_time
            time.sleep(abs(self.heater_period - sleep_time))
            elapsed = time.time() - start_time
            strain, force, adc_temp = SensorManager.read_adc(self.experiment, ADC)
            heater_temp = SensorManager.read_temp_sensor(self.temp_sensor)
            print("[" + str(round(elapsed, 3)) + " s] ", end='')
            print(strain, force, adc_temp, heater_temp)

            if self.is_end_condition(strain, elapsed):
                break
        if self.experiment:
            exp = 'B'
        else:
            exp = 'A'
        insertPayloadLog(int(start_time), int(time.time()), exp)
        self.end()
        self.lock.release()
        return True
Beispiel #2
0
def main():
    SensorManager.gpio_output(PAYLOAD_EN_GPIO, ON)
    SensorManager.init_adc(ADC)
    start_time = time.time()
    try:
        while True:
            strain, force, adc_temp = SensorManager.read_adc(0, ADC)
            elapsed = time.time() - start_time
            print("[" + str(round(elapsed, 3)) + " s] ")
            print(strain, force, adc_temp)
            time.sleep(2)
    except KeyboardInterrupt:
        SensorManager.stop_adc_sensor(ADC)
        SensorManager.gpio_output(PAYLOAD_EN_GPIO, OFF)
Beispiel #3
0
 def test_adc_read(self):
     experiment = 2
     strain, force, adc_temp = SensorManager.read_adc(experiment, ADC)
     self.assertNotEqual(strain, -1)
     self.assertNotEqual(force, -1)
     self.assertNotEqual(adc_temp, -1)