Lab 4: Robot Model and Gazebo
Seneca Polytechnic AIG240 Robotics
Introduction
URDF
URDF (Unified Robot Description Format) is an XML format for representing a robot model. URDF is commonly used in Robot Operating System (ROS) tools such as RViz (ROS Visualization tool) and Gazebo simulator. It is essentially a 3D model with information about joints, motors, mass, etc. The files are then run through the Robot Operating System (ROS). The data from the file informs the human operator what the robot looks like and is capable of before they begin operating the robot.
More details on the URDF specification can be found here.
Many robotic manufacturers have URDF models of their devices available for download. These include the Segway RMP, TurtleBot, and AR10.
More Models:
- Agility Robotics Digit
 - ANYbotics Anymal
 - Boston Dynamics Spot (via Clearpath ROS Driver)
 - Clearpath Jackal
 - Clearpath Dingo
 - Clearpath Husky
 - Clearpath TurtleBot
 - Unitree Go1
 - Universal Robots
 
URDF vs XACRO
URDF (Unified Robot Description Format) and XACRO (XML Macros) are both used in ROS (Robot Operating System) for robot modeling, but they have distinct roles. URDF is a straightforward XML format that describes the physical structure of a robot, detailing its links and joints, as well as their properties like geometry and dynamics. It is ideal for simpler robot designs where the model's complexity is limited. In contrast, XACRO is an extension of URDF that incorporates macros, allowing for parameterization and reducing redundancy in model descriptions. This makes XACRO particularly useful for complex robots or those with interchangeable components, as it facilitates easier maintenance and enhances readability. Typically, XACRO files are processed into URDF files before they are utilized in simulations or applications, combining the flexibility of XACRO with the straightforwardness of URDF.
RViz
RViz, or Robot Visualization, is a powerful 3D visualization tool used primarily in robotics and the Robot Operating System (ROS). It enables developers to visualize and interpret a wide array of sensor data, such as point clouds, maps, and robot models, in real-time. With its interactive features, users can manipulate objects and adjust visual settings to enhance understanding of robot behavior and performance. RViz's plugin architecture allows for extensibility, accommodating various data types and visualization needs. This makes it an invaluable resource for debugging algorithms, simulating scenarios, and gaining insights into robotic systems, ultimately aiding in the development and refinement of robotics applications.
Gazebo
Gazebo is an open-source robotics simulation tool that provides a highly realistic environment for testing and developing robotic systems. It allows users to simulate robots in complex 3D environments, complete with detailed physics interactions, which include gravity, collisions, and friction. Gazebo supports a variety of sensors, such as cameras and LIDAR, enabling the generation of realistic sensor data for developing perception algorithms. Its seamless integration with the Robot Operating System (ROS) enhances its functionality, allowing developers to leverage ROS tools and libraries for robot control and communication. With a flexible plugin architecture, Gazebo can be customized to meet specific simulation needs, making it an essential platform for researchers and engineers in the field of robotics.
Preparation
JetAuto Robot
In preparation for using the JetAuto robot, please be familiar with the user manual and the basic lesson provided by the manufacturer found here:
Procedures
Install Gazebo and other ROS packages
After becoming familiar with ROS, we'll now install the Gazebo simulation environment.
- 
Install Gazebo version 9.X to be used with ROS Melodic. Each Gazebo version works with a specific version of ROS. More details about the installation can be found here.
sudo apt install gazebo9 libgazebo9-dev - 
Once installed, start Gazebo with the following command to ensure it is functional:
gazebo
Figure 4.1 Gazebo Running
 - 
Lastly, ensure the following ROS Gazebo packages are installed:
sudo apt install ros-melodic-gazebo-dev ros-melodic-gazebo-msgs ros-melodic-gazebo-plugins ros-melodic-gazebo-ros ros-melodic-gazebo-ros-control ros-melodic-gazebo-ros-pkgs ros-melodic-joint-state-publisher ros-melodic-joint-state-publisher-gui ros-melodic-joint-trajectory-controller ros-melodic-moveit ros-melodic-trac-ik-kinematics-plugin ros-melodic-slam-gmapping 
Download the JetAuto Workspace to Local Machine for Simulation
- 
For this lab, we'll use the JetAuto workspace
jetauto_wson our local virtual machine so we can test the robot locally in a simulation before programming the actual robot.Download jetauto_ws.zip and unzip it to the
jetautouser's directory:/home/jetauto/If you downloaded the file on your host machine instead of your virtual machine, you may use WinSCP to transfer the file over to your virtual machine.
On your virtual machine: Open a terminal and ensure
openssh-serveris installed.sudo apt-get install openssh-serverEnable and start SSH as necessary:
sudo systemctl enable ssh sudo systemctl start sshOn your host machine: Open WinSCP and connect to: 127.0.0.1 port 22.
Copy the
jetauto_wsfolder fromjetauto_ws.zipinto/home/jetauto/. - 
Once
jetauto_wsis on your virtual machine'sjetautouser directory, let's add it as a source in~/.bashrc.First, we need to change the workspace setup script to be an executable:
sudo chmod +x /home/jetauto/jetauto_ws/devel/_setup_util.pyThen:
echo "source /home/jetauto/jetauto_ws/devel/setup.bash" >> ~/.bashrcUse
nanoto check if thesourceline got added to the end of~/.bashrcnano ~/.bashrc 
JetAuto Robot Model
Now that the JetAuto robot workspace is on the virtual machine, let's try to simulate it in Gazebo. A robot model in URDF consists of links that are joined together to form a robot assembly. Each link has its given geometry, mass, and collision parameters. The geometry can be provided as a simple shape or a complex shape using a solid model.
- 
Before we start, let's ensure (double-check) we have the required packages installed (if you haven't installed them from the beginning of this lab) to view and test our robot model:
sudo apt install ros-melodic-joint-state-publisher ros-melodic-joint-state-publisher-gui ros-melodic-joint-trajectory-controller - 
Next, we need to set some environment variables that our launch script will look for. Edit the system's environment variables:
sudo gedit /etc/environmentWe'll add the following in the environment:
LIDAR_TYPE="A1" DEPTH_CAMERA_TYPE="AstraProPlus" MACHINE_TYPE="JetAutoPro" HOST="/" MASTER="/"Restart your virtual machine in order for the changes to take effect.
 - 
