from dotenv import load_dotenv, find_dotenv from pathlib import Path # Python 3.6+ only import configparser def get_config_by_items(config_dict): __config_dict = {} for i, k in config_dict: __config_dict[i] = k return __config_dict def get_dict_value(_dict, key, default=None): if key in _dict: return _dict[key] else: return default MACHINE_LEVEL = "二档" IS_TEST = False IS_MCU = True IS_LIN_SHI_TEST = False PhotographSeconds = float(0.3) # 拍照停留时间 def moveSpeed(level: str = None): config = { "一档": { "camera_high_motor": { "max_speed": 10000, "up_speed": 800, "down_speed": 700, }, "turntable_steering": { "max_speed": 6000, "up_speed": 500, "down_speed": 400, }, }, "二档": { "camera_high_motor": { "max_speed": 7000, "up_speed": 600, "down_speed": 500, }, "turntable_steering": { "max_speed": 4500, "up_speed": 350, "down_speed": 300, }, }, "三档": { "camera_high_motor": { "max_speed": 3500, "up_speed": 400, "down_speed": 300, }, "turntable_steering": { "max_speed": 3000, "up_speed": 200, "down_speed": 200, }, }, } if level is None: return config[MACHINE_LEVEL] else: return config[level] config = configparser.ConfigParser() config_name = "config.ini" config.read(config_name, encoding="utf-8") # 应用名称 APP_NAME = config.get("app", "app_name") # 应用版本号 APP_VERSION = config.get("app", "version") # 是否开启调试模式 IS_DEBUG = config.get("app", "debug") # 应用端口号 PORT = config.get("app", "port") # 应用线程数 APP_WORKS = config.get("app", "works") # 应用host地址 APP_HOST = config.get("app", "host") # 应用服务启动名称 APP_RUN = config.get("app", "app_run") # 日志名称 LOG_FILE_NAME = config.get("log", "log_file_name") # 最大字节数 MAX_BYTES = config.get("log", "max_bytes") print("Max bytes is", MAX_BYTES) # 备份数量 BACKUP_COUNTS = config.get("log", "backup_counts") # 远程服务器地址 HLM_HOST = config.get("log", "hlm_host") PROJECT = config.get("log", "project") # ---------------------------------- mcu_config_dict = config.items("mcu_config") _mcu_config_dict = {} for i, k in mcu_config_dict: _mcu_config_dict[i] = int(k) # print(_mcu_config_dict) _config_mcu_config = get_config_by_items(config.items("mcu_config")) LEFT_FOOT_ACTION = _mcu_config_dict["left_foot_action"] LEFT_FOOT_PHOTOGRAPH = _mcu_config_dict["left_foot_photograph"] LEFT_FOOT_ACTION_1 = _mcu_config_dict["left_foot_action_1"] LEFT_FOOT_ACTION_2 = _mcu_config_dict["left_foot_action_2"] RIGHT_FOOT_ACTION = _mcu_config_dict["right_foot_action"] RIGHT_FOOT_PHOTOGRAPH = _mcu_config_dict["right_foot_photograph"] RIGHT_FOOT_ACTION_1 = _mcu_config_dict["right_foot_action_1"] RIGHT_FOOT_ACTION_2 = _mcu_config_dict["right_foot_action_2"] NEXT_STEP = int(get_dict_value(_config_mcu_config, "next_step", 6)) # 下一步 MOVE_UP = _mcu_config_dict["move_up"] MOVE_DOWN = _mcu_config_dict["move_down"] STOP = _mcu_config_dict["stop"]