Ejemplo n.º 1
0
def main():

    NUM_LOGGING = 1000
    I2C_ADDRESS_BME280 = 0x77
    I2C_ADDRESS_APDS9301 = 0x39

    pi = pigpio.pi()
    handler_bme280 = PigpioI2CHandler(pi,
                                      I2C_ADDRESS_BME280,
                                      name="handler_bme280")
    handler_apds9301 = PigpioI2CHandler(pi,
                                        I2C_ADDRESS_APDS9301,
                                        name="handler_apds9301")

    bme280 = Bme280(handler_bme280)
    apds9301 = Apds9301(handler_apds9301)
    adapter_barometer = BarometerAdapter()

    con = SensorController(bme280 + apds9301, AdapterGroup(adapter_barometer))
    queue = DictLogQueue(500, con.dnames)
    counter = 0

    with DataLogger(con, queue) as dlogger:
        init_time = time.time()
        while counter < NUM_LOGGING:
            dlogger.read()
            counter += 1

    total_time = time.time() - init_time
    print("finish logging.")
    print("time: {} sec".format(total_time))
Ejemplo n.º 2
0
 def setUp(self) -> None:
     pi = pigpio.pi()
     handler_bme = PigpioI2CHandler(pi, ADDRESS_BME280)
     handler_bno = PigpioI2CHandler(pi, ADDRESS_BNO055)
     self.bme280 = Bme280(handler_bme, name=NAME_BME280)
     self.bno055 = Bno055(handler_bno, name=NAME_BNO055)
     self.logque = LogQueue(LinkedDataModel)
Ejemplo n.º 3
0
 def setUp(self) -> None:
     pi = pigpio.pi()
     handler_bme = PigpioI2CHandler(pi, ADDRESS_BME280)
     handler_bno = PigpioI2CHandler(pi, ADDRESS_BNO055)
     self.bme280 = Bme280(handler_bme, name=NAME_BME280)
     self.bno055 = Bno055(handler_bno, name=NAME_BNO055)
     self.bno055.change_operation_mode(self.bno055.OperationMode.NDOF)
     self.group = SensorGroup(LinkedDataModel,
                              self.bme280,
                              self.bno055,
                              name="group")
Ejemplo n.º 4
0
def run_child():
    pi = pigpio.pi()

    # handlers
    handler_bme280 = PigpioI2CHandler(pi, I2C_ADDRESS_BME280)
    handler_opt3002 = PigpioI2CHandler(pi, I2C_ADDRESS_OPT3002)
    handler_gps = PyserialSerialHandler(SERIAL_PORT_GPS, BAUDRATE_GPS)
    handler_im920 = PyserialSerialHandler(SERIAL_PORT_IM920, BAUDRATE_IM920)
    handler_led = PigpioDigitalOutputHandler(pi, GPIO_LED, name=NAME_LED)

    # sensors
    bme280 = Bme280(handler_bme280, name=NAME_BME280)
    opt3002 = Opt3002(handler_opt3002, name=NAME_OPT3002)
    gps = SamM8Q(handler_gps, name=NAME_GPS)

    # transceiver
    im920 = Im920(handler_im920, name=NAME_IM920)
    socket_transceiver = SocketTransceiver(im920,
                                           certain=True,
                                           name=NAME_SOCKET_TRANSCEIVER)

    # logger
    que = LogQueue(ChildLoggingModel, maxlen=5000, name=NAME_LOGQUEUE)
    dlogger = DataLogger(que, bme280, opt3002, gps, name=NAME_DATA_LOGGER)

    slogger = SystemLogger(name=NAME_SYSTEM_LOGGER)
    slogger.setFileHandler()

    manager = ComponentManager(handler_led,
                               im920,
                               socket_transceiver,
                               dlogger,
                               recursive=True,
                               name=NAME_MANAGER)

    context = Context(
        {
            MissionStandbyNode: {
                True: ChildServerNode,
                False: MissionStandbyNode
            },
            ChildServerNode: {
                True: None,
                False: ChildServerNode
            }
        },
        start=MissionStandbyNode)

    cansat = CanSat(context, manager, dlogger=dlogger, slogger=slogger)
    cansat.run()
