Skip to content

Detailed environment setup

Rich Wareham edited this page Oct 7, 2013 · 12 revisions

This page gives detailed command-by-command instructions for setting up your workspace once you have ROS installed. Follow the Ubuntu installation guide on the ROS website for that bit.

Note that the home directories on the wired lab computer are all mounted on a directory served from vega. On this page I'm using the example of rjw57 logged into the machine portia.

On the shared machines, the parts requiring sudo have already been done. You'll need to run rosdep update yourself.

Create a workspace

Make a directory for your workspace and a src directory under it:

rjw57@portia:~$ mkdir ~/cued-masters/
rjw57@portia:~$ mkdir ~/cued-masters/src

Set up your environment to run ROS programs:

rjw57@portia:~$ source /opt/ros/hydro/setup.bash

Change into the src directory and create a catkin workspace.

rjw57@portia:~$ cd ~/cued-masters/src/
rjw57@portia:~/cued-masters/src$ catkin_init_workspace 
Creating symlink "/remote/homes/rjw57/cued-masters/src/CMakeLists.txt" pointing to "/opt/ros/hydro/share/catkin/cmake/toplevel.cmake"

Change into your workspace directory and "make" it:

rjw57@portia:~/cued-masters/src$ cd ~/cued-masters/
rjw57@portia:~/cued-masters$ catkin_make
Base path: /remote/homes/rjw57/cued-masters
Source space: /remote/homes/rjw57/cued-masters/src
[ ... stuff ... ]

Write a script to set up your environment

Use your favourite editor (which should be vim) to create the file ~/cued-masters/setup.bash file with the following contents:

source /opt/ros/hydro/setup.bash
source $HOME/cued-masters/devel/setup.bash
export ROS_HOSTNAME="`hostname`"
export ROS_MASTER_URI="http://${ROS_HOSTNAME}:11311"

Now you can set up your ROS environment each time you log into the machine:

rjw57@portia:~$ source ~/cued-masters/setup.bash

Alternatively you can add the line source ~/cued-masters/setup.bash to the bottom of ~/.bashrc if you don't want to bother doing this every time.

Set up SSH keys

Generate a SSH public key using the ssh-keygen program. You can press Enter at the prompts to accept the defaults. If you're security conscious, you can add a passphrase. Note that the lab machines are shared machines which a number of people have access to and so a passphrase is a Good Idea(TM).

rjw57@portia:~$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/remote/homes/rjw57/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /remote/homes/rjw57/.ssh/id_rsa.
Your public key has been saved in /remote/homes/rjw57/.ssh/id_rsa.pub.
The key fingerprint is:
be:e2:c5:a2:8b:6f:9c:e3:e9:ab:7b:fb:bd:6d:2b:84 rjw57@portia
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|       .S        |
|      Eo.        |
|   . ...+        |
|   .*o.+.o.      |
|  +OXBo.++o.     |
+-----------------+

Set up GitHub

Although GitHub recommends using the HTTPS access method, it's worth setting up SSH-based access. Certainly I (rjw57) prefer it since it allows me to do a HTTPS checkout when I want to make absolutely sure I can't accidentally push something to a repo even if I have push rights.

GitHub have instructions for adding SSH keys on their website. The short, short version is to go to https://github.com/settings/ssh and paste the contents of the ~/.ssh/id_rsa.pub file into the box.

Test your connection to GitHub:

rjw57@portia:~$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Enter passphrase for key '/remote/homes/rjw57/.ssh/id_rsa': 
Hi rjw57! You've successfully authenticated, but GitHub does not provide shell access.

Set up SSH connection to the robot

Make sure the robot is plugged in to both the power and the network. (If it is WiFi only, the hostname will be sigproc-robot1 and not binky.) When the robot has booted, you should be able to ping it:

rjw57@portia:~$ ping -c 3 binky
PING binky.eng.cam.ac.uk (129.169.154.122) 56(84) bytes of data.
64 bytes from binky.eng.cam.ac.uk (129.169.154.122): icmp_req=1 ttl=64 time=0.453 ms
64 bytes from binky.eng.cam.ac.uk (129.169.154.122): icmp_req=2 ttl=64 time=0.371 ms
64 bytes from binky.eng.cam.ac.uk (129.169.154.122): icmp_req=3 ttl=64 time=0.461 ms

--- binky.eng.cam.ac.uk ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.371/0.428/0.461/0.044 ms

To copy your SSH key over to the robot which will allow you to log in, use the ssh-copy-id program:

rjw57@portia:~$ ssh-copy-id qbo@binky
The authenticity of host 'binky (129.169.154.122)' can't be established.
ECDSA key fingerprint is c1:8c:a4:18:95:ba:8e:85:25:c4:17:5e:bb:eb:81:e5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'binky,129.169.154.122' (ECDSA) to the list of known hosts.
qbo@binky's password: 
Now try logging into the machine, with "ssh 'qbo@binky'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

Note: the username for binky is qbo. Ask rjw57 for the password.

Test the key was copied by trying to log into the robot:

