The robots are coming (virtually)

Yes, it’s several years since I last posted anything. But I think this might conceivably be useful for somebody, in a very specific set of circumstances.

Install ROS and baxter emulator on WSL

This is a fairly detailed set of steps to install ROS Noetic and the Baxter SDK and its 3d graphical emulator on a Ubuntu system running in Windows, to allow development of ROS applications for Baxter without a real robot. It’s mostly written down to help me remember the steps I had to go through to get everything working with WSL and Noetic even though the Baxter SDK has been prtty much abandoned and doesn’t support newer versions of ROS. It’s actually not that hard, but there area a lot of steps. I hope you find it useful.

Some of this comes from Setting up ROS in Windows through WSL2, and some from Baxter workstation setup, and more from Github. Other bits I’ve worked out through trial and error and a number of web searches.

Preparation

I’m assuming you already have the Windows Subsystem for Linux version 2 (WSL2) installed on your windows PC. If not, then this won’t be much use. I’m also assuming you have a Ubuntu distro installed (I’m using 20.04) and the Windows Terminal as an interface to it.

Install X VxXsrv server to allow gui apps

VxXsrv is an XWindows server program which runs in windows, so the WSL Ubuntu instance can use it as a front end for graphical applications. It works really well.

NB: This bit is done in Windows.

From sourceforge download the installer and run it. When the install is complete, run VxXsrv and on its first run make sure ‘Native OpenGL’ is not selected, and ‘Disable access control’ is selected. Save the config for future runs.

Use ifconfig to find the ip v4 address of the the windows machine, because you’ll need it for the next step (in WSL)

From here on, work in your Ubuntu instance through the Windows Terminal

Configure display in WSL to use X server

Add the display config to your bash script

echo 'export DISPLAY=999.999.999.999:0.0' >> ~/.bashrc

Replace 999.999.999.999 with the ipv4 address you found in the previous step. Note that this may change if you are on a wifi network, and it will need to be reconfigured every time it does.

Make the config active

source ~/.bashrc

Optional: test the x server

sudo apt update
sudo apt install x11-apps
xcalc

If all is well, you’ll see the xcalc running in an X window on your windows desktop

Install ROS

Make sure everything is up to date

sudo apt update
sudo apt upgrade

Add ROS package information to sources list

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

Add the keys to allow these extra sources to be used. Install curl if it’s not already present, then use it to download keys

sudo apt install curl

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo 
apt-key add -

sudo apt update

Install ROS Noetic:

sudo apt install ros-melodic-desktop-full

Prepare for ROS use by configuring bash script

echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

Install development packages

sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential

When it’s done

sudo rosdep init
rosdep update

test it!

roscore & rosrun rviz rviz

Create ROS workspace

mkdir -p ~/ros_ws/src

Source ROS and build

source /opt/ros/noetic/setup.bash

Build and Install

cd ~/ros_ws
catkin_make
catkin_make install

Install Baxter SDK

cd ~/ros_ws/src
wstool init .
wstool merge https://raw.githubusercontent.com/RethinkRobotics/baxter/master/baxter_sdk.rosinstall
wstool update

Source ROS setup

source /opt/ros/noetic/setup.bash

Build and install

Be prepared for this to fail with errors!

cd ~/ros_ws
catkin_make

Don’t worry. Because we are now using Python 3, some of the scripts need a bit of tweaking because they are using Python 2 syntax.

in file ~/ros_ws/src/baxter_interface/src/baxter_interface/robot_enable.py, find a line which says

except OSError, e:

and change it to

except OSError as e:

Then try again:

cd ~/ros_ws
catkin_make
catkin_make install

Set up ROS workspace

Download the baxter.sh script. This will set the right parameters for ROS to communicatwe with the (emulated) robot.

$ wget https://github.com/RethinkRobotics/baxter/raw/master/baxter.sh
$ chmod u+x baxter.sh

Customize the baxter.sh script

Edit the baxter.sh shell script making the necessary modifications to describe your development environment. In WSL, th linux system will probably have a different IP address to the windows PC hosting it. This is absolutely fine for the baxter simulator, but you need to know what it is. The hostname comand will tell you:

hostname -I

Using your favorite editor (you’ve got an X server now, so you could use xedit) edit ~/ros_ws/baxter.sh and make the following changes:

