Esempio n. 1
0
        self._cb.cancel()


if __name__ == "__main__":

    import time
    import pigpio
    import read_RPM

    RPM_GPIO = 22
    RUN_TIME = 60.0
    SAMPLE_TIME = 2.0

    pi = pigpio.pi()

    p = read_RPM.reader(pi, RPM_GPIO)

    start = time.time()

    #    while (time.time() - start) < RUN_TIME:
    while True:
        # time.sleep(SAMPLE_TIME)

        RPM = p.RPM()

        print("RPM={}".format(int(RPM + 0.5)))

        p.cancel()

        pi.stop()
Esempio n. 2
0
   import time
   import pigpio
   import read_RPM

   RPM_GPIO = 17
   RUN_TIME = 60.0
   SAMPLE_TIME = 2.0
   
   print("RPM GPIO= " + str(RPM_GPIO) + ", RUN_TIME= " + str(RUN_TIME) + ", SAMPLE_TIME= " + str(SAMPLE_TIME))


   
   pi = pigpio.pi()

   p = read_RPM.reader(pi, RPM_GPIO)

   print("min period " + str(p._min_period))
   
   start = time.time()

   while (time.time() - start) < RUN_TIME:

      time.sleep(SAMPLE_TIME)

      RPMstr = p.getUpdate()
     
      print('RPM= ' + RPMstr)

   p.cancel()
Esempio n. 3
0
def acquire_data(main_queue, killer, pi, i2c_handle_6b, i2c_handle_69,
                 i2c_handle_ADS7828, reporting_interval):  #new_data_event):
    #target data string:
    #timestamp           ,lat,  ,lon     ,el    ,press , temp , level, qual,rpm
    #2016-03-16T16:15:04Z,32.758,-97.448,199.700,32.808,63.722,26.887,2.144,0.000

    PWM_GPIO = 24  # to pin 18 on pi, mistakenly labeled "5" on rev c of the interface PCB
    RPM_GPIO = 17  # to pin 11 on the pi.

    #for reference, the ups uses gpio 27 (pin 13) to shutdown the pi (FSSD) and 22 (pin 15) is use for pulse train output to the ups (watchdog), 4 is used by the GPS PPS output, STACounter enable on 25 (pin 22)

    led_state = 0

    analog_sensors = ADS7828.ADS7828(pi, i2c_handle_ADS7828)
    oil_sensor = read_PWM.reader(pi, PWM_GPIO)
    rpm_sensor = read_RPM.reader(pi, RPM_GPIO)

    UPS_Pico_run_prior = 0
    UPS_Pico_run_temp = 0
    UPS_Pico_run_read_count = 0
    UPS_Pico_run_read_errors = 0
    UPS_PICO_RUN_MAX_READ_ERRORS = 5

    if (reporting_interval == 0):
        reporting_interval = 5
    gps_sensor = GPS_AdafruitSensor(interface='/dev/ttyAMA0')
    time_format_str = '%Y-%m-%dT%H:%M:%SZ'
    system_clock_set_from_gps = False

    while not killer.kill_now:
        try:
            logging.debug('acquire_data process launched...')

            while not killer.kill_now:

                #---------verifying that the Pico UPS is running properly -------------
                UPS_Pico_run_now = pi.i2c_read_word_data(
                    i2c_handle_69,
                    0x0e)  #rolling vale, should change after each read.

                if (UPS_Pico_run_now == UPS_Pico_run_prior):
                    UPS_Pico_run_read_errors += 1
                    if (UPS_Pico_run_read_errors >=
                            UPS_PICO_RUN_MAX_READ_ERRORS):
                        raise TimeoutError(
                            'The UPS Pico_run register (UPS Pico module status register 69 0x0E) has returend the same value ('
                            + str(UPS_Pico_run_now) + ') ' +
                            str(UPS_Pico_run_read_errors) +
                            ' times, which most likely indicates that the UPS is not running (either shutdown or locked up). The number of successful reads prior to error: '
                            + str(UPS_Pico_run_read_count))
                else:
                    UPS_Pico_run_read_errors = 0
                    UPS_Pico_run_read_count += 1
                UPS_Pico_run_prior = UPS_Pico_run_now

                time.sleep(reporting_interval)

                #---------begin data colection -------------
                timestamp = gps_sensor.timestamp
                timestamp_str = timestamp.strftime(time_format_str)

                pressure_str = analog_sensors.getUpdate()
                oil_str = oil_sensor.getUpdate()
                rpm_str = rpm_sensor.getUpdate()

                #---------concatenating, checking minimum number of fields and date validity -------------
                # all of the fields have leading commas.
                data_str = timestamp_str + gps_sensor.data_str(
                ) + pressure_str + oil_str + rpm_str

                if (len(data_str.split(',')) < 10):
                    logging.debug(
                        'Invalid data length, < 10 after split on comma, ACTUAL DATA: '
                        + data)
                    continue
                if (timestamp.year < 2016):
                    logging.debug(
                        'Discarding sample with an invalid timestamp: ' +
                        timestamp_str)
                    continue
                else:
                    if not system_clock_set_from_gps:  #only done once at startup
                        logging.debug('Setting date according to GPS')
                        os.system('sudo date -s ' + timestamp_str)
                        system_clock_set_from_gps = True

                filename = gps_sensor.timestamp.strftime(
                    "%Y-%m-%d_%H.csv")  #change log file every hour
                main_queue.put(('new data', filename, data_str))
                # print(data_str)
                led_state = 1 - led_state
                pi.i2c_write_byte_data(
                    i2c_handle_6b, 0x0D, led_state
                )  #toggle the red LED to show data is being processed

        except Exception as ex:
            logging.error('acquire_data: ' + traceback.format_exc())
            main_queue.put(('quit', ))
        finally:
            logging.debug('DAQ thread caught stop signal.')
            try:
                pi.i2c_write_byte_data(i2c_handle_6b, 0x0D,
                                       0)  #turn off the red LED
                r.cancel()  #stop the call backs
                p.cancel()
            except:
                pass
            main_queue.put(('DAQ thread stopped', ))
            logging.debug('DAQ thread is exiting.')