Ejemplo n.º 5
0
def main():

    kp = float(input('Enter Kp: '))
    ex_time = float(input('Enter experiment time [sec]: '))

    # device setting
    pi = pigpio.pi()
    handler_bno055 = PigpioI2CHandler(pi, setting.I2C_ADDRESS_BNO055)
    handler_gps = PyserialSerialHandler(setting.SERIAL_PORT_GPS, baudrate=9600)
    handler_motor_l_fin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_L_FIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_motor_l_rin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_L_RIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_motor_r_fin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_R_FIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_motor_r_rin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_R_RIN,
                                           setting.MOTOR_PWM_FREQ)
    bno055 = Bno055(handler_bno055, name=setting.NAME_BNO055)
    gps = SamM8Q(handler_gps, name=setting.NAME_GPS)
    sencon = SensorController(RunningModel, bno055, gps)
    motor_l = BD62xx(handler_motor_l_fin,
                     handler_motor_l_rin,
                     name=setting.NAME_MOTOR_L)
    motor_r = BD62xx(handler_motor_r_fin,
                     handler_motor_r_rin,
                     name=setting.NAME_MOTOR_R)

    # testing
    data = sencon.read()
    pidcontroller = PIDController(kp=kp)
    first_time = time.time()
    last_time = first_time
    delta_time = 0.

    while delta_time < ex_time:
        current_time = time.time()
        if (current_time - last_time) < setting.SAMPLE_TIME:
            continue
        last_time = current_time

        offset = data.offset_angle2goal
        if offset is None:
            continue

        duty = pidcontroller.calc_input(offset)

        motor_r.ccw(duty)
        motor_l.cw(setting.DUTY_BASE)

        last_time = current_time
        delta_time = first_time - current_time

        time.sleep(setting.SAMPLE_TIME)

    motor_r.brake()
    motor_l.brake()
Ejemplo n.º 6
0
    def setUp(self) -> None:
        pi = pigpio.pi()
        handler_bme = PigpioI2CHandler(pi, ADDRESS_BME280)
        handler_bno = PigpioI2CHandler(pi, ADDRESS_BNO055)
        self.bme280 = Bme280(handler_bme, name=NAME_BME280)
        self.bno055 = Bno055(handler_bno, name=NAME_BNO055)
        self.logque = LogQueue(LinkedDataModel)
        self.dlogger = DataLogger(self.logque,
                                  self.bme280,
                                  self.bno055,
                                  name=NAME_DLOGGER)
        self.slogger = SystemLogger(name=NAME_SLOGGER)
        self.slogger.setFileHandler()
        self.manager = ComponentManager(self.dlogger,
                                        self.slogger,
                                        recursive=True)

        context = Context(
            {
                TestNode0: {
                    True: TestNode1,
                    False: TestNode0
                },
                TestNode1: {
                    True: TestNode2,
                    False: TestNode1
                },
                TestNode2: {
                    True: None,
                    False: TestNode2
                }
            },
            start=TestNode1)

        self.cansat = CanSat(context,
                             self.manager,
                             dlogger=self.dlogger,
                             slogger=self.slogger)
Ejemplo n.º 7
0
def main():
    pi = pigpio.pi()
    handler = PigpioI2CHandler(pi, setting.I2C_ADDRESS_BME280)
    bme280 = Bme280(handler, name=setting.NAME_BME280)
    
    try:
        while True:
            data = bme280.read()
            if data.press is None or data.temp is None:
                continue
            
            altitude = press2alti(data.press, data.temp)
            print(f"altitude: {altitude} [m]")
            time.sleep(SLEEP_TIME)
    except KeyboardInterrupt:
        pass
Ejemplo n.º 8
0
 def setUp(self) -> None:
     pi = pigpio.pi()
     handler = PigpioI2CHandler(pi, ADDRESS_BME280)
     self.bme280 = Bme280(handler, name="bme280")
     self.testor = SensorTestor(self.bme280)
Ejemplo n.º 9
0
 def setUp(self) -> None:
     pi = pigpio.pi()
     handler = PigpioI2CHandler(pi, ADDRESS_OPT3002)
     self.opt3002 = Opt3002(handler, name="apds9301")
     self.testor = SensorTestor(self.opt3002)
Ejemplo n.º 10
0
 def setUp(self) -> None:
     pi = pigpio.pi()
     handler = PigpioI2CHandler(pi, ADDRESS_APDS9301)
     self.apds9301 = Apds9301(handler, name="apds9301")
     self.testor = SensorTestor(self.apds9301)
