Пример #1
0
def init_all(conf):
    """Initialise all components"""

    log = logging.getLogger()

    db = initialisation.db_init(conf['DATABASE'])
    initialisation.init_gpio(conf, state=0)  # set all used pins to LOW

    # Get all comports and collect the initialisation dicts
    ports = list_ports.comports()
    motor = initialisation.motor_init(conf['MOTOR'], ports)
    gps = initialisation.gps_init(conf['GPS'], ports)

    rad, Rad_manager = initialisation.rad_init(conf['RADIOMETERS'], ports)
    sample = initialisation.sample_init(conf['SAMPLING'])
    battery, bat_manager = initialisation.battery_init(conf['BATTERY'], ports)
    tpr = initialisation.tpr_init(conf['TPR'])  # tilt sensor
    rht = initialisation.rht_init(conf['RHT'])  # internal temp/rh sensor

    # collect info on which GPIO pins are being used to control peripherals
    gpios = []
    if Rad_manager is not None and rad['use_gpio_control']:
        gpios.append(rad['gpio1'])

    # start individual monitoring threads
    if battery['used']:
        bat_manager.start()
        time.sleep(0.1)

    if gps['manager'] is not None:
        gps['manager'].add_serial_port(gps['serial1'])
        gps['manager'].start()

    if tpr['manager'] is not None:
        log.info("Starting Tilt/Pitch/Roll manager")
        tpr['manager'].start()

    if rht['manager'] is not None:
        # take a few readings to stabilize
        for i in range(5):
            rht_time, rht_rh, rht_temp = rht['manager'].update_rht_single()
        try:
            log.info("Internal Temperature and Humidity: {0:2.1f}C {1:2.1f}% ".
                     format(rht_temp, rht_rh))
        except:
            log.error("Could not read RHT sensor")
        #rht['manager'].start()  # there is no need to run an averaging thread, but it's there if we want it

    if motor['used']:
        # Get the current motor pos and if not at HOME move it to HOME
        motor_pos = motor_func.get_motor_pos(motor['serial'])
        if motor_pos != motor['home_pos']:
            t0 = time.time()
            log.info("Homing motor.. {0} --> {1}".format(
                motor_pos, motor['home_pos']))
            motor_func.return_home(
                motor['serial']
            )  # FIXME replace with rotate function to home pos as set in config
            moving = True
            while moving and (time.time() - t0 < 5):
                moving = motor_func.motor_moving(motor['serial'],
                                                 motor['home_pos'],
                                                 tolerance=300)[0]
                if moving is None:
                    moving = True  # assume we are not done
                log.info("..homing motor..")
                time.sleep(1)
            log.info("..done")
        else:
            log.info("Motor in home position")
        time.sleep(0.1)

    # Start the radiometry manager
    if Rad_manager is not None:
        log.info("Starting radiometry manager")
        try:
            radiometry_manager = Rad_manager(rad)
            time.sleep(0.1)
            rad['ed_sampling'] = radiometry_manager.ed_sampling  # if the Ed sensor is not identified, disable this feature
        except Exception as msg:
            log.exception(msg)
            stop_all(
                db,
                None,
                gps,
                battery,
                bat_manager,
                gpios,
                tpr,
                rht,
                idle_time=0
            )  # calls sys.exit after pausing for idle_time to prevent immediate restart
    else:
        radiometry_manager = None

    # Return all the dicts and manager objects
    return db, rad, sample, gps, radiometry_manager, motor, battery, bat_manager, gpios, tpr, rht
Пример #2
0
import inspect
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))))
import serial.tools.list_ports as list_ports
from initialisation import motor_init
from main_app import parse_args, read_config
import functions.motor_controller_functions as motor_func
import codecs

test_duration = 3600
print("Run test for {0} seconds. Press CTRL-C to stop".format(test_duration))

if __name__ == '__main__':
    args = parse_args()
    conf = read_config(args.config_file)
    ports = list_ports.comports()
    motor = motor_init(conf['MOTOR'], ports)
    stpd = float(motor['steps_per_degree'])

    t0 = time.time()
    while time.time() - t0 < test_duration:

        # read register 128: present alarm code
        response = motor_func.read_command(motor['serial'], 1, 3, 128, 2)
        # print(response, len(response), type(response))  # bytes class
        #slave_id = int(response[0])
        #function_code = int(response[1])
        length = int(response[2])
        alarm = int.from_bytes(response[3:3+length], byteorder='big')

        # read register 204-205: Detection position
        response = motor_func.read_command(motor['serial'], 1, 3, 204, 2)
Пример #3
0
def init_all(conf):
    """Initialise all components"""

    log = logging.getLogger()

    db = initialisation.db_init(conf['DATABASE'])
    initialisation.init_gpio(conf, state=0)  # set all used pins to LOW

    # Get all comports and collect the initialisation dicts
    ports = list_ports.comports()
    motor = initialisation.motor_init(conf['MOTOR'], ports)
    gps = initialisation.gps_init(conf['GPS'], ports)
    rad, Rad_manager = initialisation.rad_init(conf['RADIOMETERS'], ports)
    sample = initialisation.sample_init(conf['SAMPLING'])
    battery, bat_manager = initialisation.battery_init(conf['BATTERY'], ports)

    # start the battery manager
    if battery['used']:
        bat_manager.start()
        time.sleep(0.1)

    # collect info on which GPIO pins are being used
    gpios = []
    if gps['gpio_control']:
        gpios.append(gps['gpio2'])
    if rad['use_gpio_control']:
        gpios.append(rad['gpio1'])
        gpios.append(rad['gpio2'])
        gpios.append(rad['gpio3'])

    # Get the GPS serial objects from the GPS dict
    gps_ports = [port for key, port in gps.items() if 'serial' in key]
    # Instantiate GPS monitoring threads
    if len(gps_ports) > 0:
        gps_managers = []
        for port in gps_ports:
            gps_manager = GPSManager()
            gps_manager.add_serial_port(port)
            gps_manager.start()
            gps_managers.append(gps_manager)
    else:
        log.info("Check GPS sensors and Motor connection settings")
    time.sleep(0.1)

    # Start the GPS checker thread
    gps_checker_manager = GPSChecker(gps_managers)
    gps_checker_manager.start()

    # Get the current motor pos and if not at HOME move it to HOME
    motor_pos = motor_func.get_motor_pos(motor['serial'])
    if motor_pos != motor['home_pos']:
        t0 = time.clock()
        log.info("Homing motor.. {0} --> {1}".format(motor_pos,
                                                     motor['home_pos']))
        motor_func.return_home(
            motor['serial']
        )  # FIXME replace with rotate function to home pos as set in config
        moving = True
        while moving and (time.clock() - t0 < 5):
            moving = motor_func.motor_moving(motor['serial'],
                                             motor['home_pos'],
                                             tolerance=300)[0]
            if moving is None:
                moving = True  # assume we are not done
            log.info("..homing motor..")
            time.sleep(1)
        log.info("..done")
    else:
        log.info("Motor in home position")
    time.sleep(0.1)

    # Start the radiometry manager
    log.info("Starting radiometry manager")
    radiometry_manager = Rad_manager(rad)
    time.sleep(0.1)

    # Return all the dicts and manager objects
    return db, rad, sample, gps_managers, radiometry_manager, motor, battery, bat_manager, gps_checker_manager, gpios