Now, let's have a quick view of the URDF model. We can use RViz for visualization. A launch file allows us to start multiple nodes at once as well as define other attributes.
roslaunch jetauto_description display.launch model:=urdf/jetauto.urdfYou may inspect this particular launch file at the following location:
~/jetauto_ws/src/jetauto_simulations/jetauto_description/launch/display.launch
In it, you'll find it starts three nodes:
- joint_state_publisher_gui
 - robot_state_publisher
 - rviz
 
You can find more information about
roslaunchand.launchfiles in the official ROS tutorials: roslaunch and Roslaunch tips for large projects. - 
Once RViz is started, you can use the
joint_state_publisher_guito adjust the arm angle.
Figure 4.3 JetAuto in RViz (Note: The original image caption said "JetAuto in Gazebo", but the context and image refer to RViz)
 - 
Let's open up the JetAuto URDF model file to take a closer look at it.
~/jetauto_ws/src/jetauto_simulations/jetauto_description/urdf/jetauto_car.urdf.xacro
Here, we see a file in XML format:
<robot name="jetauto" xmlns:xacro="http://ros.org/wiki/xacro" > <xacro:property name="M_PI" value="3.1415926535897931"/> <xacro:property name="base_link_mass" value="1.6" /> <xacro:property name="base_link_w" value="0.297"/> <xacro:property name="base_link_h" value="0.145"/> <xacro:property name="base_link_d" value="0.11255"/> <xacro:property name="wheel_link_mass" value="0.1" /> <xacro:property name="wheel_link_radius" value="0.049"/> <xacro:property name="wheel_link_length" value="0.04167"/>The first few lines define the robot's name and the basic parameters of the JetAuto's body.
M_PIdefines the value of π.base_link_massdefines the mass of the JetAuto’s body model.base_link_wdefines the width of the JetAuto’s body model.base_link_hdefines the height of the JetAuto’s body model.base_link_ddefines the length of the JetAuto’s body model.wheel_link_massdefines the mass of each Mecanum wheel.wheel_link_radiusdefines the radius of each Mecanum wheel.
The name of the robot is also defined as
jetauto.<link name="base_footprint"/> <joint name="base_joint" type="fixed"> <parent link="base_footprint"/> <child link="base_link"/> <origin xyz="0.0 0.0 0.0" rpy="0 0 0"/> </joint>base_footprintis defined as the top parent link (part) of the JetAuto model to create an overall envelope that sits at the origin.base_linkis the base part of the robot that houses the battery and motor. In the URDF model, it is connected tobase_footprintas a child link. This envelope configuration ensures the wheels of the robot will always be above the origin (ground).<link name="base_link"> <xacro:box_inertial m="${base_link_mass}" w="${base_link_w}" h="${base_link_h}" d="${base_link_d}"/> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://jetauto_description/meshes/base_link.stl" /> </geometry> <material name="green"/> </visual> <collision> <origin xyz="${base_link_w/2.0 - 0.14810} 0 ${0.126437/2 + 0.02362364}" rpy="0 0 0" /> <geometry> <box size="${base_link_w} ${base_link_h} ${base_link_d}" /> </geometry> </collision> </link>Next is the link/part
base_linkalong with its elements. The mass and inertial information of the part is defined as an XACRO element. Thegeometrysub-element in thevisualelement is provided by anstlmesh file from thejetauto_descriptionpackage. Thecollisionelement is also defined as a box relative to the specified XYZ coordinate.
Figure 4.4 JetAuto base_link STL
<link name="back_shell_link"> <inertial> <origin xyz="-1.22838595456587E-05 0.00218574826309681 -0.0500522861933898" rpy="0 0 0" /> <mass value="0.0663478534899862" /> <inertia ixx="5.65277934912267E-05" ixy="-5.13394387877366E-11" ixz="-4.07561372273553E-11" iyy="4.33740893441632E-05" iyz="-5.43059341238134E-06" izz="6.86642544694324E-05" /> </inertial> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://jetauto_description/meshes/back_shell_link.stl" /> </geometry> <material name="black"> </material> </visual> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <mesh filename="package://jetauto_description/meshes/back_shell_link.stl" /> </geometry> </collision> </link> <joint name="back_shell_joint" type="fixed"> <origin xyz="-0.076481 0 0.082796" rpy="-3.1416 0 1.5708" /> <parent link="base_link" /> <child link="back_shell_link" /> <axis xyz="0 0 0" /> </joint>The
back_shell_linkis the part that houses the Jetson Nano, the expansion board, and mounts the antenna. All the elements are defined in a similar manner asbase_link, and it is defined as a child link ofbase_linkwith its relative position defined injoint.The
wheel_XXX_linkare all defined in a similar manner. - 
The JetAuto URDF model file above only defines the mechanical structure of the robot. If we take a look at the URDF file for simulating the robot in Gazebo, we will find more links that are used and defined in other URDF files within the same package.
~/jetauto_ws/src/jetauto_simulations/jetauto_description/urdf/jetauto.xacro
 - 
