How to Build a Simulated Mobile Manipulator Using ROS

In this tutorial, we will create a mobile manipulator using a wheeled robot base and a robotic arm. All we need to do is to connect the arm_base link of the robot arm to the base_link of the robot.

mobile-manipulator-gif

This tutorial would not have been possible without Ramkumar Gandhinathan and Lentin Joseph’s awesome book ROS Robotics Projects Second Edition (Disclosure: As an Amazon Associate I earn from qualifying purchases). I highly recommend it if you want to learn ROS 1. Many of the files (URDF, configuration, and STL files), come from their book’s public GitHub page.

Real-World Applications

This project has a number of real-world applications: 

  • Indoor Delivery Robots
  • Order Fulfillment
  • Factories
  • Warehouses
  • Space Exploration
  • Power Plants

Let’s get started!

Prerequisites

  • You have completed this tutorial where you learned how to create a mobile robot base.
  • You have completed this tutorial where you learned how to create a robotic arm.

Build the Mobile Manipulator

Open a new terminal window.

Move to the urdf folder of your package.

roscd mobile_manipulator_body/urdf/

Now create a file named mobile_manipulator.urdf.

gedit mobile_manipulator.urdf

Add the mobile_manipulator.urdf code inside there.

Save and close the file.

Test the Mobile Manipulator

Now, let’s launch RViz to see what our robot looks like so far.

roscd mobile_manipulator_body/urdf/
roslaunch urdf_tutorial display.launch model:=mobile_manipulator.urdf
1-rviz-mobile-manipulator

A GUI will appear that will enable you to move the joints.

2-gui-will-appear

Launch the Mobile Manipulator

Now let’s launch the mobile manipulator.

Open a new terminal window, and go to the package.

roscd mobile_manipulator_body/launch/

Create a new launch file.

gedit mobile_manipulator_gazebo.launch

Add the mobile_manipulator_gazebo.launch code inside there.

Save and close the file.

Now let’s launch the robot in Gazebo.

Move to your catkin workspace.

cd ~/catkin_ws/
roslaunch mobile_manipulator_body mobile_manipulator_gazebo.launch

Here is how the robot looks.

3-gazebo-mobile-manipulator

Here are the active ROS topics.

rostopic list
4-ros-active-topics

Open a new terminal, and type this command to move the robot arm a little bit:

rostopic pub /arm_controller/command trajectory_msgs/JointTrajectory '{joint_names: ["arm_base_joint","shoulder_joint", "bottom_wrist_joint", "elbow_joint","top_wrist_joint"], points: [{positions: [-0.1, 0.5, 0.02, 0, 0], time_from_start: [1,0]}]}' -1


Type this command to bring the robot back to the home position.

rostopic pub /arm_controller/command trajectory_msgs/JointTrajectory '{joint_names: ["arm_base_joint","shoulder_joint", "bottom_wrist_joint", "elbow_joint","top_wrist_joint"], points: [{positions: [0, 0, 0, 0, 0], time_from_start: [1,0]}]}' -1
3b-gazebo-mobile-manipulator

You can steer the robot by opening a new window and typing:

rosrun rqt_robot_steering rqt_robot_steering

You will need to change the topic inside the GUI to:

/robot_base_velocity_controller/cmd_vel

To see the velocity messages, open a new window and type:

rostopic echo /robot_base_velocity_controller/cmd_vel

References

ROS Robotics Projects Second Edition

How to Build a Simulated Robot Arm Using ROS

In the previous tutorial, we built a simulated mobile robot base from scratch. Now I want to create a robotic arm that I will eventually attach to this base so that I have a complete mobile manipulator. Here is what we will build:

robot-arm-gif

This tutorial would not have been possible without Ramkumar Gandhinathan and Lentin Joseph’s awesome book ROS Robotics Projects Second Edition (Disclosure: As an Amazon Associate I earn from qualifying purchases). I highly recommend it if you want to learn ROS 1. Many of the files (URDF, configuration, and STL files), come from their book’s public GitHub page.

Real-World Applications

This project has a number of real-world applications: 

  • Indoor Delivery Robots
  • Order Fulfillment
  • Factories
  • Warehouses
  • Space Exploration
  • Power Plants

Let’s get started!

Prerequisites

  • You have completed this tutorial where you learned how to create a mobile robot base.

Build the Robot Arm

Open a new terminal window.

Move to the urdf folder of your package.

roscd mobile_manipulator_body/urdf/

Now create a file named robot_arm.urdf.

gedit robot_arm.urdf

Add the robot_arm.urdf code inside there.

Save and close the file.

Test the Robot Arm

Now let’s launch the robot arm.

Open a new terminal window, and go to the package.

roscd mobile_manipulator_body/urdf/
roslaunch urdf_tutorial display.launch model:=robot_arm.urdf

