HW 0: Getting started with ROS
Table of contents
Introduction
Objectives
The purpose of this tutorial is to get you set up with some basic tools that we’ll use to program robots in this class.
Some terminology:
- ROS: This stands for “Robot Operating System”. But… it’s not really an operating system. It’s more like an API that’s generic across multiple robot platforms (see below).
- Gazebo: This is the physics simulator we’ll use to test our robots. Even when we have physical robots available to us, it’s best practice to test our code in simulation first to make sure it works as expected.
- RViz: This is a visual interface and debugging tool for some of our ROS software modules. We can use it to preview the robot’s actions, send motion commands, and visualize sensor data.
- xArm7: This is the specific robot platform we’ll be using.
What is ROS?
ROS provides a software interface that’s consistent across many robot platforms. Check out this video for an overview.
The rest of this tutorial will get right into the specifics of how to use ROS and its related tools, but doesn’t offer much of an explanation about why or how these tools work. I encourage you to visit this channel to walk you through any new concepts such as RViz, URDFs, MoveIt, or even the ROS install process itself.
Part 0: Setting up your user account
- We have dedicated computers in AKW that you can use for our class. Log into Canvas to find the room number, keycode, and computer password.
- The rest of this tutorial has been tested on these computers. You may use your own Linux-installed computer instead if you’d like, but note that we might not be able to help with installation issues.
- We have two computers in the teaching lab: Eve and WALL-E. Create a user account on either one (or both!) of them. All of your work must be completed on your own user account.
- Log into the “robot-lab” user account using the password you found on Canvas.
- Open “Settings” and then scroll down to “Users”.
- In the top-right corner, click “Unlock…” and enter the password again.
- Click “Add User…” and create an Administrator account for yourself.
- Log out and then back into your new user account.
Shared computer etiquette
While you have your own user profile, please remember that the lab computer is a shared resource. Be careful not to interfere with system settings or install/update any packages that will conflict with other people’s work.
-
Don’t install packages via
apt-get
, when possible.-
apt-get
installations are performed system-wide. Even if the package you are trying to install does not conflict with anyone else’s code, it may install dependencies that do. - It’s okay to run
apt-get
to install ROS. Since ROS is already set up on one of the user profiles, you may find that manyapt-get
packages you need are already installed anyways. - If you need to install any other package using
apt-get
, check with Anjiabei (your TF) or Prof. Tesca first.
-
-
Do install packages via
pip
with the--user
flag.- This will ensure that python packages are installed only to your user directory.
- Example:
pip install --user PACKAGENAME
- But never use
sudo
for apip
install.
- Do use virtualenv, conda, or another environment manager to ensure packages are installed only locally.
Part 1: Setting up your ROS workspace
- Follow these instructions to install ROS2 “Humble” (desktop version). Follow all steps from Setup Sources to Environment Setup.
- When you’re done, use your favorite text editor to open the file
~/.bashrc
and add this line to the bottom:source /opt/ros/humble/setup.bash
- After you’ve edited your
~/.bashrc
file, you need to “source” it for the changes to take effect. You can do this by closing and reopening your terminal window, or by running this in your existing terminal window:source ~/.bashrc
- When you’re done, use your favorite text editor to open the file
- Install the basic packages.
- Install MoveIt2:
sudo apt install ros-humble-moveit
- Install Gazebo. If you’re using the shared teaching computers, you can skip this step.
curl -sSL http://get.gazebosim.org | sh
- Test that it works by running:
gazebo
You should see an empty simulation environment appear.
- Install Gazebo ROS packages:
sudo apt install ros-humble-gazebo-ros-pkgs
- If you run into any issues with these steps, check out the xArm installation instructions.
- Install MoveIt2:
- Install the ROS package for our xArm robot.
- Download the source code of
xarm_ros2
repository:cd ~ mkdir -p dev_ws/src cd ~/dev_ws/src git clone https://github.com/xArm-Developer/xarm_ros2.git --recursive -b $ROS_DISTRO
- Update
xarm_ros2
repositorycd ~/dev_ws/src/xarm_ros2 git pull git submodule sync git submodule update --init --remote
- Install dependencies:
cd ~/dev_ws/src/ rosdep update rosdep install --from-paths . --ignore-src --rosdistro $ROS_DISTRO -y
- Build
xarm_ros2
:sudo apt install python3-colcon-common-extensions cd ~/dev_ws/ colcon build
- Download the source code of
- Now let’s test that everything is installed correctly.
- Source the environment setup script by adding this to your
~/.bashrc
file:source ~/dev_ws/install/setup.bash
- After you’ve edited your
~/.bashrc
file, you need to “source” it for the changes to take effect. You can do this by closing and reopening your terminal window, or by running this in your existing terminal window:source ~/.bashrc
- Next, let’s launch the simulated arm in RViz and Gazebo:
ros2 launch xarm_planner xarm7_planner_gazebo.launch.py add_gripper:=true
- You should see the robot arm appear in two windows: RViz and Gazebo. If you don’t see these windows appear, take a look at any errors that may have appeared in your terminal window. Check out the xArm installation instructions for debugging help, or ask your friendly TF or classmates for help.
- Source the environment setup script by adding this to your
Part 2: Moving the arm in simulation
Now, let’s use MoveIt to plan trajectories and preview them in RViz. We’ll try three different interfaces to do this.
- RViz interface
- On the left side of the RViz window, there’s a tab called “MotionPlanning”. Under that, there’s a sub-tab “Planning Request”. Under that, check the box for “Query Goal State”.
- Try dragging the sphere to indicate the pose that the robot arm should move to.
- At the top left corner of the screen, go to the “Panels” menu and check the box for “Motion Planning”.
- In the panel that just appeared, click “Plan”. You should see that the arm moves in RViz, but not in Gazebo. This is because “Plan” will just give you a preview of the trajectory without actually running it.
- Now click “Plan & Execute”. This will tell the simulated arm to move along that trajectory. This time, you should see the arm actually moving in Gazebo. Tada!
- ROS service interface
- In a new terminal tab, run this to generate a motion plan to a particular end-effector pose:
ros2 service call /xarm_pose_plan xarm_msgs/srv/PlanPose "{target:{ position: {x: 0.3, y: 0.2, z: 0.2}, orientation: {x: 1.0, y: 0.0, z: 0.0, w: 0.0}}}"
- Now, execute that planned trajectory by running this:
ros2 service call /xarm_exec_plan xarm_msgs/srv/PlanExec "{wait: true}"
- You should now see the arm move in Gazebo. Hurray!
- In a new terminal tab, run this to generate a motion plan to a particular end-effector pose:
- Python interface
- Download
xarm_planning_client.py
. This file contains code that generates a ROS service request (similar to what you just ran in the terminal). - Edit the file to specify whatever end-effector target pose you’d like. Run it and see if it works!
- You can execute a trajectory by creating multiple target poses and calling the client node for each one.
- Download