rjw57@portia:~$ ssh -oHostKeyAlgorithms='ssh-rsa' qbo@binky
Enter passphrase for key '/remote/homes/rjw57/.ssh/id_rsa': 
Welcome to Ubuntu 13.04 (GNU/Linux 3.8.0-31-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

Last login: Mon Oct  7 11:23:55 2013 from spica.eng.cam.ac.uk
qbo@sigproc-robot1:~$ exit
logout
Connection to binky closed.
rjw57@portia:~$ 

The -oHostKeyAlgorithms='ssh-rsa' is very important for the first login due to a ROS bug. It's not necessary for subsequent logins.

Install the SigProc ROS packages

Install our fork of the Q.bo controller stack. Note that we use HTTPS here.

rjw57@portia:~$ cd ~/cued-masters/src/
rjw57@portia:~/cued-masters/src$ git clone https://github.com/OpenQbo/qbo_cereal_port.git                                                                                                                                                      
Cloning into 'qbo_cereal_port'...
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 18 (delta 3), reused 18 (delta 3)
Unpacking objects: 100% (18/18), done.
rjw57@portia:~/cued-masters/src$ git clone https://github.com/sigproc/qbo_arduqbo.git                                                                                                                                                          
Cloning into 'qbo_arduqbo'...
remote: Counting objects: 506, done.
remote: Compressing objects: 100% (158/158), done.
remote: Total 506 (delta 331), reused 501 (delta 326)
Receiving objects: 100% (506/506), 148.67 KiB, done.
Resolving deltas: 100% (331/331), done.
Checking out files: 100% (80/80), done.
rjw57@portia:~/cued-masters/src$ git clone https://github.com/sigproc/qbo_joint_odom.git                                                                                                                                                       
Cloning into 'qbo_joint_odom'...
remote: Counting objects: 51, done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 51 (delta 21), reused 51 (delta 21)
Unpacking objects: 100% (51/51), done.

Check out the SigProC ROS stack. This time we use SSH because it's likely we'll want to push changes:

rjw57@portia:~/cued-masters/src$ git clone git@github.com:sigproc/qbo_sigproc.git
Cloning into 'qbo_sigproc'...
Enter passphrase for key '/remote/homes/rjw57/.ssh/id_rsa': 
remote: Counting objects: 283, done.
remote: Compressing objects: 100% (138/138), done.
remote: Total 283 (delta 144), reused 267 (delta 132)
Receiving objects: 100% (283/283), 38.30 KiB, done.
Resolving deltas: 100% (144/144), done.
Checking out files: 100% (37/37), done.

Now try making the ROS nodes:

rjw57@portia:~/cued-masters/src$ cd ~/cued-masters
rjw57@portia:~/cued-masters$ rosmake qbo_arduqbo 
[ rosmake ] rosmake starting...                                                                                                                                                                                                                
[ rosmake ] Packages requested are: ['qbo_arduqbo']
[ ... stuff ... ]
[ rosmake ] Results:                                                                                                                                                                                                                           
[ rosmake ] Built 51 packages with 0 failures.                                                                                                                                                                                                 
[ rosmake ] Summary output to directory                                                                                                                                                                                                        
[ rosmake ] /remote/homes/rjw57/.ros/rosmake/rosmake_output-20131007-172501

Test the ROS connection

There is a little test roslaunch file which will try to log into the robot and run a little talker node. Try it now:

rjw57@portia:~$ roslaunch qbo_sigproc_launch qbo_test_talker.launch qbo_address:=binky --screen
... logging to /remote/homes/rjw57/.ros/log/507d8462-2f6e-11e3-ac5a-0019d1841c3c/roslaunch-portia-12987.log

You should see lines like the following which show messages are getting from the Q.bo to your machine:

[INFO] [WallTime: 1381163663.087087] /listenerI heard hello world 1381159976.78
[INFO] [WallTime: 1381163663.187129] /listenerI heard hello world 1381159976.88
[INFO] [WallTime: 1381163663.287138] /listenerI heard hello world 1381159976.98

Note: if you get output like this:

started roslaunch server http://portia:53830/
remote[binky-0] starting roslaunch
remote[binky-0]: creating ssh connection to binky:22, user[qbo]
remote[binky-0]: failed to launch on qbo:

Authentication to remote computer[qbo@binky:22] failed.
A common cause of this error is a missing key in your authorized_keys file.


[binky-0] killing on exit
unable to start remote roslaunch child: binky-0

Then you've either not copied your SSH key over, you forgot the -oHostKeyAlgorithms='ssh-rsa' the first time you logged into binky or you are, correctly, using a passphrase but there's no SSH agent set up. (Under Ubuntu, there is sometimes a program configured to ask for your passphrase and sometimes not, it doesn't appear to be obvious when this works.) The way to get around this is to do the following:

rjw57@portia:~$ ssh-agent bash
rjw57@portia:~$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /remote/homes/rjw57/.ssh/id_rsa: 
Identity added: /remote/homes/rjw57/.ssh/id_rsa (/remote/homes/rjw57/.ssh/id_rsa)
rjw57@portia:~$ source ~/cued-masters/setup.bash 

Try the roslaunch command again.