{"id":25050892,"url":"https://github.com/king-sj/carrobot","last_synced_at":"2025-04-14T06:42:02.153Z","repository":{"id":261474709,"uuid":"871552071","full_name":"King-sj/CarRobot","owner":"King-sj","description":"北京邮电大学创新创业智能车python版本 | BUPT Innovation and Entrepreneurship Intelligent Car Python Version","archived":false,"fork":false,"pushed_at":"2024-11-06T18:09:30.000Z","size":228,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T20:22:49.590Z","etag":null,"topics":["bupt","car","intelligence","python","smart-car","vpl"],"latest_commit_sha":null,"homepage":"https://www.bupt.online/projects/carrobot.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/King-sj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-12T09:25:22.000Z","updated_at":"2025-03-05T14:51:19.000Z","dependencies_parsed_at":"2024-11-06T19:23:48.911Z","dependency_job_id":"d86555e9-2c7d-4a77-bcd8-f806b8f44804","html_url":"https://github.com/King-sj/CarRobot","commit_stats":null,"previous_names":["king-sj/carrobot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/King-sj%2FCarRobot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/King-sj%2FCarRobot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/King-sj%2FCarRobot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/King-sj%2FCarRobot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/King-sj","download_url":"https://codeload.github.com/King-sj/CarRobot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837259,"owners_count":21169373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bupt","car","intelligence","python","smart-car","vpl"],"created_at":"2025-02-06T09:18:20.976Z","updated_at":"2025-04-14T06:42:02.100Z","avatar_url":"https://github.com/King-sj.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart cars\n\n[Go to the Go version](https://github.com/DrinkLessMilkTea/robot_car)\n\n[lib](https://github.com/King-sj/CarRobot/tree/lib)\n\n## Languages\n- [English](README.md)\n- [中文](README.zh.md)\n\n## Environment Setup\n\n- Python 3.11\n- No additional requirements\n\n## How to Start\n\n```sh\npython -m src\n```\n\n**Or just press F5 in VSCode.**\n\n## API Documentation\n\n### General Car Class\n\nFile: `src/car.py`\n\n- `Car()`: Create an instance\n- `connect()`: Asynchronously connect to the car's WiFi with tcp\n- `update_state()`: Asynchronously update the car's state\n- `set_speed(...)`: Set the car's speed\n- `distance`: Distance to an obstacle\n- `in_road`: Whether the car is on the correct path\n- `have_obstacle`: Whether there is an obstacle ahead (based on infrared signals)\n\n### Minimal Demo\n\n```py\nfrom src.car import Car\nfrom src.logging_config import setup_logging\nimport logging\nfrom src.config import Config\nimport asyncio\nlogger = logging.getLogger(__name__)\n# @attention await sleep some times is necessary to release thread for other coroutine.\nasync def control_car(car: Car):\n  car.set_speed(0.5, 0.5)\n  while True:\n    print(f\"current state: {car.distance}, {car.in_road}, {car.have_obstacle}\")\n    if car.distance is None or car.in_road is None or car.speed is None:\n      await asyncio.sleep(0.1)\n      continue\n    if car.distance \u003c 20:\n      print(\"change state\")\n      car.set_speed(0.5, 0.0)\n    else:\n      print(\"change state\")\n      car.set_speed(0.5, 0.5)\n    await asyncio.sleep(0.1)\n\nasync def main():\n  setup_logging()\n  car = Car()\n  await car.connect()\n  await asyncio.gather(\n    car.update_state(),\n    control_car(car)\n  )\n\nif __name__ == \"__main__\":\n  logger.setLevel(Config.LOG_LEVEL)\n  asyncio.run(main())\n  print(\"done\")\n```\n\n### Intelligent Car\n\nFile: `src/robot_craft_car.py`\n\n- `class RobotCraftCar(Car)`: Further encapsulation for car\nsome example\n```py\nfrom src.car import Car\nfrom enum import Enum\nfrom typing import Callable\nimport asyncio\nclass Direction(Enum):\n  LEFT = \"left\"\n  RIGHT = \"right\"\n\nclass RobotCraftCar(Car):\n  def __init__(self):\n    super().__init__()\n  def straight(self):\n    self.set_speed(0.2,0.2)\n  def low_straight(self):\n    self.set_speed(0.2,0.2)\n  def turn_left(self):\n    self.set_speed(-0.1,0.1)\n  def turn_right(self):\n    self.set_speed(0.1,-0.1)\n  async def adjustment_dir(self, dir:Direction, duration:float, is_right_gesture:Callable):\n    time_left = duration\n    if (dir == Direction.LEFT):\n      self.turn_left()\n    else:\n      self.turn_right()\n    while time_left \u003e 0:\n      if is_right_gesture():\n        break\n      time_left -= 0.1\n      await asyncio.sleep(0.1)\n    self.straight()\n```\n### Example Usage\n\n```py\nfrom src.robot_craft_car import RobotCraftCar as Car, Direction\nfrom src.logging_config import setup_logging\nimport logging\nfrom src.config import Config\nimport asyncio\n\nlogger = logging.getLogger(__name__)\n\nasync def control_car(car: Car):\n  car.set_speed(0.3, 0.3)\n  while True:\n    print(f\"current state: {car.distance}, {car.in_road}, {car.have_obstacle}\")\n    if car.distance is None or car.in_road is None or car.speed is None:\n      await asyncio.sleep(0.1)\n      continue\n    if not car.in_road:\n      await car.adjustment_dir(Direction.RIGHT, 1, lambda: car.in_road)\n    if car.distance \u003c 20:\n      print(\"change state\")\n      await car.adjustment_dir(Direction.RIGHT, 1, lambda: car.distance is not None and car.distance \u003e 40)\n    await asyncio.sleep(0.1)\n\nasync def main():\n  setup_logging()\n  car = Car()\n  await car.connect()\n  await asyncio.gather(\n    car.update_state(),\n    control_car(car)\n  )\n\nif __name__ == \"__main__\":\n  logger.setLevel(Config.LOG_LEVEL)\n  asyncio.run(main())\n  print(\"done\")\n```\n\n## Communication Protocol\n\n![Protocol Diagram 1](image-1.png)\n![Protocol Diagram 2](image.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fking-sj%2Fcarrobot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fking-sj%2Fcarrobot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fking-sj%2Fcarrobot/lists"}