Search this site
Embedded Files
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
  • More
    • Home
      • Computer Geek
      • Learning
      • Math Geek
      • Projects

ROS Beginner tutorial

< Back to ROS Beginner tutorials
Creating the packages
Getting the Robot ready
Robot Description
RViZ Configuration files
Gazebo World file
Launch files
Gazebo launch
Spawn model in Gazebo
RViZ launch
Robot Model inspection
Running everything
Additional
Links

We'll control a four wheel robot with a camera (one that we made in the previous page) and see in depth how everything is working out. We'll create everything from scratch here (even the packages). Since there's so much to do, I'll just give information in brief about the codes and procedures. You'll also see how to go about a project in ROS, so there's plenty of practical knowledge to be gained.

Creating the packages

We'll call the robot fwb and thus the packages can be named fwb_description for the robot description and fwb_gazebo for Gazebo simulator.

Run the following commands on a terminal:

  • cd ROS_workspaces/ros_ws/src/
    • Navigate into the src folder of your ROS workspace.
  • catkin_create_pkg fwb_description robot_state_publisher tf urdf xacro
    • The robot description package
  • catkin_create_pkg fwb_gazebo gazebo_ros
    • Package for Gazebo
  • Create folders named rviz, launch and urdf for the fwb_description package.
  • Create folders named worlds and launch for the fwb_gazebo package.

Then, make your workspace (not always necessary, but good to see if there are any existing problems)

  • cd ~/ROS_workspaces/ros_ws/
  • catkin_make
Check the links section in Additional (at the end) for links

Getting the Robot ready

Robot Description

XACRO hereGazebo here

We'll use the same robot description file that was used in the previous tutorial with the same Gazebo tags as well. We'll just make a few additions to the Robot Description to support a controller in Gazebo.

  • Add the robot description file in the urdf folder of package fwb_description, there must be a XACRO file (four_wheel_bot.xacro) and a Gazebo file (four_wheel_bot.gazebo).
    • Everything is discussed in comments of the files and in the previous tutorial, please check them.
  • There are a few differences that you'll observe for this model:
    • The vehicle is now facing towards X axis (instead of Y axis).
    • All wheel joints are actuated along +ve Z axis. This is the convention chosen by DH parameters and is the default convention for plugins made for Gazebo.
    • To comply with the sense of messages received, the facing direction must be the X axis for forward.

After that, make the following amendments to accommodate for the controller plugin, do these in the Gazebo file (four_wheel_bot.gazebo):

  • Start a <plugin ... > tag inside the <gazebo> tag for the entire model. We'll use a plugin made for a standard four wheel drive, which is skid_steer_drive. The ".so" filename (attribute) is "libgazebo_ros_skid_steer_drive.so" and it's entire code can be found here. We'll name (attribute) it "skid_steer_drive_controller". The tutorial on this is here.
    • Set the element updateRate to 100 (integer value)
    • Specify the joint names in the elements rightFrontJoint, leftFrontJoint, rightRearJoint and leftRearJoint tags.
    • Specify the wheel separation, length of bot in our case, in the element wheelSeparation tag. Specify the wheel diameter in the element wheelDiameter tag.
    • Specify the robot base frame using the element robotBaseFrame tag.
    • Specify the torque (in Nm) using the element torque tag.
    • Specify the topic name under which the command velocities will be given using the element commandTopic tag. Usually, it's "cmd_vel". The message type is "geometry_msgs/Twist".
XACRO hereGazebo here

RViZ Configuration files

RViZ file here

We'll create the RViZ file by the following process:

  • Run rviz using the following commands on different terminals (or tabs):
    • roscore
    • rosrun rviz rviz
  • Under "Global Options" make the "Fixed Frame" value to "base_link".
  • Add a RobotModel (Add -> RobotModel). Make "Alpha" value 0.75
  • Add transformation frames (Add -> TF).
  • Add a camera feed (Add -> Camera). Make the "Overlay Alpha" value 0.75. Make the value in "Image Topic" the same as we made imageTopicName in the Gazebo file.
  • Save the configuration file in the rviz folder of fwb_description package. Click on File -> Save Config As -> Navigate to the rviz folder of fwb_description package and save file as "RobotConfiguration.rviz".
RViZ file here

Gazebo World file

Gazebo world here
  • We'll use the same world file that we created in the previous page on Gazebo (page here). Move that file to a folder named "worlds" in the fwb_gazebo package.
  • You also suggested to move the individual walls and models into the same location (just for later debugging purposes). Basically, the worlds folder must look like this.