Ejemplo n.º 11
0
def run_parent():

    # device setting
    pi = pigpio.pi()

    handler_bno055 = PigpioI2CHandler(pi, I2C_ADDRESS_BNO055)
    handler_bme280 = PigpioI2CHandler(pi, I2C_ADDRESS_BME280)
    handler_gps = PyserialSerialHandler(SERIAL_PORT_GPS, baudrate=BAUDRATE_GPS)
    handler_im920 = PyserialSerialHandler(SERIAL_PORT_IM920,
                                          baudrate=BAUDRATE_IM920)

    handler_motor_L_fin = PigpioPWMHandler(pi,
                                           GPIO_MOTOR_L_FIN,
                                           freq=MOTOR_PWM_FREQ)
    handler_motor_L_rin = PigpioPWMHandler(pi,
                                           GPIO_MOTOR_L_RIN,
                                           freq=MOTOR_PWM_FREQ)
    handler_motor_R_fin = PigpioPWMHandler(pi,
                                           GPIO_MOTOR_R_FIN,
                                           freq=MOTOR_PWM_FREQ)
    handler_motor_R_rin = PigpioPWMHandler(pi,
                                           GPIO_MOTOR_R_RIN,
                                           freq=MOTOR_PWM_FREQ)
    handler_mosfet_para = PigpioDigitalOutputHandler(pi,
                                                     GPIO_MOSFET_PARA,
                                                     name=NAME_MOSFET_PARA)
    handler_mosfet_child = PigpioDigitalOutputHandler(pi,
                                                      GPIO_MOSFET_CHILD,
                                                      name=NAME_MOSFET_CHILD)
    handler_sonic_trig = PigpioDigitalOutputHandler(pi, GPIO_SONIC_TRIG)
    handler_sonic_echo = PigpioDigitalInputHandler(pi, GPIO_SONIC_ECHO)
    handler_led = PigpioDigitalOutputHandler(pi, GPIO_LED, name=NAME_LED)

    # actuator
    motor_L = BD62xx(handler_motor_L_fin,
                     handler_motor_L_rin,
                     name=NAME_MOTOR_L)
    motor_R = BD62xx(handler_motor_R_fin,
                     handler_motor_R_rin,
                     name=NAME_MOTOR_R)
    wheels = TwoWheels(motor_L, motor_R, name=NAME_WHEELS)

    # transceiver
    im920 = Im920(handler_im920, name=NAME_IM920)
    im920.clear_buf()
    socket_transceiver = SocketTransceiver(im920,
                                           certain=True,
                                           name=NAME_SOCKET_TRANSCEIVER)

    # sensor
    bno055 = Bno055(handler_bno055, name=NAME_BNO055)
    bno055.change_operation_mode(Bno055.OperationMode.NDOF)
    bno055.remap_axis(Bno055.Axis.Y, Bno055.Axis.X, Bno055.Axis.Z)
    bno055.remap_sign(y=Bno055.AxisSign.NEGATIVE)
    bme280 = Bme280(handler_bme280, name=NAME_BME280)
    gps = SamM8Q(handler_gps, name=NAME_GPS)
    sonic = HcSr04(handler_sonic_echo,
                   handler_sonic_trig,
                   name=NAME_SUPERSONIC)

    que = LogQueue(LoggingModel, maxlen=10000, name=NAME_LOGQUEUE)
    dlogger = DataLogger(que,
                         bno055,
                         bme280,
                         gps,
                         sonic,
                         name=NAME_DATA_LOGGER)

    slogger = SystemLogger(name=NAME_SYSTEM_LOGGER)
    slogger.setFileHandler()

    # register callable components in Nodes
    manager = ComponentManager(motor_L,
                               motor_R,
                               wheels,
                               im920,
                               socket_transceiver,
                               handler_mosfet_para,
                               handler_mosfet_child,
                               handler_led,
                               dlogger,
                               slogger,
                               recursive=True,
                               name=NAME_MANAGER)

    # context setting
    context = Context(
        {
            MissionStandbyNode: {
                True: FallingNode,
                False: MissionStandbyNode
            },
            FallingNode: {
                True: ParaSeparateNode,
                False: FallingNode
            },
            ParaSeparateNode: {
                True: FirstRunningNode,
                False: ParaSeparateNode
            },
            FirstRunningNode: {
                True: ChildSeparateNode,
                False: FirstRunningNode
            },
            ChildSeparateNode: {
                True: SencondRunningNode,
                False: ChildSeparateNode
            },
            SencondRunningNode: {
                True: GoalSearchNode,
                False: SencondRunningNode
            },
            GoalSearchNode: {
                True: GoalDetectNode,
                False: GoalSearchNode
            },
            GoalDetectNode: {
                True: None,
                False: GoalDetectNode
            }
        },
        start=MissionStandbyNode)

    # build a cansat
    cansat = CanSat(context, manager, dlogger=dlogger, slogger=slogger)
    cansat.run()