Edit the ‘baxter_hostname’ field

baxter_hostname=“baxter_hostname.local”

Edit the ‘your_ip’ field. Modify where ‘your_ip’ is the IP address of your PC.

your_ip=“192.168.XXX.XXX”

Modify ‘ros_version’ to noetic:

ros_version=“noetic”

Save the file.

Initialize your SDK environment

From this point forward, your ROS environment setup should be as simple as sourcing the baxter.sh script from the root of your Catkin workspace:

cd ~/ros_ws
. baxter.sh

“Should”. What a great word.

Getting it all to work

Install the baxter simulator

cd ~/ros_ws/src
git clone https://github.com/RethinkRobotics/baxter_simulator.git
wstool merge baxter_simulator/baxter_simulator.rosinstall
wstool update

Install other dependent packages:

cd ~/ros_ws/src
git clone https://github.com/ros/xacro.git -b noetic-devel
git clone https://github.com/ros/roslint.git

Build everything

Expect this to fail!

source /opt/ros/noetic/setup.bash
cd ~/ros_ws
catkin_make

The emulator uses the Qt4 user interface library, but this has been superseded by Qt5 and is not installed by default. So it needs to be manually added (unless you fancy editing all the files which use it and converting them to Qt5). We need to use a third party PPA to do this:

sudo add-apt-repository ppa:rock-core/qt4
sudo apt update
sudo apt install qt4-default

Then try catkin_make again:

catkin_make

And once again, it will fail. There appear to be loads of errors, but in fact there are only two files which need to be edited:

1. ~/ros_ws/src/baxter_simulator/baxter_sim_kinematics/src/arm_kinematics.cpp

Edit the lines which says

boost::shared_ptr<const urdf::Link> link = robot_model.getLink(tip_name);
boost::shared_ptr<const urdf::Joint> joint;

to read as follows (i.e. replace the reference to the boost libraries with the std one).

std::shared_ptr<const urdf::Link> link = robot_model.getLink(tip_name);
std::shared_ptr<const urdf::Joint> joint;

2: ~/ros_ws/src/baxter_simulator/baxter_sim_hardware/src/baxer_emulator.cpp

Edit the lines which says

cv_ptr->image = cv::imread(img_path, CV_LOAD_IMAGE_UNCHANGED);

to read as follows (updateing to match changes in the OpenCV library).

cv_ptr->image = cv::imread(img_path, cv::IMREAD_UNCHANGED);

Then try catkin_make again, and assuming it works (you might get some warnings, but you can ignore them) do catkin_make install

catkin_make
catkin_make install 

Time to try it out

Use the baxter.sh script with the ‘sim’ parameter to set up parameters for simulation rather than a real robot.

cd ~/ros_ws
.\baxter.sh sim
roslaunch baxter_gazebo baxter_world.launch

And it fails again. This time it’s a ROS launch file which needs modifying to use xacro instead of the old xacro.py. Edit the file ~/ros_ws/src/baxter_simulator/baxter_gazebo/launch/baxter_world.launch and change the section below

<param if="$(arg load_robot_description)" name="robot_description" command="$(find xacro)/xacro.py --inorder $(find baxter_description)/urdf/baxter.urdf.xacro gazebo:=true"/>

removing the “.py” from the xacro command:

<param if="$(arg load_robot_description)" name="robot_description" command="$(find xacro)/xacro --inorder $(find baxter_description)/urdf/baxter.urdf.xacro gazebo:=true"/>

That’s it. You sould be good to go, now. Run the following command

roslaunch baxter_gazebo baxter_world.launch

And you should see Gazebo fire up, with a model of Baxter in it, and also a window showing emulations of the arm and body control dials and buttons. Note that these are running alongside any other Windows apps! It’s a bit like magic.

You can now open otehr Windows terminal sessions to the same Ubuntu instance and run other ROS nodes to control the simulated robot. As with a real robot, you need to enable it using the enable_robot script fromt eh baxter_tools package before it will do anything. You can also run the standard sample demos, e.g. the arm wobbler:

./baxter.sh sim
rosrun baxter_examples joint_velocity_wobbler.py

Though you might need to edit the first lines of python files to ue Python3 instead of python or python2. And in enable_robot.py you’ll need to correct the syntax of an exception handler and a print statement. But they are left as simple exercises for the reader :-)