Introduction

The normal work-flow for this course will be to log into a lab machine, clone a repository from stu, make your changes, then push those changes back to stu before logging out. This activity will walk you through that process, along with the steps of creating a ROS package.

Creating a Mercurial Repository

Complete the following steps in order to create an empty Mercurial repository on stu:

  1. SSH to stu:
    ssh YOUR_EID@stu.cs.jmu.edu
    
  2. Change directories to your folder in the cs354 course directory:
    cd /cs/students/cs354/f15/YOUR_EID
    
  3. Create a folder named wander and initialize the repository:
    mkdir wander
    cd wander
    hg init
    
  4. It will appear that nothing happened, but if you list the contents of this directory, you should see a folder named .hg:
    $ ls -la
    total 12
    drwxr-xr-x 3 spragunr faculty 4096 Sep 10 08:03 .
    drwxr-xr-x 4 spragunr faculty 4096 Sep 10 08:02 ..
    drwxr-xr-x 3 spragunr faculty 4096 Sep 10 08:03 .hg
    
    Congratulations! You have a mercurial repository.
  5. You should now log off from stu by typing exit. The remaining steps will be completed locally.

Cloning your repository

Mercurial is able to clone a remote repository over SSH. I'm providing a shell script that automates this process.

In addition to cloning your repository, this script makes sure that ~/catkin_ws is properly configured as a catkin workspace.

  1. Download the file hg_clone.sh and make sure that it is executable:
    chmod +x hg_clone.sh
    
    OR
    chmod 755 hg_clone.sh
    
  2. Execute the script. If all goes well, you should see something like the following:
    
    $ ./hg_clone.sh
    Enter eid: spragunr
    Enter repository name: wander
    
    INITIALIZING WORKSPACE
    Creating symlink "/home/student/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/indigo/share/catkin/cmake/toplevel.cmake"
    
    
    CLONING PACKAGE
    hg clone ssh://spragunr@stu.cs.jmu.edu/../../../students/cs354/f15/spragunr/wander /home/student/catkin_ws/src/wander
    no changes found
    updating to branch default
    0 files updated, 0 files merged, 0 files removed, 0 files unresolved
    

Creating and Building The Package

If all went well in the previous step, your repository should now be cloned to /home/student/catkin_ws/src/wander. The next step is to convert this empty folder to a properly configured ROS package.

  1. First, change directories into your workspace src folder:
    cd ~/catkin_ws/src/
    
  2. Now create the package:
    catkin_create_pkg wander std_msgs rospy
    
  3. If you look inside your wander folder, you should now see at least two files: CMakeLists.txt, package.xml. Update package.xml with the correct maintainer and author information.
  4. The following illustrates the standard layout of a Python-based ROS package:
    wander/
        package.xml                  <-- Package information
        CMakeLists.txt               <-- Build configuration
        src/                         <-- Importable Python modules go here.
            wander/                  <-- Python package for exportable modules.
                __init__.py          <-- This file turns the folder into a package.
                useful_module.py      
        rviz/                        <-- rviz configuration files.
            wander.rviz
        launch/                      <-- Launch files
            wander.launch
        msg/                         <-- Message files
        scripts/                     <-- Scripts that create Python ROS nodes. 
            wander.py
            announce.py
        srv/                         <-- Service files
    

    Create a scripts directory and place your forward.py, bumper.py and wander.py files inside it.

  5. Build your newly created package by changing into your workspace directory and typing:
    catkin_make
    

    Once this command completes, there should be devel and build directories along-side the existing src directory.

  6. Type the following commands into the terminal:
    source devel/setup.bash
    rospack profile
    

    The first command will configure your environment so that the ROS system is aware of your newly created package. The second command isn't strictly necessary. It forces an immediate update of the ROS's package list. Without this command it may take a couple of minutes before ROS "notices" that you new package exists.

    You should now be able to interact with your package using ROS command line tools:

    rosrun wander wander.py
    

    Congratulations! You now have a fully-functional, properly built, ROS package.

Saving Your Work

Once you are satisfied with your package, commit your work, and push it back to stu by completing the following steps:

  1. Change into your package folder and type
    hg add *
    
    to add all of your newly created files to the repository.
  2. Commit your changes by typing:
    hg commit -m 'First commit.' --user YOUR_EID
    
    Every time you commit your code you MUST provide a reasonably informative commit message.
  3. Push your changes back to stu by typing:
    hg push
    
    Your changes are not safe until you complete this step!
  4. Once you have completed the previous step, test that everything is OK by deleting the local version of your package, and then re-cloning it using the hg_clone.sh script.

Submitting

There is nothing to submit for this lab. I'll check your work by accessing your Mercurial repository on stu.