Esempio n. 4
0
####################

##SETUP RPM MEASURING
RPM_GPIO = 4
RPM_GPIO_2 = 17
RUN_TIME = 60.0
SAMPLE_TIME = 2.0

pi = pigpio.pi()
pi2 = pigpio.pi()

###################

##SETUP ENCODERS

encoder_1 = read_RPM.reader(pi, RPM_GPIO)
encoder_2 = read_RPM.reader(pi2, RPM_GPIO_2)

###################

### SETUP MOTORS BCM PINS (EN, IN1, IN2) ###

motor_1 = Setup_robo(25,24,23)
motor_1.set_motors()


#### SET MOTOR 2 ###
motor_2 = Setup_robo(6,16,26)
motor_2.set_motors()

controle = Control_robo(encoder_1, encoder_2, SAMPLE_TIME, motor_1, motor_2)
Esempio n. 5
0
def acquire_data(main_queue, killer, pi, i2c_handle_6b, i2c_handle_69, i2c_handle_ADS7828, reporting_interval): #new_data_event):
    #target data string:
    #timestamp           ,lat,  ,lon     ,el    ,press , temp , level, qual,rpm
    #2016-03-16T16:15:04Z,32.758,-97.448,199.700,32.808,63.722,26.887,2.144,0.000
   
        
    PWM_GPIO = 24 # to pin 18 on pi, mistakenly labeled "5" on rev c of the interface PCB
    RPM_GPIO = 17 # to pin 11 on the pi. 

    #for reference, the ups uses gpio 27 (pin 13) to shutdown the pi (FSSD) and 22 (pin 15) is use for pulse train output to the ups (watchdog), 4 is used by the GPS PPS output, STACounter enable on 25 (pin 22)

    led_state = 0
    
    analog_sensors = ADS7828.ADS7828(pi, i2c_handle_ADS7828)
    oil_sensor = read_PWM.reader(pi, PWM_GPIO)
    rpm_sensor = read_RPM.reader(pi, RPM_GPIO)

    UPS_Pico_run_prior = 0 
    UPS_Pico_run_temp = 0
    UPS_Pico_run_read_count = 0
    UPS_Pico_run_read_errors = 0
    UPS_PICO_RUN_MAX_READ_ERRORS = 5
    
    if(reporting_interval == 0):
       reporting_interval = 5
    gps_sensor = GPS_AdafruitSensor(interface='/dev/ttyAMA0')
    time_format_str = '%Y-%m-%dT%H:%M:%SZ'
    system_clock_set_from_gps = False
    

    while not killer.kill_now:
        try:
            logging.debug('acquire_data process launched...')

            while not killer.kill_now:


                #---------verifying that the Pico UPS is running properly ------------- 
                UPS_Pico_run_now = pi.i2c_read_word_data(i2c_handle_69, 0x0e) #rolling vale, should change after each read.

                if(UPS_Pico_run_now == UPS_Pico_run_prior):
                    UPS_Pico_run_read_errors += 1
                    if(UPS_Pico_run_read_errors >= UPS_PICO_RUN_MAX_READ_ERRORS):
                        raise TimeoutError('The UPS Pico_run register (UPS Pico module status register 69 0x0E) has returend the same value (' + str(UPS_Pico_run_now) + ') ' + str(UPS_Pico_run_read_errors) + ' times, which most likely indicates that the UPS is not running (either shutdown or locked up). The number of successful reads prior to error: ' + str(UPS_Pico_run_read_count))
                else:
                    UPS_Pico_run_read_errors = 0
                    UPS_Pico_run_read_count += 1
                UPS_Pico_run_prior = UPS_Pico_run_now

            
                time.sleep(reporting_interval)

                #---------begin data colection ------------- 
                timestamp = gps_sensor.timestamp
                timestamp_str = timestamp.strftime(time_format_str) 

                pressure_str = analog_sensors.getUpdate()
                oil_str = oil_sensor.getUpdate()
                rpm_str = rpm_sensor.getUpdate()

                #---------concatenating, checking minimum number of fields and date validity ------------- 
                # all of the fields have leading commas.
                data_str = timestamp_str + gps_sensor.data_str() + pressure_str + oil_str + rpm_str
                    
                
                if(len(data_str.split(',')) < 10):
                    logging.debug('Invalid data length, < 10 after split on comma, ACTUAL DATA: ' + data)
                    continue
                if(timestamp.year < 2016):
                    logging.debug('Discarding sample with an invalid timestamp: ' + timestamp_str)
                    continue
                else:
                    if not system_clock_set_from_gps: #only done once at startup
                        logging.debug('Setting date according to GPS')
                        os.system('sudo date -s ' + timestamp_str)
                        system_clock_set_from_gps = True

                filename = gps_sensor.timestamp.strftime("%Y-%m-%d_%H.csv") #change log file every hour
                main_queue.put(('new data', filename, data_str))
                # print(data_str)
                led_state = 1 - led_state
                pi.i2c_write_byte_data(i2c_handle_6b, 0x0D, led_state) #toggle the red LED to show data is being processed
                    

        except Exception as ex:
            logging.error('acquire_data: ' + traceback.format_exc())
            main_queue.put(('quit',))
        finally:
            logging.debug('DAQ thread caught stop signal.')
            try:
                pi.i2c_write_byte_data(i2c_handle_6b, 0x0D, 0) #turn off the red LED
                r.cancel() #stop the call backs            
                p.cancel()
            except:
                pass
            main_queue.put(('DAQ thread stopped',))
            logging.debug('DAQ thread is exiting.')
Esempio n. 6
0
# Calibrate ESC
ESC_GPIO = 13
pi.set_servo_pulsewidth(ESC_GPIO, 2000)  # Maximum throttle.
sleep(2)
pi.set_servo_pulsewidth(ESC_GPIO, 1000)  # Minimum throttle.
sleep(2)

# Set up input pins for thumbwheel switch
BCD = [16, 20, 21]
for pin in BCD:
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Set up RPM reader
RPM_GPIO = 14
SAMPLE_TIME = 2.0
tach = reader(pi, RPM_GPIO)

try:
    while 1:
        speed = 0
        # Loop through pins to return value of BCD counter
        for pin in BCD:
            # Left shift speed then OR by negated pin value
            speed = (speed << 1) | (1 ^ GPIO.input(pin))

        # Set ESC speed via PWM
        pi.set_servo_pulsewidth(ESC_GPIO, speed * 1000 / 7 + 1000)

        # Read RPM
        rpm = tach.RPM()