├── .github └── workflows │ └── manual.yml ├── CODEOWNERS ├── LICENSE ├── README.md └── wall_follower.cpp /.github/workflows/manual.yml: -------------------------------------------------------------------------------- 1 | # Workflow to ensure whenever a Github PR is submitted, 2 | # a JIRA ticket gets created automatically. 3 | name: Manual Workflow 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on pull request events but only for the master branch 8 | pull_request_target: 9 | types: [opened, reopened] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | jobs: 15 | test-transition-issue: 16 | name: Convert Github Issue to Jira Issue 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@master 21 | 22 | - name: Login 23 | uses: atlassian/gajira-login@master 24 | env: 25 | JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} 26 | JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} 27 | JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} 28 | 29 | - name: Create NEW JIRA ticket 30 | id: create 31 | uses: atlassian/gajira-create@master 32 | with: 33 | project: CONUPDATE 34 | issuetype: Task 35 | summary: | 36 | Github PR [Assign the ND component] | Repo: ${{ github.repository }} | PR# ${{github.event.number}} 37 | description: | 38 | Repo link: https://github.com/${{ github.repository }} 39 | PR no. ${{ github.event.pull_request.number }} 40 | PR title: ${{ github.event.pull_request.title }} 41 | PR description: ${{ github.event.pull_request.description }} 42 | In addition, please resolve other issues, if any. 43 | fields: '{"components": [{"name":"Github PR"}], "customfield_16449":"https://classroom.udacity.com/", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}' 44 | 45 | - name: Log created issue 46 | run: echo "Issue ${{ steps.create.outputs.issue }} was created" 47 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @udacity/active-public-content -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Udacity 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Udacity - Robotics NanoDegree Program](https://s3-us-west-1.amazonaws.com/udacity-robotics/Extra+Images/RoboND_flag.png)](https://www.udacity.com/robotics) 2 | 3 | # RoboND-PathPlanning 4 | A wall_follower ROS C++ node for the Home Service Robot Project. This node will autonomously drive your robot close to the walls while avoiding obstacles on its path. 5 | 6 | ### Basic Idea 7 | A wall follower algorithm is a common algorithm that solves mazes. This algorithm is also known as the left-hand rule algorithm or the right-hand rule algorithm depending on which is your priority. The wall follower can only solve mazes with connected walls, where the robot is guaranteed to reach the exit of the maze after traversing close to walls. You will implement this basic algorithm in your environment to travel close to the walls and autonomously map it. 8 | 9 | Here’s the wall follower algorithm(the left-hand one) at a high level: 10 | ``` 11 | If left is free: 12 | Turn Left 13 | Else if left is occupied and straight is free: 14 | Go Straight 15 | Else if left and straight are occupied: 16 | Turn Right 17 | Else if left/right/straight are occupied or you crashed: 18 | Turn 180 degrees 19 | ``` 20 | 21 | This algorithm has a lot of disadvantages because of the restricted space it can operate in. In other words, this algorithm will fail in open or infinitely large environments. Usually, the best algorithms for autonomous mapping are the ones that go in pursuit of undiscovered areas or unknown grid cells. 22 | 23 | ### Task List 24 | Here's a detailed task list of the steps you should take in order to implement this package with your home service robot to autonomously map an environment: 25 | 1. Create a **wall_follower** package. 26 | 2. Create a **wall_follower** C++ node by cloning this repo. 27 | 3. Edit the wall_follower C++ **node name** and change it to **wall_follower**. 28 | 4. Edit the wall_follower C++ subscriber and publisher **topics name**. 29 | 5. Write a **wall_follower.sh** shell script that launch the **turtlebot_world.launch**, **gmapping_demo.launch**, **view_navigation.launch**, and the **wall_follower** node. 30 | 6. Edit the **CMakeLists.txt** file and add directories, executable, and target link libraries. 31 | 7. Build your **catkin_ws**. 32 | 8. Run your **wall_follower.sh** shell script to autonomously map the environment. 33 | 9. Once you are satisfied with the map, kill the wall_follower terminal and save your map in both **pgm** and **yaml** formats in the **World** directory of your **catkin_ws/src**. 34 | -------------------------------------------------------------------------------- /wall_follower.cpp: -------------------------------------------------------------------------------- 1 | // ROS Libraries 2 | #include "ros/ros.h" 3 | #include "geometry_msgs/Twist.h" // Motor Commands 4 | #include "sensor_msgs/LaserScan.h" // Laser Data 5 | #include "tf/transform_listener.h" // tf Tree 6 | 7 | // C++ Libraries 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | // ROS Publisher:Motor Commands, Subscriber:Laser Data, and Messages:Laser Messages & Motor Messages 14 | ros::Publisher motor_command_publisher; 15 | ros::Subscriber laser_subscriber; 16 | sensor_msgs::LaserScan laser_msg; 17 | geometry_msgs::Twist motor_command; 18 | 19 | // Define the robot direction of movement 20 | typedef enum _ROBOT_MOVEMENT { 21 | STOP = 0, 22 | FORWARD, 23 | BACKWARD, 24 | TURN_LEFT, 25 | TURN_RIGHT, 26 | GO_RIGHT, 27 | GO_LEFT 28 | 29 | } ROBOT_MOVEMENT; 30 | 31 | // The robot_move function will be called by the laser_callback function each time a laser scan data is received 32 | // This function will accept robot movements and actuate the robot's wheels accordingly 33 | // Keep a low speed for better results 34 | bool robot_move(const ROBOT_MOVEMENT move_type) 35 | { 36 | if (move_type == STOP) { 37 | ROS_INFO("[ROBOT] HALT! \n"); 38 | 39 | motor_command.angular.z = 0.0; 40 | motor_command.linear.x = 0.0; 41 | } 42 | 43 | else if (move_type == FORWARD) { 44 | ROS_INFO("[ROBOT] Always FORWARD! \n"); 45 | motor_command.angular.z = 0.0; 46 | motor_command.linear.x = 0.5; 47 | } 48 | 49 | else if (move_type == BACKWARD) { 50 | ROS_INFO("[ROBOT] I'm going back! \n"); 51 | motor_command.linear.x = -0.75; 52 | motor_command.angular.z = 0.0; 53 | } 54 | 55 | else if (move_type == TURN_LEFT) { 56 | ROS_INFO("[ROBOT] I'm turning left! \n"); 57 | motor_command.linear.x = 0.0; 58 | motor_command.angular.z = 1.0; 59 | } 60 | 61 | else if (move_type == TURN_RIGHT) { 62 | ROS_INFO("[ROBOT] I'm turning right! \n"); 63 | motor_command.linear.x = 0.0; 64 | motor_command.angular.z = -1.0; 65 | } 66 | else if (move_type == GO_RIGHT) { 67 | ROS_INFO("[ROBOT] I'm goin right! \n"); 68 | motor_command.linear.x = 0.25; 69 | motor_command.angular.z = -0.25; 70 | } 71 | else if (move_type == GO_LEFT) { 72 | ROS_INFO("[ROBOT] I'm goin left! \n"); 73 | motor_command.linear.x = 0.25; 74 | motor_command.angular.z = 0.25; 75 | } 76 | else { 77 | ROS_INFO("[ROBOT_MOVE] Move type wrong! \n"); 78 | return false; 79 | } 80 | 81 | //Publish motor commands to the robot and wait 10ms 82 | motor_command_publisher.publish(motor_command); 83 | usleep(10); 84 | return true; 85 | } 86 | 87 | bool following_wall = false; 88 | bool thats_a_door = false; 89 | bool crashed = false; 90 | 91 | // The laser_callback function will be called each time a laser scan data is received 92 | void laser_callback(const sensor_msgs::LaserScan::ConstPtr& scan_msg) 93 | { 94 | // Read and process laser scan values 95 | laser_msg = *scan_msg; 96 | std::vector laser_ranges; 97 | laser_ranges = laser_msg.ranges; 98 | size_t range_size = laser_ranges.size(); 99 | float left_side = 0.0, right_side = 0.0; 100 | float range_min = laser_msg.range_max, range_max = laser_msg.range_min; 101 | int nan_count = 0; 102 | for (size_t i = 0; i < range_size; i++) { 103 | if (laser_ranges[i] < range_min) { 104 | range_min = laser_ranges[i]; 105 | } 106 | 107 | if (std::isnan(laser_ranges[i])) { 108 | nan_count++; 109 | } 110 | if (i < range_size / 4) { 111 | if (laser_ranges[i] > range_max) { 112 | range_max = laser_ranges[i]; 113 | } 114 | } 115 | 116 | if (i > range_size / 2) { 117 | left_side += laser_ranges[i]; 118 | } 119 | else { 120 | right_side += laser_ranges[i]; 121 | } 122 | } 123 | 124 | // Check if the robot has crashed into a wall 125 | if (nan_count > (range_size * 0.9) || laser_ranges[range_size / 2] < 0.25) { 126 | crashed = true; 127 | } 128 | else { 129 | crashed = false; 130 | } 131 | 132 | // Assign movements to a robot that still did not crash 133 | if (!crashed) { 134 | 135 | if (range_min <= 0.5 && !thats_a_door) { 136 | following_wall = true; 137 | crashed = false; 138 | robot_move(STOP); 139 | 140 | if (left_side >= right_side) { 141 | robot_move(TURN_RIGHT); 142 | } 143 | else { 144 | robot_move(TURN_LEFT); 145 | } 146 | } 147 | else { 148 | ROS_INFO("[ROBOT] Dam son: %f , %d \n", range_max, following_wall); 149 | robot_move(STOP); 150 | if (following_wall) { 151 | if (range_max >= 2.0) { 152 | thats_a_door = true; 153 | following_wall = false; 154 | //robot_move(TURN_RIGHT); 155 | ROS_INFO("[ROBOT] I am following wall and my max range > 2.0 Range Max: %f \n", range_max); 156 | } 157 | } 158 | if (thats_a_door) { 159 | if (laser_ranges[0] <= 0.5) { 160 | thats_a_door = false; 161 | } 162 | else { 163 | robot_move(GO_RIGHT); 164 | } 165 | ROS_INFO("[ROBOT] I am goin' right!: %d \n", thats_a_door); 166 | } 167 | else { 168 | robot_move(FORWARD); 169 | } 170 | } 171 | } 172 | // Robot should go backward since it crashed into a wall 173 | else { 174 | robot_move(BACKWARD); 175 | } 176 | } 177 | 178 | int main(int argc, char** argv) 179 | { 180 | // Initialize a ROS node 181 | ros::init(argc, argv, "node"); 182 | 183 | // Create a ROS NodeHandle object 184 | ros::NodeHandle n; 185 | 186 | // Inform ROS master that we will be publishing a message of type geometry_msgs::Twist on the robot actuation topic with a publishing queue size of 100 187 | motor_command_publisher = n.advertise("/robotactuate", 100); 188 | 189 | // Subscribe to the /scan topic and call the laser_callback function 190 | laser_subscriber = n.subscribe("/laserscan", 1000, laser_callback); 191 | 192 | // Enter an infinite loop where the laser_callback function will be called when new laser messages arrive 193 | ros::Duration time_between_ros_wakeups(0.001); 194 | while (ros::ok()) { 195 | ros::spinOnce(); 196 | time_between_ros_wakeups.sleep(); 197 | } 198 | 199 | return 0; 200 | } 201 | --------------------------------------------------------------------------------