Change the Fixed Frame to world.

Here is how the robot looks.

1-robot-arm-launch-test-1

Move the arm using the sliders. 

2-sliders

Here are the active ROS topics.

rostopic list
1a-rostopic-list

Press CTRL + C in all open terminal windows to close everything down.

Now, let’s set up the configuration parameters for the controllers.

Open a new terminal window.

Go to the config file of your package.

roscd mobile_manipulator_body/config/

Now create a file named arm_control.yaml.

gedit arm_control.yaml

Add the arm_control.yaml code inside there.

Save and close the file.

Now create a file named joint_state_controller.yaml.

gedit joint_state_controller.yaml

Add the joint_state_controller.yaml code inside there.

Save and close the file.

Launch the Robot Arm

Now let’s launch the robot arm.

Open a new terminal window, and go to the package.

roscd mobile_manipulator_body/launch/

Create a new launch file.

gedit arm_gazebo_control.launch

Add the arm_gazebo_control.launch code inside there.

Save and close the file.

Now let’s launch the robot in Gazebo.

Open a new terminal window.

Move to your catkin workspace.

cd ~/catkin_ws/
roslaunch mobile_manipulator_body arm_gazebo_control.launch

Here is how the robot arm looks.

4-robot-arm-gazebo

Here are the active ROS topics.

rostopic list
5-ros-topic-list

Open a new terminal, and type this command to move the robot arm a little bit:

rostopic pub /arm_controller/command trajectory_msgs/JointTrajectory '{joint_names: ["arm_base_joint","shoulder_joint", "bottom_wrist_joint", "elbow_joint","top_wrist_joint"], points: [{positions: [-0.1, 0.5, 0.02, 0, 0], time_from_start: [1,0]}]}' -1
6-after-publishing-command

Type this command to bring the robot back to the home position.

rostopic pub /arm_controller/command trajectory_msgs/JointTrajectory '{joint_names: ["arm_base_joint","shoulder_joint", "bottom_wrist_joint", "elbow_joint","top_wrist_joint"], points: [{positions: [0, 0, 0, 0, 0], time_from_start: [1,0]}]}' -1

References

ROS Robotics Projects Second Edition


How To Convert a Quaternion Into Euler Angles in Python

Given a quaternion of the form  (x, y, z, w) where w is the scalar (real) part and x, y, and z are the vector parts, how do we convert this quaternion into the three Euler angles:

  • Rotation about the x axis = roll angle = α
  • Rotation about the y-axis = pitch angle = β
  • Rotation about the z-axis = yaw angle = γ
yaw_pitch_rollJPG

Doing this operation is important because ROS2 (and ROS) uses quaternions as the default representation for the orientation of a robot in 3D space. Roll, pitch, and yaw angles are a lot easier to understand and visualize than quaternions.

Here is the Python code:

import math

def euler_from_quaternion(x, y, z, w):
		"""
		Convert a quaternion into euler angles (roll, pitch, yaw)
		roll is rotation around x in radians (counterclockwise)
		pitch is rotation around y in radians (counterclockwise)
		yaw is rotation around z in radians (counterclockwise)
		"""
		t0 = +2.0 * (w * x + y * z)
		t1 = +1.0 - 2.0 * (x * x + y * y)
		roll_x = math.atan2(t0, t1)
    
		t2 = +2.0 * (w * y - z * x)
		t2 = +1.0 if t2 > +1.0 else t2
		t2 = -1.0 if t2 < -1.0 else t2
		pitch_y = math.asin(t2)
    
		t3 = +2.0 * (w * z + x * y)
		t4 = +1.0 - 2.0 * (y * y + z * z)
		yaw_z = math.atan2(t3, t4)
    
		return roll_x, pitch_y, yaw_z # in radians

Example

Suppose a robot is on a flat surface. It has the following quaternion:

Quaternion [x,y,z,w] = [0, 0, 0.7072, 0.7072]

What is the robot’s orientation in Euler Angle representation in radians?

quaternion_to_euler_1JPG

The program shows that the roll, pitch, and yaw angles in radians are (0.0, 0.0, 1.5710599372799763).

quaternion_to_euler_2

Which is the same as:

Euler Angle (roll, pitch, yaw) = (0.0, 0.0, π/2)

And in Axis-Angle Representation, the angle is:

Axis-Angle {[x, y, z], angle} = { [ 0, 0, 1 ], 1.571 }

So we see that the robot is rotated π/2 radians (90 degrees) around the z axis (going counterclockwise). 

And that’s all there is to it folks. That’s how you convert a quaternion into Euler angles.

You can use the code in this tutorial for your work in ROS2 since, as of this writing, the tf.transformations.euler_from_quaternion method isn’t available for ROS2 yet.