diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4f1d87d..75aab99 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -43,4 +43,4 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Lint with mypy - run: mypy webserver robot models tests utils --check-untyped-defs --ignore-missing-imports + run: mypy $(git ls-files '*.py') --check-untyped-defs --ignore-missing-imports diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af55f4e..e7edeb3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,5 +34,6 @@ jobs: python -m pip install -e "git+https://github.com/simondlevy/BreezyLidar.git#egg=BreezyLidar&subdirectory=python" # lidar library if [ -f requirements.txt ]; then pip install -r requirements.txt; fi if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi + cp config/config.yml.dev config/config.yml - name: Test with pytest run: python3 main.py & (sleep 3; pytest .) diff --git a/README.md b/README.md index 73c6842..3550cc2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ A python real-time controller API for robotic systems via CAN Possibly, use python3.10 ```bash -pip install -e "git+https://github.com/simondlevy/BreezyLidar.git#egg=BreezyLidar&subdirectory=python" # lidar library pip install -r requirements.txt pip install -r requirements_dev.txt # only for testing ``` @@ -17,3 +16,9 @@ pip install -r requirements_dev.txt # only for testing ```bash python3 main.py ``` + +### enable LiDAR (optional) + +```bash +pip install -e "git+https://github.com/simondlevy/BreezyLidar.git#egg=BreezyLidar&subdirectory=python" # lidar library +``` diff --git a/config/config.py b/config/config.py index 49c34a1..26b0338 100644 --- a/config/config.py +++ b/config/config.py @@ -1,12 +1,19 @@ import os +from pprint import pprint import yaml +from utils.colors import bcolors, colorit + conf: dict = {} override = "config.yml" default = "config.yml.default" -conf_path = override if os.path.exists(override) else default +conf_path = override if os.path.exists(f"config/{override}") else default -with open(conf_path, "r", encoding="utf-8") as conf_file: +with open(f"config/{conf_path}", "r", encoding="utf-8") as conf_file: conf = yaml.load(conf_file, Loader=yaml.SafeLoader) + +print(f"{bcolors.OKGREEN.value}ℹ️ CONFIG") +pprint(conf) +print(colorit("ℹ️ END CONFIG", bcolors.OKGREEN)) diff --git a/config/config.yml.default b/config/config.yml.default index f6bc3fd..6d26203 100644 --- a/config/config.yml.default +++ b/config/config.yml.default @@ -1,5 +1,5 @@ # development -DEBUG_MESSAGES: False # add more prints +DEBUG_MESSAGES: True # add more prints DEBUG_POSITION: False DEBUG_CYCLE: False diff --git a/config/config.yml.dev b/config/config.yml.dev new file mode 100644 index 0000000..e9ea53e --- /dev/null +++ b/config/config.yml.dev @@ -0,0 +1,17 @@ +# development +DEBUG_MESSAGES: True # add more prints +DEBUG_POSITION: False +DEBUG_CYCLE: True + +# CAN +CHANNEL: "can0" +VCHANNEL: "vcan0" # only for development or (future) pipeline +CAN_BAUD: 403847 +DEBUG_CAN: True +DEBUG_VIRTUAL: True +DEBUG_VCAN: False # only for (future) pipeline + +# LIDAR +DEBUG_LIDAR: True +ENABLE_LIDAR: False +LIDAR_DEVICE: "/dev/ttyACM0" diff --git a/main.py b/main.py index 9aa24d8..6635f6f 100644 --- a/main.py +++ b/main.py @@ -48,7 +48,10 @@ finally: bus.shutdown() - if conf["DEBUG_VIRTUAL"]: + if ( + conf["DEBUG_VIRTUAL"] + and v_bus is not None # pylint: disable=used-before-assignment + ): v_bus.shutdown() # pylint: disable=used-before-assignment proper_exit() diff --git a/models/debug_messages.py b/models/debug_messages.py index 257a76c..3c21672 100644 --- a/models/debug_messages.py +++ b/models/debug_messages.py @@ -55,26 +55,19 @@ "format": CAN_FORMATS["ROBOT_WHEELS_VELOCITY"], "data": CAN_robot_wheels_velocty, }, - { - "packet_id": CAN_IDS["ROBOT_WHEELS_VELOCITY"], - "format": CAN_FORMATS["ROBOT_WHEELS_VELOCITY"], - "data": { - "wheel": 2, - "current_speed": 2, - "target_speed": 2, - "pwm": 2, - }, - }, - { - "packet_id": CAN_IDS["ROBOT_WHEELS_VELOCITY"], - "format": CAN_FORMATS["ROBOT_WHEELS_VELOCITY"], - "data": { - "wheel": 3, - "current_speed": 3, - "target_speed": 3, - "pwm": 3, - }, - }, + *[ + { + "packet_id": CAN_IDS["ROBOT_WHEELS_VELOCITY"], + "format": CAN_FORMATS["ROBOT_WHEELS_VELOCITY"], + "data": { + "wheel": 10 + i, + "current_speed": 20 + i, + "target_speed": 30 + i, + "pwm": 40 + i, + }, + } + for i in range(20) + ], # type: ignore { "packet_id": 0x333, "format": " None: def on_send_align(self, data) -> None: data = struct.pack(CAN_FORMATS["ALIGN"], *(CAN_align.values())) + msg = Message( arbitration_id=CAN_IDS["STRATEGY_COMMAND"], data=data,