If you are interested in building a URDF from scratch, visit the ROS tutorial here.
 - 
Close all terminals.
 
Running JetAuto robot in Gazebo
- 
In a terminal, launch:
roslaunch jetauto_gazebo worlds.launchGazebo should run, and you should see the JetAuto robot in the simulation environment.

Figure 4.5 JetAuto in Gazebo
 - 
With Gazebo and ROS running, we can now control the virtual robot the same way as the physical robot.
Let's try publishing to the
cmd_veltopic. Open a new terminal and run:rostopic pub -1 /jetauto_controller/cmd_vel geometry_msgs/Twist '{linear: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}'Stop the robot:
rostopic pub -1 /jetauto_controller/cmd_vel geometry_msgs/Twist '{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}'Do you notice the JetAuto robot listens to the same
cmd_veltopics and uses the sameTwistmessage asTurtleSim? - 
Let's inspect the source code of the motion controller to take a closer look. Open the file at the following path:
~/jetauto_ws/src/jetauto_driver/jetauto_controller/scripts/jetauto_controller_main.py
As we can see in the controller code:
linear_x = self.go_factor*msg.linear.x linear_y = self.go_factor*msg.linear.y angular_z = self.turn_factor*msg.angular.z speed_up = False if abs(self.last_linear_x - linear_x) > 0.2 or abs(self.last_linear_y - linear_y) > 0.2 or abs(self.last_angular_z - angular_z) > 1: speed_up = True self.last_linear_x = linear_x self.last_linear_y = linear_y self.last_angular_z = angular_z linear_x_, linear_y_ = linear_x * 1000.0, linear_y * 1000.0 #mm to m speed = math.sqrt(linear_x_ ** 2 + linear_y_ ** 2) direction = math.atan2(linear_y_, linear_x_) direction = math.pi * 2 + direction if direction < 0 else direction self.mecanum.set_velocity(speed, direction, angular_z, speed_up=speed_up)The
Twistmessage fromcmd_velprovides the necessary information to calculatespeed,direction, andangular_zfor controlling the Mecanum wheels using theMecanumChassisobject.Refer to JetAuto & JetAuto Pro Resources chapter 7.3 for the working principle of the Mecanum wheel.
 - 
Try other various combinations of motion commands to gain a better understanding of the robot's movement, such as changing the linear values for both
xandyas well as the angular values. - 
Next, we'll try controlling the JetAuto robot using keyboard input. In a new/other terminal, run:
roslaunch jetauto_peripherals teleop_key_control.launch robot_name:="/"Use w, a, s, d to control the robot.
Troubleshooting: If you get a
No module named 'rospkg'error, it means there are some errors with the python interpretor and the ROS package. First, ensurerospkgis installed:sudo apt install python-rospkgTroubleshooting: If the problem presist, try removing
python-rospkgwhich will also remove a long list ofrosmodules. Then re-install ROS.sudo apt remove python-rospkg sudo apt install ros-melodic-desktop-fullMake sure you re-install all the dependency at the start of this lab as well.
 - 
Inspect the source code of the teleop controller to understand its operation by opening the file at:
~/jetauto_ws/src/jetauto_peripherals/scripts/teleop_key_control.py
 
Lab Question
- 
Modify the controller you created from lab3 (or create a new one) so it will publish to the
/jetauto_controller/cmd_veltopic for controlling the JetAuto robot in Gazebo.Hint: You can follow the same approach as Lab 3 by creating a new package called
lab4_jetauto_controlin yourros_ws.catkin_create_pkg lab4_jetauto_control rospy geometry_msgsRefer to the
teleop_key_control.pycontroller you used in this lab on how to publish to the JetAuto nodes.