Gazebo world here

Launch files

Gazebo launch

Code here

This launch file is named "GazeboGUI.launch" and is placed in a folder named launch in package fwb_gazebo.

  • Create the following arguments:
    • world file for Gazebo.
  • Launch the following nodes:
    • gazebo from gazebo_ros package
Code here

Spawn model in Gazebo

Code here

This launch file is named "SpawnRobotGazebo.launch" and is placed in a folder named launch in package fwb_gazebo.

  • Create the following arguments:
    • xacro_model: XACRO filename with full path and extension.
    • spawn_z: Height at which model is spawned.
    • model_name: Name under which the robot will be spawned.
  • Create a parameter on the ROS parameter server named robot_description and parse the entire XACRO file into it.
  • Launch the following nodes:
    • spawn_model from gazebo_ros package to spawn the model.
Code here

RViZ launch

Code here

This launch file is named "RobotRViZ.launch" and is placed in a folder named launch in package fwb_description.

  • Create an argument for the RViZ display configuration file, we already would have launched the above two launch files so everything is already there.
  • Launch the RViZ node and the robot and joint state publishers
Code here

Robot Model inspection

Code here

There's another launch file made to inspect the robot model (named "XACROLauncher.launch") and it is placed in a folder named launch in package fwb_description. This launch file won't be used in the final stage, it's just to debug and see how to robot model development is going on.

  • Create the following arguments:
    • model: The name of XACRO model in the urdf folder of the package (no path and extension).
    • rviz_config: RViZ configuration to be used.
    • use_gui: GUI for the joint_state_publisher node.
  • Create the following parameters for the ROS parameter server:
    • robot_description: The XACRO parsed URDF code
    • use_gui: Use GUI or not for the joint_state_publisher node for inspection of the model
  • Launch the following nodes:
    • rviz for RViZ GUI
    • joint_state_publisher for giving joint states to robot_state_publisher
    • robot_state_publisher for publishing transforms to RViZ
Code here

Running everything

To run everything, we'll run the following commands on different terminals (or different tabs):

  • roslaunch fwb_gazebo GazeboGUI.launch
    • This will launch the Gazebo GUI, wait for the GUI to launch.
  • roslaunch fwb_gazebo SpawnRobotGazebo.launch
    • This will spawn the robot in the Gazebo GUI.
  • roslaunch fwb_description RobotRViZ.launch
    • This will launch the RViZ GUI to inspect the robot model and to see the camera feed.
  • rosrun teleop_twist_keyboard teleop_twist_keyboard.py
    • In case this throws an error, make sure that you have the teleop_twist_keyboard package installed. Use sudo apt install ros-melodic-teleop-twist-keyboard to install it and then try again. You can actually put this as a node under the launch file that spawns the robot model in gazebo.
  • rosrun rqt_graph rqt_graph
    • This is just so that we can see how everything is talking to each other on the computational graph level. Just for debugging purposes.

Some images taken during runtime are shown below

Gazebo GUI with the model spawned in the background and the teleop_twist_keyboard node running in the foreground (selected and active window). The node controls the robot movement in the Gazebo environment and the simulator simulates everything and shows the results.

RViZ GUI in the background showing the camera feed in the bottom left corner, this one was taken at a different moment

Everything that was spawned (without the rqt_graph node)

ROS Computation graph shown by running the rqt_graph node. Note that I've unchecked Debug and tf under Hide options on the top. Notice the roles played by the following nodes:

  • gazebo: Used to simulate the movement of robot in a world. It also provides some useful information like odometry (check out topic /odom for more on this). It is also publishing the camera images which RViZ is visualizing. It's basically creating a virtual world for everything to work in. That's what a simulator does!
  • teleop_twist_keyboard: Used to publish command velocities to the robot
  • rviz: Being used to visualize everything. The other two nodes associated with joint and robot states are to aid in displaying the robot and transformations.

You can play around with everything like mode items, have collisions in Gazebo and see how the physics simulator goes along. I'd also suggest using different physical parameters and seeing which one fits the real world best.

Woah...

Oops...

Additional

Links

  • Final fwb_gazebo package at the end of tutorial: here
  • Final fwb_description package at the end of tutorial: here
  • ROS Simulation packages on GitHub
  • Repository for teleop-twist-keyboard
< Back to ROS Beginner tutorials
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse