def test_pin_mode(self):
        hw = HWSim(None, [], [])
        hw.set_pin_mode(1, PinModes.OUTPUT)
        hw.set_pin_mode(3, PinModes.INPUT)
        hw.set_pin_mode(2, PinModes.OUTPUT)

        assert hw.get_pin_mode(1) == PinModes.OUTPUT
        assert hw.get_pin_mode(3) == PinModes.INPUT
        assert hw.get_pin_mode(2) == PinModes.OUTPUT
Ejemplo n.º 2
0
    def construct_sim_connection(self):
        # Assemble HW here
        '''
        Stage 1
        '''
        rocket_sim_stage_1 = RocketSim(
            'simple.ork')  # TODO: Update ORK file once possible

        hw_sim_sensors_stage_1 = [
            DummySensor(SensorType.BAROMETER, (1000, 25)),
            DummySensor(SensorType.GPS, (12.6, 13.2, 175)),
            DummySensor(SensorType.ACCELEROMETER, (1, 0, 0)),
            DummySensor(SensorType.IMU, (1, 0, 0, 0)),
            DummySensor(SensorType.TEMPERATURE, (20, )),
            VoltageSensor()
        ]

        hw_sim_ignitors_stage_1 = [
            Ignitor(IgnitorType.MAIN, 4, 14, 16),
            Ignitor(IgnitorType.DROGUE, 17, 34, 35),
        ]

        hwsim_stage_1 = HWSim(rocket_sim_stage_1, hw_sim_sensors_stage_1,
                              hw_sim_ignitors_stage_1)
        '''
        Stage 2
        '''
        rocket_sim_stage_2 = RocketSim(
            'simple.ork')  # TODO: Update ORK file once possible

        hw_sim_sensors_stage_2 = [
            DummySensor(SensorType.BAROMETER, (100000, 25)),
            DummySensor(SensorType.GPS, (12.6, 13.2, 175)),
            DummySensor(SensorType.ACCELEROMETER, (1, 0, 0)),
            DummySensor(SensorType.IMU, (1, 0, 0, 0)),
            DummySensor(SensorType.TEMPERATURE, (20, )),
            VoltageSensor()
        ]

        hw_sim_ignitors_stage_2 = [
            Ignitor(IgnitorType.MAIN, 4, 14, 16),
            Ignitor(IgnitorType.DROGUE, 17, 34, 35),
        ]

        hwsim_stage_2 = HWSim(rocket_sim_stage_2, hw_sim_sensors_stage_2,
                              hw_sim_ignitors_stage_2)

        return {
            'TANTALUS_STAGE_1_CONNECTION':
            SimConnection("TantalusStage1", "0013A20041678FC0", hwsim_stage_1),
            'TANTALUS_STAGE_2_CONNECTION':
            SimConnection("TantalusStage2", "0013A20041678FC0", hwsim_stage_2),
        }
    def test_clock(self):
        clock = Clock()
        rocket_sim = MagicMock()
        rocket_sim.get_clock = MagicMock(return_value=clock)

        hw = HWSim(rocket_sim, [], [])

        assert clock.get_time_ms() == 0
        assert clock.get_time_us() == 0

        assert hw.time_update(1000) == 1
        assert hw.time_update(1900) == 2
        assert hw.time_update(100) == 3
    def construct_sim_connection(self):
        # Assemble HW here

        '''
        Body
        '''
        rocket_sim_body = RocketSim('Hollyburn CanSat Jan 20.ork')

        hw_sim_sensors_body = [
            SensorSim(SensorType.BAROMETER, rocket_sim_body, error_stdev=(50, 0.005)),
            DummySensor(SensorType.GPS, (12.6, 13.2, 175)),
            SensorSim(SensorType.ACCELEROMETER, rocket_sim_body),
            DummySensor(SensorType.IMU, (1, 0, 0, 0)),
            DummySensor(SensorType.TEMPERATURE, (20,)),
        ]

        hw_sim_ignitors_body = [
            Ignitor(IgnitorType.MAIN, 4, 14, 16, action_fn=rocket_sim_body.deploy_main),
            Ignitor(IgnitorType.DROGUE, 17, 34, 35, action_fn=rocket_sim_body.deploy_drogue),
        ]

        hwsim_body = HWSim(rocket_sim_body, hw_sim_sensors_body, hw_sim_ignitors_body)

        '''
        Nose
        '''

        # TODO: Enable this once possible
        '''
        rocket_sim_nose = RocketSim('Hollyburn CanSat Jan 20.ork')

        hw_sim_sensors_nose = [
            SensorSim(SensorType.BAROMETER, rocket_sim_nose, error_stdev=(50, 0.005)),
            DummySensor(SensorType.GPS, (12.6, 13.2, 175)),
            SensorSim(SensorType.ACCELEROMETER, rocket_sim_nose),
            DummySensor(SensorType.IMU, (1, 0, 0, 0)),
            DummySensor(SensorType.TEMPERATURE, (20,)),
        ]

        hw_sim_ignitors_nose = [
            Ignitor(IgnitorType.MAIN, 4, 14, 16, action_fn=rocket_sim_body.deploy_main),
            Ignitor(IgnitorType.DROGUE, 17, 34, 35, action_fn=rocket_sim_body.deploy_drogue),
        ]

        hwsim_nose = HWSim(rocket_sim_nose, hw_sim_sensors_nose, hw_sim_ignitors_nose)
        '''

        return {
            'HOLLYBURN_BODY_CONNECTION': SimConnection("Hollyburn", "0013A20041678FC0", hwsim_body),
            # 'HOLLYBURN_NOSE_CONNECTION': SimConnection("Hollyburn", "0013A20041678FC0", hwsim_nose),
        }
    def test_sensor_read(self):
        GPS_DATA = (1, 2, 3)
        BARO_DATA = (4, 5)

        GPS = DummySensor(SensorType.GPS, GPS_DATA)
        BARO = DummySensor(SensorType.BAROMETER, BARO_DATA)

        hw = HWSim(None, [GPS, BARO], [])

        assert hw.sensor_read(SensorType.GPS) == GPS_DATA
        assert hw.sensor_read(SensorType.BAROMETER) == BARO_DATA

        GPS_DATA = (11, 12, 13)
        BARO_DATA = (14, 15)

        GPS.set_value(GPS_DATA)
        BARO.set_value(BARO_DATA)

        assert hw.sensor_read(SensorType.GPS) == GPS_DATA
        assert hw.sensor_read(SensorType.BAROMETER) == BARO_DATA
    def test_ignitor_broken(self):
        hw = HWSim(None, [], [
            Ignitor(IgnitorType.MAIN, 1, 2, 3, broken=True),
            Ignitor(IgnitorType.DROGUE, 4, 5, 6, broken=True)
        ])

        hw.set_pin_mode(1, PinModes.INPUT)
        hw.set_pin_mode(2, PinModes.OUTPUT)
        hw.set_pin_mode(3, PinModes.INPUT)
        hw.set_pin_mode(4, PinModes.INPUT)
        hw.set_pin_mode(5, PinModes.OUTPUT)
        hw.set_pin_mode(6, PinModes.INPUT)

        assert ignitor_test(hw, 1, 2) == Ignitor.DISCONNECTED
        assert ignitor_test(hw, 4, 5) == Ignitor.DISCONNECTED

        hw = HWSim(None, [], [
            Ignitor(IgnitorType.MAIN, 1, 2, 3, broken=True),
            Ignitor(IgnitorType.DROGUE, 4, 5, 6, broken=False)
        ])

        hw.set_pin_mode(1, PinModes.INPUT)
        hw.set_pin_mode(2, PinModes.OUTPUT)
        hw.set_pin_mode(3, PinModes.INPUT)
        hw.set_pin_mode(4, PinModes.INPUT)
        hw.set_pin_mode(5, PinModes.OUTPUT)
        hw.set_pin_mode(6, PinModes.INPUT)

        assert ignitor_test(hw, 1, 2) == Ignitor.DISCONNECTED
        assert ignitor_test(hw, 4, 5) == Ignitor.CONNECTED

        hw.digital_write(6, True)
        assert ignitor_test(hw, 4, 5) == Ignitor.DISCONNECTED
    def test_ignitor_fire(self):
        hw = HWSim(None, [], [Ignitor(IgnitorType.MAIN, 6, 3, 1)])

        hw.set_pin_mode(1, PinModes.INPUT)
        hw.set_pin_mode(3, PinModes.OUTPUT)
        hw.set_pin_mode(6, PinModes.INPUT)
        hw.digital_write(1, False)  # Writing false does not fire
        assert hw.analog_read(3) == Ignitor.OFF
        hw.digital_write(6, True)
        assert hw.analog_read(3) == Ignitor.CONNECTED
        hw.digital_write(6, False)

        hw.digital_write(1, True)  # Fire the pin
        assert hw.analog_read(3) == Ignitor.OFF
        hw.digital_write(6, True)
        assert hw.analog_read(3) == Ignitor.DISCONNECTED
        hw.digital_write(6, False)

        hw.digital_write(1, False)  # Firing is one-way
        assert hw.analog_read(3) == Ignitor.OFF
        hw.digital_write(6, True)
        assert hw.analog_read(3) == Ignitor.DISCONNECTED
        hw.digital_write(6, False)
    def test_ignitor_readwrite(self):
        hw = HWSim(None, [], [
            Ignitor(IgnitorType.MAIN, 1, 2, 3),
            Ignitor(IgnitorType.DROGUE, 5, 9, 10)
        ])

        hw.set_pin_mode(2, PinModes.OUTPUT)
        hw.set_pin_mode(9, PinModes.OUTPUT)
        assert hw.analog_read(2) == Ignitor.OFF
        assert hw.analog_read(9) == Ignitor.OFF

        hw.set_pin_mode(1, PinModes.INPUT)
        hw.digital_write(1, True)
        assert hw.analog_read(2) == Ignitor.CONNECTED
        assert hw.analog_read(9) == Ignitor.OFF
        hw.digital_write(1, False)

        assert hw.analog_read(2) == Ignitor.OFF
        assert hw.analog_read(9) == Ignitor.OFF

        hw.set_pin_mode(5, PinModes.INPUT)
        hw.set_pin_mode(7, PinModes.INPUT)
        hw.digital_write(5, True)
        hw.digital_write(7, True)
        assert hw.analog_read(2) == Ignitor.OFF
        assert hw.analog_read(9) == Ignitor.CONNECTED