The ME314_XArm package provides Python-based control and teleoperation functionalities for the xArm7 robotic arm, integrating with ROS2 for Stanford University's ME 314: Robotic Dexterity taught by Dr. Monroe Kennedy III.
Please stay away from the robot arm during operation to avoid personal injury or equipment damage. Ensure e-stop is close and accessible before controlling arm.
- Install Docker Desktop (or Docker Engine for CLI only)
- In terminal run:
docker pull aqiu218/me314_xarm_ros2
- Clone ME314_student repo to your computer
git clone https://github.com/armlabstanford/ME314_student.git
- Start container using the following command (only needs to be run once):
docker run --privileged --name me314_ros2 -p 6080:80 --shm-size=512m -v <path/to/ME314_student>:/home/ubuntu/xarm_ros2_ws/src/me314 aqiu218/me314_xarm_ros2
** In the above command, -v : mounts a folder on your local computer to the docker container, thus linking any files/directories/changes made on local to your docker container ubuntu system. ** --name sets the name of the container, this can be set to anything you want. We want to link our ME314_student folder from our host device to the virtualized ubuntu system.
Example:
docker run --privileged --name me314_ros2 -p 6080:80 --shm-size=512m -v /home/alex/ME314_student:/home/ubuntu/xarm_ros2_ws/src/me314 aqiu218/me314_xarm_ros2
** WE HIGHLY RECOMMEND ONLY CHANGING THE COMPUTER PATH TO YOUR ME314_student REPO IN THE ABOVE EXAMPLE COMMAND **
-
Navigate to http://localhost:6080/ and click connect. You should now see a full Ubuntu Linux desktop environment!
-
Stop container by pressing ctrl+c in host device (your laptop) terminal
-
To run container in the future, run the following command in your terminal and navigate to http://localhost:6080/:
docker start me314_ros2
- To stop container (run in terminal):
docker stop me314_ros2
-
Navigate to terminal (if using native Linux) or double click on Terminator on home screen.
-
Build your ROS2 workspace (you should only need to build the first time you start your docker container):
cd /home/ubuntu/xarm_ros2_ws
source /opt/ros/humble/setup.bash
colcon build --symlink-install --packages-select me314_pkg me314_msgs
source install/setup.bash
You will see some warnings, these can be ignored.
- To start gazebo simulation (and RViz), run the following launch command in the same terminal:
ros2 launch me314_pkg me314_xarm_gazebo.launch.py
This will take a while and will likely fail the first time you run this command when starting the container since Gazebo loads very slowly, ctrl+c and re-run the command after gazebo fully opens but no robot appears. Now you should see the xarm7 spawn on a table, with a red block in front of it.
- To test an example script that commands the xarm to move from point A to B, run the following command in a separate terminal while gazebo and rviz are open:
cd xarm_ros2_ws
source install/setup.bash
clear
ros2 run me314_pkg xarm_a2b_example.py
Follow instructions for ros2 humble (desktop) install: https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debs.html or copy and paste the below commands in terminal:
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop
sudo apt install gazebo
sudo apt install ros-humble-gazebo-ros-pkgs
sudo apt install \
ros-humble-gazebo-ros2-control \
ros-humble-controller-manager \
ros-humble-ros2-control \
ros-humble-joint-state-broadcaster \
ros-humble-joint-trajectory-controller
a. Install librealsense (source: https://github.com/IntelRealSense/realsense-ros?tab=readme-ov-file#installation-on-ubuntu step #2 option #2)
# Configure Ubuntu Repositories
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
# Install librealsense2 debian package
sudo apt install ros-humble-librealsense2*
b. Install RealSense Wrapper (source: https://github.com/IntelRealSense/realsense-ros?tab=readme-ov-file#installation-on-ubuntu)
# Assuming Ubuntu Repositories are already configured from previous step, install realsense2 wrapper debian package
sudo apt install ros-humble-realsense2-*
sudo apt install ros-humble-moveit
cd ~
mkdir -p xarm_ros2_ws/src
cd ~/xarm_ros2_ws/src
git clone https://github.com/Realexqiu/xarm_ros2.git --recursive -b $ROS_DISTRO
rosdep update && rosdep install --from-paths . --ignore-src --rosdistro $ROS_DISTRO -y --skip-keys="roscpp catkin"
cd ~/xarm_ros2_ws
colcon build
cd ~/xarm_ros2_ws/src
git clone https://github.com/armlabstanford/ME314_student.git
cd ~/xarm_ros2_ws
colcon build --symlink-install --packages-select me314_pkg me314_msgs
- If using Terminator, ctrl+shift+E is shortkey to open side by side terminal tab
- If xarm isn't spawning in gazebo, try quitting and re-running launch command
- If encountering the following issue when running a script in docker: /usr/bin/env: 'python3\r': No such file or directory, open the file in vscodium and convert the file format from CRLF to LF (bottom right of vscodium)
- For more info about docker check out this quickstart guide: https://github.com/armlabstanford/collaborative-robotics/wiki/Docker-Quickstart
- Docker cheat sheet commands here: https://docs.docker.com/get-started/docker_cheatsheet.pdf
cd xarm_ros2_ws
source /opt/ros/humble/setup.bash
source install/setup.bash
Tele-Operation with Spacemouse (this only works when connected to real-robot and spacemouse (https://3dconnexion.com/us/product/spacemouse-compact/)
ros2 run me314_pkg xarm_spacemouse_ros2.py
- Control in Gazebo
a. In one terminal run the following command:
ros2 launch me314_pkg me314_xarm_gazebo.launch.py
b. In another terminal run script (example):
ros2 run me314_pkg xarm_a2b_example.py
- Control in Real
a. In one terminal run the xarm planner launch command:
ros2 launch me314_pkg me314_xarm_real.launch.py
b. In another terminal run script (example):
ros2 run me314_pkg xarm_a2b_example.py