Ejemplo n.º 12
0
 def setUp(self) -> None:
     pi = pigpio.pi()
     handler = PigpioI2CHandler(pi, ADDRESS_BNO055)
     self.bno055 = Bno055(handler, name="bno055")
     self.bno055.change_operation_mode(Bno055.OperationMode.NDOF)
     self.testor = SensorTestor(self.bno055)
Ejemplo n.º 13
0
def main():

    # device setting
    pi = pigpio.pi()

    handler_bno055 = PigpioI2CHandler(pi, setting.I2C_ADDRESS_BNO055)
    handler_bme280 = PigpioI2CHandler(pi, setting.I2C_ADDRESS_BME280)
    handler_gps = PyserialSerialHandler(setting.SERIAL_PORT_GPS)
    # handler_im920 = PyserialSerialHandler(setting.SERIAL_PORT_IM920)

    handler_motor_L_fin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_L_FIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_motor_L_rin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_L_RIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_motor_R_fin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_R_FIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_motor_R_rin = PigpioPWMHandler(pi, setting.GPIO_MOTOR_R_RIN,
                                           setting.MOTOR_PWM_FREQ)
    handler_mosfet_para = PigpioDigitalOutputHandler(
        pi, setting.GPIO_MOSFET_PARA, name=setting.NAME_MOSFET_PARA)
    handler_mosfet_child = PigpioDigitalOutputHandler(
        pi, setting.GPIO_MOSFET_CHILD, name=setting.NAME_MOSFET_CHILD)
    handler_sonic_trig = PigpioDigitalOutputHandler(pi,
                                                    setting.GPIO_SONIC_TRIG)
    handler_sonic_echo = PigpioDigitalInputHandler(pi, setting.GPIO_SONIC_ECHO)
    handler_led = PigpioDigitalOutputHandler(pi,
                                             setting.GPIO_LED,
                                             name=setting.NAME_LED)

    # actuator
    motor_L = BD62xx(handler_motor_L_fin,
                     handler_motor_L_rin,
                     name=setting.NAME_MOTOR_L)
    motor_R = BD62xx(handler_motor_R_fin,
                     handler_motor_R_rin,
                     name=setting.NAME_MOTOR_R)
    wheels = TwoWheels(motor_L, motor_R, name=setting.NAME_WHEELS)

    # transceiver
    # im920 = Im920(handler_im920, name=setting.NAME_IM920)

    # sensor
    bno055 = Bno055(handler_bno055, name=setting.NAME_BNO055)
    bno055.change_operation_mode(Bno055.OperationMode.NDOF)
    bme280 = Bme280(handler_bme280, name=setting.NAME_BME280)
    gps = SamM8Q(handler_gps, name=setting.NAME_GPS)
    sonic = HcSr04(handler_sonic_echo,
                   handler_sonic_trig,
                   name=setting.NAME_SUPERSONIC)

    con = SensorController(LoggingModel,
                           bno055,
                           bme280,
                           gps,
                           sonic,
                           name=setting.NAME_SENSOR_CONTROLLER)
    que = LogQueue(LoggingModel, maxlen=1000, name=setting.NAME_LOGQUEUE)
    dlogger = DataLogger(con, que, name=setting.NAME_DATA_LOGGER)

    slogger = SystemLogger(name=setting.NAME_SYSTEM_LOGGER)
    slogger.setFileHandler()

    # register callable components in Nodes
    manager = ComponentManager(motor_L,
                               motor_R,
                               wheels,
                               handler_mosfet_para,
                               handler_mosfet_child,
                               handler_led,
                               dlogger,
                               slogger,
                               recursive=True,
                               name=setting.NAME_MANAGER)

    # context setting
    context = Context(
        {
            FallingNode: {
                True: ParaSeparateNode,
                False: FallingNode
            },
            ParaSeparateNode: {
                True: None,
                False: ParaSeparateNode
            },
        },
        start=FallingNode)

    # build a cansat
    cansat = CanSat(context, manager, dlogger=dlogger, slogger=slogger)
    cansat.run()