Artificial Intelligence for Robotics
上QQ阅读APP看书,第一时间看更新

Installing ROS on the laptop

We need a copy of ROS to talk to our robot and to execute development. You can find directions on how to do this at the ROS website repository at http://wiki.ros.org/kinetic/Installation/Ubuntu.

I'll give you the quick and dirty method here:

Get on your Linux laptop/desktop computer – virtual or otherwise – and get to a command prompt. We need to establish the source of the software. We do this as follows:

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

We need to set up our key to get access to the software with this command. Remember that you can cut and paste this from the ROS website as well:

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

At this point, it is recommended that you check that your Linux installation is up to date. We can do this by entering the following command:

sudo apt-get update

This is going to take a bit of time depending on your internet connection and computer. 

Now, we are finally ready to install the main ROS distribution. Since we are on a desktop or laptop computer, we can get the whole thing, so that we have all of the tools and user interfaces. Note that we are using ROS Kinetic, the latest full release as at the time of publication of this book:

sudo apt-get install ros-kinetic-desktop-full

Expect that this step can take quite a while – it was about 30 minutes on my computer. Once it finally finishes, we can proceed to setting up the ROS on our computer. We need to set up the ROS dependency manager using these commands:

sudo rosdep init
rosdep update

rosdep keeps up with which other packages your program depends on, and will download them automatically if they are missing. This is a good feature to have, and we won't be needing it very often – just when we install a new package. 

This next part is really important. ROS uses several environment variables to configure some important parts of the system, such as keeping up with which computer is in charge. The default configuration is set by doing the following:

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

The first setup appends the /opt/ros/kinetic/setup.bash to our default .bashrc file so that those environment variables will get automatically created each time we start a new terminal window. The .bashrc script is executed when a new bash shell program is started. 

We can check the default setup by looking at the environment variables. Let's get only the ones with the string ROS inside them by using a pipe (|) symbol and the grep command:

>>:~$ env | grep ROS
ROS_ROOT=/opt/ros/kinetic/share/ros
ROS_PACKAGE_PATH=/opt/ros/kinetic/share
ROS_MASTER_URI=http://localhost:11311
SESSION_MANAGER=local/BookROS:@/tmp/.ICE-unix/1847,unix/BookROS:/tmp/.ICE-unix/1847
ROS_DISTRO=kinetic
ROS_ETC_DIR=/opt/ros/kinetic/etc/ros

The most important variable in this set is the ROS_MASTER_URI. This points to the place where the ROSCORE program is running. Normally, this will be on the robot. Let's say the robot’s IP address is 192.168.1.15. Then, we set the ROS_MASTER_URI to be http://192.168.1.15:11311. You can also set up an entry in the /etc/hosts file with the name of the robot and the IP address as follows:

>>:sudo nano /etc/hosts
192.168.1.15        tinman 

Then you can use the hostname tinman in place of the IP address: 

env ROS_MASTER_URI=http://tinman:11311. 

Remember to change this in the .bashrc script as well (nano .bashrc).