settings.py 3.3 KB

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