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