Skip to content

All the details (and unique quirks) that I found out during my Summer Internship

Notifications You must be signed in to change notification settings

Piebee007/Setting-up-a-world-in-Gazebo

Repository files navigation

Setting-up-a-world-in-Gazebo

All the details (and unique quirks) that I found out during my Summer Internship

Prerequisites:

  • ROS2 Galactic installed on Ubuntu Linux 20.04
    • Note: this tutorial is designed for Ros2 Foxy so replace all "foxy" with "galactic"
  • You have created a ROS 2 workspace (I had "dev_ws")
  • Python 3.7 installed
  • You have a package named two_wheeled_robot inside ~/dev_ws/src

Useful Resources

A very useful series of websites is made by AutomaticAddison. Some of the sections in the website is out of date so take all the files from their Github

If in doubt:

  • StackOverflow
  • Gazebo Answers
  • ROS Answers

Adding a custom model to Gazebo:

Option 1

Follow these steps first. Only go to option 2 if you can't save the Gazebo world

  1. Load up gazebo (in verbose mode you can find any errors that come up)

    gazebo --verbose

  2. Go to Edit -> Model Editor (Ctrl + M)

  3. Go to Custom Shapes and click add

  4. Then browse for the model you want to add

    This will be a collada (.dae) file

    Make sure the collada file is in a folder with all the textures required

  5. Place your model in the world and save the model

  6. To change the model from grey to the textures you added:

    1. Go to your file manager and go to the folder model_editor_models
    2. Find the folder corresponding to the model name you just saved
    3. Open the model.sdf
    4. Delete this seciton of code:
       <material>
         <lighting>1</lighting>
         <script>
           <uri>file://media/materials/scripts/gazebo.material</uri>
           <name>Gazebo/Grey</name>
         </script>
         <shader type='pixel'/>
       </material>
    
  7. Delete the model from your world

  8. Insert the model (from the insert tab)

  9. Repeat these steps until you have created your desired world

  10. To save the world, go to File -> Save World As (Ctrl + shift + s)

Option 2

If you encounter an issue where you can't save your gazebo world, follow these steps

  1. Load up Gazebo using sudo

     `sudo gazebo --verbose`
    
  2. Follow steps 2 - 5 in Option 1

  3. To change the model from grey to the textures you added:

    1. Open a new terminal and type:

    sudo nautilus

    1. Find the folder corresponding to the model name you just saved
    2. Open the model.sdf
    3. Delete this seciton of code:
       <material>
         <lighting>1</lighting>
         <script>
           <uri>file://media/materials/scripts/gazebo.material</uri>
           <name>Gazebo/Grey</name>
         </script>
         <shader type='pixel'/>
       </material>
    
  4. Delete the model from your world

  5. Insert the model (from the insert tab)

  6. Repeat these steps until you have created your desired world

  7. To save the world, go to File -> Save World As (Ctrl + shift + s)

Make a world

  1. Open Gazebo
  2. Add what ever models to your world that you would like
  3. Save the model in thee two_wheeled_robots/worlds folder
  4. Open up that file and paste this section of code at the end just above :
    <include>
     <uri>model://two_wheeled_robot_description</uri>
     <static>false</static>
     <pose>-20.0 4.0 3.5 0 0 0</pose>
    </include> 
    

How to launch the world

  1. Creating the launch file

    colcon_cd two_wheeled_robot

    cd launch

    gedit load_world_into_gazebo.launch.py

  2. Add the code from the load_world_into_gazebo.launch.py file which is in the repository

  3. Change line 24 from world_file_name = 'CHANGE_ME.world' to the name of your world

  4. Save the file and close it

  5. Go to your root directory

    cd ~/dev_ws

  6. Build the package

    colcon build

  7. Open a new terminal and run the launch file using this command:

    ros2 launch two_wheeled_robot load_world_into_gazebo.launch.py

Creating a map for RVIZ

Creating a map for rviz involves taking a picture of the floor plan (either .png or .jpeg) and outputs a .pmg and a .yaml file which sets the scale of the map

BE AWARE: door diagrams and other marks in the picture will be perceived as a wall. Use software like paint to remove the unnecessary information

  1. Add the files needed which is in the maps folder in the root directory

    1. Add the file convert_to_binary.py
    2. Add the file MakeROSMap.py
  2. Change the file names in the "convert_to_binary.py" indicated by the CHANGE_ME

  3. Convert the floorplan to binary and then make the ros map

    To run code do python3 *insert file name here* in a terminal

    Follow the prompts in the terminal

  4. Edit the .yaml file kjhdsakjhsakjdhfkjsdhgkjsfkjheksjfhkjhkjdhksjhkjhkjhkjhkjkjhkjhkjh

Launch RVIZ

Editing the launch file:

Change the file names in the launch file

def generate_launch_description():
  package_name = 'two_wheeled_robot'
  robot_name_in_model = 'two_wheeled_robot'
  default_launch_dir = 'launch'
  gazebo_models_path = 'models'
  map_file_path = 'maps/CHANGE_ME.yaml'
  nav2_params_path = 'params/CHANGE_ME/nav2_params.yaml'
  robot_localization_file_path = 'config/ekf.yaml'
  rviz_config_file_path = 'rviz/CHANGE_ME/nav2_config.rviz'
  sdf_model_path = 'models/two_wheeled_robot_description/model.sdf'
  urdf_file_path = 'urdf/two_wheeled_robot.urdf'
  world_file_path = 'worlds/CHANGE_ME.world'

Launching

Note: After any edit of any file, you must rebuild the file

  1. Open a new terminal and go to the root directory and build the files

    cd ~/dev_ws

    colcon build

  2. Open another new terminal and type in this command:

    ros2 launch two_wheeled_robot *insert_launch_file_name*.launch.py

Setting up the Camera

Assumption that the two_wheeled_robot 's .sdf and .udrf has been set up for using a camera

  1. Click on the button "ADD" which is on the left of the screen
  2. Go to By topic -> /depth camera/ image and click OK
  3. Find the image in the Display section (on the left of the screen)
  4. Go to Topic -> Reliaility Pollicy and change from "Reliable" to "Best Effort"

Note: You can drag the image section out of the rviz window to have a seperate window of what the robot camera is seeing

Moving the robot

To install the the package type this command:

sudo apt-get install ros-galactic-rqt-robot-steering

Then open a new terminal and to run the program type this command:

rqt_robot_steering

You can either interact with the GUI with your mouse or using WASD to move the robot.

Note: Having the camera set up makes moving the robot around a lot easier

About

All the details (and unique quirks) that I found out during my Summer Internship

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages