settings.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. from dotenv import load_dotenv, find_dotenv
  2. from pathlib import Path # Python 3.6+ only
  3. import configparser
  4. def get_config_by_items(config_dict):
  5. __config_dict = {}
  6. for i, k in config_dict:
  7. __config_dict[i] = k
  8. return __config_dict
  9. def get_dict_value(_dict, key, default=None):
  10. if key in _dict:
  11. return _dict[key]
  12. else:
  13. return default
  14. MACHINE_LEVEL = "二档"
  15. IS_TEST = False
  16. IS_MCU = True
  17. IS_LIN_SHI_TEST = False
  18. PhotographSeconds = float(0.3) # 拍照停留时间
  19. def moveSpeed(level: str = None):
  20. config = {
  21. "一档": {
  22. "camera_high_motor": {
  23. "max_speed": 10000,
  24. "up_speed": 800,
  25. "down_speed": 700,
  26. },
  27. "turntable_steering": {
  28. "max_speed": 6000,
  29. "up_speed": 500,
  30. "down_speed": 400,
  31. },
  32. },
  33. "二档": {
  34. "camera_high_motor": {
  35. "max_speed": 7000,
  36. "up_speed": 600,
  37. "down_speed": 500,
  38. },
  39. "turntable_steering": {
  40. "max_speed": 4500,
  41. "up_speed": 350,
  42. "down_speed": 300,
  43. },
  44. },
  45. "三档": {
  46. "camera_high_motor": {
  47. "max_speed": 3500,
  48. "up_speed": 400,
  49. "down_speed": 300,
  50. },
  51. "turntable_steering": {
  52. "max_speed": 3000,
  53. "up_speed": 200,
  54. "down_speed": 200,
  55. },
  56. },
  57. }
  58. if level is None:
  59. return config[MACHINE_LEVEL]
  60. else:
  61. return config[level]
  62. config = configparser.ConfigParser()
  63. config_name = "config.ini"
  64. config.read(config_name, encoding="utf-8")
  65. # 应用名称
  66. APP_NAME = config.get("app", "app_name")
  67. # 应用版本号
  68. APP_VERSION = config.get("app", "version")
  69. # 是否开启调试模式
  70. IS_DEBUG = config.get("app", "debug")
  71. # 应用端口号
  72. PORT = config.get("app", "port")
  73. # 应用线程数
  74. APP_WORKS = config.get("app", "works")
  75. # 应用host地址
  76. APP_HOST = config.get("app", "host")
  77. # 应用服务启动名称
  78. APP_RUN = config.get("app", "app_run")
  79. # 日志名称
  80. LOG_FILE_NAME = config.get("log", "log_file_name")
  81. # 最大字节数
  82. MAX_BYTES = config.get("log", "max_bytes")
  83. print("Max bytes is", MAX_BYTES)
  84. # 备份数量
  85. BACKUP_COUNTS = config.get("log", "backup_counts")
  86. # 远程服务器地址
  87. HLM_HOST = config.get("log", "hlm_host")
  88. # ----------------------------------
  89. mcu_config_dict = config.items("mcu_config")
  90. _mcu_config_dict = {}
  91. for i, k in mcu_config_dict:
  92. _mcu_config_dict[i] = int(k)
  93. # print(_mcu_config_dict)
  94. _config_mcu_config = get_config_by_items(config.items("mcu_config"))
  95. LEFT_FOOT_ACTION = _mcu_config_dict["left_foot_action"]
  96. LEFT_FOOT_PHOTOGRAPH = _mcu_config_dict["left_foot_photograph"]
  97. LEFT_FOOT_ACTION_1 = _mcu_config_dict["left_foot_action_1"]
  98. LEFT_FOOT_ACTION_2 = _mcu_config_dict["left_foot_action_2"]
  99. RIGHT_FOOT_ACTION = _mcu_config_dict["right_foot_action"]
  100. RIGHT_FOOT_PHOTOGRAPH = _mcu_config_dict["right_foot_photograph"]
  101. RIGHT_FOOT_ACTION_1 = _mcu_config_dict["right_foot_action_1"]
  102. RIGHT_FOOT_ACTION_2 = _mcu_config_dict["right_foot_action_2"]
  103. NEXT_STEP = int(get_dict_value(_config_mcu_config, "next_step", 6)) # 下一步
  104. MOVE_UP = _mcu_config_dict["move_up"]
  105. MOVE_DOWN = _mcu_config_dict["move_down"]
  106. STOP = _mcu_config_dict["stop"]