Пример #1
0
 def test_config_with_invalid_board_id(self):
     """
     Test that an invalid board ID causes the expected exception.
     """
     with self.assertRaises(ThunderBorgException) as cm:
         ThunderBorg(logger_name=self._LOG_FILENAME,
                     log_level=logging.DEBUG)
    def __init__(self,
                 bus_num=ThunderBorg.DEFAULT_BUS_NUM,
                 address=ThunderBorg.DEFAULT_I2C_ADDRESS,
                 log_level=logging.INFO,
                 debug=False):
        self._debug = debug
        log_level = logging.DEBUG if debug else log_level
        cl = ConfigLogger()
        cl.config(logger_name=self._BASE_LOGGER_NAME,
                  file_path=self._LOG_PATH,
                  level=log_level)
        self._log = logging.getLogger(self._LOGGER_NAME)

        if not self._debug:
            self._tb = ThunderBorg(bus_num=bus_num,
                                   address=address,
                                   logger_name=self._TBORG_LOGGER_NAME,
                                   log_level=log_level)

        PYGameController.__init__(self,
                                  logger_name=self._CTRL_LOGGER_NAME,
                                  log_level=log_level,
                                  debug=debug)
        Daemon.__init__(self,
                        self._PIDFILE,
                        logger_name=self._LOGGER_NAME,
                        verbose=2 if debug else 0)
Пример #3
0
 def test_config_with_invalid_address(self):
     """
     Test that an invalid address creates the expected exception.
     """
     with self.assertRaises(ThunderBorgException) as cm:
         ThunderBorg(address=0x70,
                     logger_name=self._LOG_FILENAME,
                     log_level=logging.DEBUG)
Пример #4
0
 def setUpClass(self):
     ThunderBorg.DEFAULT_I2C_ADDRESS = 0x15
     ThunderBorg.set_i2c_address(ThunderBorg.DEFAULT_I2C_ADDRESS)
     tb = ThunderBorg()
     tb.halt_motors()
     tb.set_both_leds(0, 0, 0)
     tb.set_led_battery_state(False)
     tb.set_comms_failsafe(False)
     tb.write_external_led_word(0, 0, 0, 0)
Пример #5
0
 def test_config_with_auto_set_address(self):
     """
     Test that ``auto_set_addr`` if set to ``True`` causes the API to
     find the first valid board and configure itself to that board.
     """
     # First change the board address so it cannot be found at the
     # default address.
     new_addr = 0x70
     ThunderBorg.set_i2c_address(new_addr)
     # Now instantiate ThunderBorg.
     tb = ThunderBorg(logger_name=self._LOG_FILENAME,
                      log_level=logging.DEBUG,
                      auto_set_addr=True)
Пример #6
0
 def test_find_address_with_invalid_default_address(self):
     """
     Test that an invalid default address will cause a board to be
     initialized if the `auto_set_addr` argument is `True`.
     """
     default_address = 0x15
     # Initialize the board by instantiating ThunderBorg.
     tb = ThunderBorg(logger_name=self.LOGGER_NAME,
                      log_level=logging.DEBUG,
                      auto_set_addr=True)
     boards = ThunderBorg.find_board()
     msg = "Boards found: {}".format(boards)
     self.assertEquals(ThunderBorg.DEFAULT_I2C_ADDRESS, 0x20, msg)
     self.assertTrue(len(boards) > 0, msg)
     self.assertEqual(boards[0], default_address, msg)
    def __init__(self,
                 bus_num=ThunderBorg.DEFAULT_BUS_NUM,
                 address=ThunderBorg.DEFAULT_I2C_ADDRESS,
                 borg=True,
                 log_level=logging.INFO,
                 voltage_in=_VOLTAGE_IN,
                 debug=False):
        self._borg = borg
        self.voltage_in = float(voltage_in)
        log_level = logging.DEBUG if debug else log_level
        cl = ConfigLogger()
        cl.config(logger_name=self._BASE_LOGGER_NAME,
                  file_path=self._LOG_PATH,
                  level=log_level)
        self._log = logging.getLogger(self._LOGGER_NAME)
        super(JoyStickControl, self).__init__(self._PIDFILE,
                                              logger_name=self._LOGGER_NAME)
        self._log.info(
            "Initial arguments: bus_num: %s, address: %s, "
            "borg: %s, log_level: %s, voltage_in: %s, debug: %s", bus_num,
            address, borg, logging.getLevelName(log_level), voltage_in, debug)

        if self._borg:
            self._tb = ThunderBorg(bus_num=bus_num,
                                   address=address,
                                   logger_name=self._TBORG_LOGGER_NAME,
                                   log_level=log_level)

            if math.isclose(self.voltage_in, 0.0):
                self.voltage_in = self._tb.get_battery_voltage()

            self._log.info("Voltage in: %s, max power: %s", self.voltage_in,
                           self.max_power)
            self.set_battery_limits()

        # Set defaults
        self.__quit = False
        self.fwd_rev_invert = False
        self.turn_invert = False
        # Longer than 10 secs will never be recognized because the
        # controller itself will disconnect before that.
        self.quit_hold_time = 9.0
Пример #8
0
 def setUp(self):
     self._tb = ThunderBorg(logger_name=self._LOG_FILENAME,
                            log_level=logging.DEBUG)