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)
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()
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")
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)
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()
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)
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()