Understanding Files and Launching the robot in RVIZ and Gazebo

 Previously on this page...…

  • We assembled the robot in Fusion360 and exported it into urdf file.
  • We took a brief look at different folders and files generated by exporter.
  • And if you considered bonus point you may successfully launched robot in gazebo, if not ,don't worry we will launch it again in this post.

 Understanding Different files generated....

  • launch files:

  1. Controller.launch: this file is supplement of gazebo.launch file, it is good convention to keep it as different launch file since it consist of joint controllers of robot in gazebo simulator, you may wonder what the controllers do in simulation, as name suggests, they control the state of joints of robot, provide feedback. Also once the controllers are loaded you can publish data, what you want the state of joint to be and can receive feedback as well, this is how the file looks:

    don't worry if your file don't look like this I have formatted  so that it looks clean and easy to handle, lets take a look at each and every line: since it is markup language we will be seeing tags every where, to make any file a launch file, we have to initialize launch tag, then we open rosparameter tag and inside it we give a file which is controller.yaml and load it, I want you to take a look at it you will find it in same launch folder, I want you to explore YAML format as well, basically it is used to store and transmit data, in our use case its storing p,i,d gain values used by controllers, we will discuss more about pid in next post, After the yaml file is loaded we use node tag to spawn the controllers to gazebo and in next tag we initialize robot-state-publisher node from the package and remap the publishing topic to our robot's joint-state topic and then launch tag is closed.
  2. Display.launch: this file is used to launch the RVIZ, Rviz is a power full visualization tool which helps us to visualize what the robot is doing and sensing about environment we will be using this tool further in project when we will add sensor to robot and try to automate it.
    Have a look at it and try to understand the tags as they are similar so will not be explaining it line by line but in short it will set the arguments and initialize the  Rviz nodes, one tag is missing in this for users of ros noetic, if you have ros melodic then you find that joint control is available in gui while noetic users have to load it separately we will do this in next section.
  3. Gazebo.launch: this file is main file which launches robot in gazebo and this file looks like this:

     Lets understand this file ,again its in markup language we open launch tag inside it we load urdf as parameter under name robot_description and then initialize the spawn node from gazebo_ros package , also we include empty_world.launch from gazebo_ros pkg, we set default arguments and after that in image you will find the below tags are similar to controller launch file I have pasted it here so that we need not to launch the file separately, its not recommended to you to do this until you have checked and resolved errors in controller file, also I have commented one tag in include which is world (environment) for the robot, we will make it in upcoming posts, now I want you to explore urdf.rviz file and let me know in comments what it does.

  • Xacro file: this file is inside urdf folder, there are two of these, one is pnp_bot.xacro and other is material.xacro , which will contain any material used by urdf file by default its silver and its color is mentioned you can create your own, now coming to pnp_bot.xacro it is main urdf file if you are curious to know more about xacro click here and ros has its know tutorials for creating urdf by coding in xacro file if your are codding enthusiast  click here to visit the tutorials now lets have look at file:
    here you will see lots of tags I want you to go through urdf tutorials to get familiar with these tags just complete learning urdf step by step section.

  • Gazebo file: this file will contain all gazebo required parameters like physics parameters, plugins , this file helps gazebo to simulate the robot as real world, you will see mu1 mu2 tags which are nothing but friction parameter, also you will find plugin and gazebo tags we will discuss these in next section.

  • Trans file: this file will help gazebo to simulate the transmission for different actuators/joints to know more about this click here in transmission section.

Launching Rviz and Gazebo.....

1.Rviz:
  • open terminal and type : roslaunch pnp_bot_description display.launch
  • this will start two windows if you are using ros melodic and if noetic only one window will pop like this:


  • don't take image as it is, there is error in my fileπŸ˜… and I neglected it while launching this file, you will not encounter such error don't worry
  • so  for ros melodic users the second window is for joint_state_publisher which by default include gui in melodic while for noetic users go to display launch file and just replace joint_state_publisher with joint_state_publisher_gui and it will launch gui window as well 
  • if you encounter any error then try to install joint_state_publisher_gui package via typing 'sudo apt-get install ros-noetic-joint-state-publisher-gui' .
  • when gui is launched you can control joint positions in Rviz, here is my window:

  • I have fixed that problem nowπŸ˜… and launched it with gui if you followed above steps then you will find these two windows.

2. Gazebo launch:

  • now if you have launched Rviz and have tested the joints, now you can launch it in gazebo, you might be wondering where is color of robot, for gazebo it will display as sliver color as it set by default in material.xacro file  we change it there.
  • The mesh file used by the xacro is stl which is color less you can use any other mesh file specifically dae file which will give color to mesh but its not recommended for beginner, we will do it in further projects.
  • now type : roslaunch pnp_bot_description gazebo.launch in terminal and gazebo will launch the robot.
  • you will notice that simulation is paused, feel free to play it, so to see your robot without any control.
  • but watching the only robot without control is boring right πŸ˜”, lets control it, first kill the master by pressing "ctrl+c" in terminal where you launch gazebo.
  • open pnp_bot.gazebo file and in just below 1st gazebo close tag paste the differential-drive plugin from gazebo-plugins , you will find it in differential drive section, after following the steps your file will look like this:
  • Ignore the comments in first plugin you will not find them in your file, you can notice I have change the joint values to wheels joint of robot.
  • you will need to change some values in this plugin, change the name of left side wheel joints to your rev joints similarly change it for right side, then if you want you can change wheel acceleration and torque, and make sure to change value of wheel separation and diameter of wheel to actual values and then keep the else part as it is.
  • now again launch the robot in gazebo by typing same gazebo launch command.
  • open a new terminal and type rosrun teleop_twist_keyboard teleop_twist_keyboard.py , if you encounter message that can't run the package or there is no package...….
  • In this case you don't have package teleop_twist_keyboard installed , to install it follow the convention: sudo apt-get install ros-<distro>-<package> make sure to replace <distro> with your version of ros and <package> with teleop-twist-keyboard, yes you guessed it correctly while installing any package replace underscore(_) with dash(-)
  • now again try and run rosrun teleop_twist_keyboard teleop_twist_keyboard.py  in new terminal and it will take some time to run and display messages that which button do what.





  • now you can control the movement of robot, take your time to celebrate 😝 and keep yourself motivated for upcoming posts.

Upcoming.....

  • We will see how to control the joints of robot (other than wheels)
  • We will add colors to robot and make environment for it.
  • We will be writing scripts for the joints. 



Comments

Popular posts

Introduction

Getting started......