{"id":28372934,"url":"https://github.com/dmytro-varich/bug2-algorithm-webots-bot","last_synced_at":"2025-07-21T08:32:03.509Z","repository":{"id":293473387,"uuid":"981623444","full_name":"dmytro-varich/Bug2-Algorithm-Webots-Bot","owner":"dmytro-varich","description":"This project demonstrates the implementation of classical Bug 2 navigation algorithms in a simulated environment using Webots, including the development of a custom robot model and a designed simulation environment with obstacles.","archived":false,"fork":false,"pushed_at":"2025-05-16T17:55:52.000Z","size":13970,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-25T12:51:15.326Z","etag":null,"topics":["bug2-algorithm","obstacle-avoidance","planning-algorithms","python","webots"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmytro-varich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-05-11T14:29:59.000Z","updated_at":"2025-05-16T20:28:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"c56d2d66-2990-409a-82ad-4b52b39b0794","html_url":"https://github.com/dmytro-varich/Bug2-Algorithm-Webots-Bot","commit_stats":null,"previous_names":["dmytro-varich/bug-algorithm-webots-bot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dmytro-varich/Bug2-Algorithm-Webots-Bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmytro-varich%2FBug2-Algorithm-Webots-Bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmytro-varich%2FBug2-Algorithm-Webots-Bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmytro-varich%2FBug2-Algorithm-Webots-Bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmytro-varich%2FBug2-Algorithm-Webots-Bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmytro-varich","download_url":"https://codeload.github.com/dmytro-varich/Bug2-Algorithm-Webots-Bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmytro-varich%2FBug2-Algorithm-Webots-Bot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266267200,"owners_count":23902310,"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":["bug2-algorithm","obstacle-avoidance","planning-algorithms","python","webots"],"created_at":"2025-05-29T18:30:17.135Z","updated_at":"2025-07-21T08:32:03.502Z","avatar_url":"https://github.com/dmytro-varich.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🐞 Bug 2 Algorithm Webots Bot\n![Bug 2 Header](https://github.com/dmytro-varich/Bug2-Algorithm-Webots-Bot/blob/main/assets/Bug2_Project_Header.png)\nThis project demonstrates the implementation of classical [Bug 2](https://medium.com/@sefakurtipek/robot-motion-planning-bug-algorithms-34cf5175ab39) navigation algorithms in a simulated environment using Webots. It includes the development of a custom robot model and a designed simulation environment with obstacles. This project was completed as part of the **Intelligent Robotics** course at [TUKE](https://www.tuke.sk/).\n\n## 🗂️ Project Structure\n```\nBug2-Algorithm-Webots-Bot/\n├── controllers/\n│   └── bug_2_controller/\n│       ├── bug_2_controller.py        # Main control script implementing Bug2 algorithm\n│       ├── initialization.py          # Initialization of sensors, motors, and robot parameters\n│       └── navigation_utils.py        # Utility functions for navigation logic and state handling\n├── protos/\n│   ├── boxObject.proto                # Custom obstacle/object prototype\n│   └── robotModel.proto               # Custom robot model definition\n├── worlds/\n│   └── world.wbt                      # Webots world file with robot and obstacles\n```\n\n## 🛠️ Tech Stack:\n- Language: `Python`\n- Environment: `Webots`\n- Robot Model: `Custom`\n- Algorithm: `Bug2`\n  \n## 🎥 Demo Video\nhttps://github.com/user-attachments/assets/14758d53-76c9-48fe-9161-3371dce5e57a\n\n## ▶️ How to run\n1. Install [Webots](https://cyberbotics.com/).\n\n2. Clone the repository:\n\n   ```bash\n   git clone https://github.com/dmytro-varich/Bug2-Algorithm-Webots-Bot.git\n   ```\n\n3. Open the `world.wbt` file in Webots.\n\n4. Start the simulation.\n\n5. The robot will begin moving toward the goal, navigating around obstacles using the Bug2 algorithm.\n\n## 🔁 Algorithm\n![Bug 2 Scheme](https://github.com/dmytro-varich/Bug-Algorithm-Webots-Bot/blob/main/assets/Bug_2_Scheme.png)\n\nThe **Bug2 algorithm** is a classical path-planning algorithm for mobile robots navigating in environments with unknown obstacles. It combines **goal-oriented motion** with **obstacle following**, making it both simple and effective for many robotic applications. Bug2 allows a robot to move towards a goal in a straight line (called the **M-line**) until it encounters an obstacle. When that happens, the robot follows the obstacle’s boundary until it can **rejoin the M-line** and continue toward the goal.\n\n## 🤖 Robot Model\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/dmytro-varich/Bug2-Algorithm-Webots-Bot/blob/main/assets/robot_model.gif\" alt=\"Robot Model 3D view\" /\u003e\n\u003c/p\u003e\n\nThe robot model in Webots represents a mobile platform with a differential drive and a set of sensors for navigation and spatial orientation. The robot is equipped with various sensors, including **lidars**, a **compass**, **GPS**, and **ultrasonic sensors (sonars)**, enabling obstacle detection and environmental awareness. Each wheel is controlled by a **motor** and tracked with a **position encoder** to enable precise motion control. Both the wheels and the robot body have `boundingObjects` defined via `Shape` (Cylinder). A simplified physical behavior is specified (**mass**, **density**) suitable for motion simulation.\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eDrives and Wheels\u003c/b\u003e\u003c/summary\u003e\n\n| Wheel        | Position       | Mass | Size           | Motor         |\n| ------------ | -------------- | ---- | -------------- | ------------- |\n| `wheel_left`  | Rear left      | 1 kg | r=0.05, h=0.03 | `motor_left`  |\n| `wheel_right` | Rear right     | 1 kg | r=0.05, h=0.03 | `motor_right` |\n| `wheel_rear`  | Support (rear) | 5 kg | r=0.05, h=0.04 | `motor_rear`  |\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eLidars\u003c/b\u003e\u003c/summary\u003e\n\n| Name          | Position      | Field of View | Range | Resolution |\n| ------------- | ------------- | ------------- | ----- | ---------- |\n| `lidar_front` | Front         | ~60°          | 0.5 m | 256        |\n| `lidar_left`  | Left          | ~45°          | 0.6 m | 256        |\n| `lidar_right` | Right (fixed) | ~45°          | 0.6 m | 256        |\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eUltrasonic Distance Sensors (Sonars)\u003c/b\u003e\u003c/summary\u003e\n\n| Name               | Position   | Direction          | Max Range |\n| ------------------ | ---------- | ------------------ | --------- |\n| `sonar_front`       | Front      | Forward            | 0.5 m     |\n| `sonar_right`       | Right      | Right              | 0.5 m     |\n| `sonar_back_right`  | Back right | Back-right (~30°)  | 0.5 m     |\n| `sonar_left`        | Left       | Left               | 0.5 m     |\n| `sonar_back_left`   | Back left  | Back-left (~30°)   | 0.5 m     |\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cb\u003eAdditional Sensors\u003c/b\u003e\u003c/summary\u003e\n\n* **GPS** — determines the global coordinates of the robot.  \n* **Compass** — measures orientation relative to magnetic north.\n\u003c/details\u003e\n\n## ⚙️ Implementation\n![Bug 2 Algorithm](https://github.com/dmytro-varich/Bug-Algorithm-Webots-Bot/blob/main/assets/Bug2_Algorithm.drawio.png)\n\nThe algorithm is implemented in **Python** using the **Webots** simulation environment with a custom robot model. The navigation logic is based on two main states: `go_to_goal` (moving towards the target) and `follow_wall` (obstacle avoidance). The robot relies on **GPS**, **compass**, **lidar**, and **ultrasonic sensors** to perceive its environment and make decisions.\n\nAt the start, the robot determines its initial position and begins moving in a straight line towards the goal (the so-called **M-line**). If it encounters an obstacle, it switches to the `follow_wall` state, where it follows the boundary of the obstacle. The robot records the **hit point** (where it first touches the obstacle) and searches for a **leave point** on the M-line that is closer to the goal.\n\nWhile following the wall, the robot transitions between substates:\n\n* `turn_right` — turning right when an obstacle is directly in front.\n* `turn_left` — turning left if the wall is lost on the left side.\n* `move_forward` — moving forward along the wall.\n* `search_wall` — searching for the wall after a turn.\n\nWhen the robot returns to the M-line and is closer to the goal than it was at the hit point, it switches back to `go_to_goal` and continues moving towards the target. The implementation also includes a safeguard against infinite loops: if the robot returns to the hit point on the M-line and the goal is still unreachable, it stops and concludes that the goal cannot be reached.\n\n## 🧛🏻 Author\nDmytro Varich is the creator of this robotics project. You can learn more about his projects on his personal [Telegram channel](https://t.me/varich_channel), as well as connect with him via LinkedIn ([dmytro-varich](https://www.linkedin.com/in/dmytro-varich/)) and email (varich.it@gmail.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmytro-varich%2Fbug2-algorithm-webots-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmytro-varich%2Fbug2-algorithm-webots-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmytro-varich%2Fbug2-algorithm-webots-bot/lists"}