Lab: Intro to Terminal & ROS

Personal note: We realize some of you may find this a bit slow/pedantic, but please know that we aren’t doing this just to annoy you. Knowledge being what it is, it is often necessary to learn a language before trying to write with it. And if you do enjoy the language itself, that’s cool beans too!

Manipulating Files Using the Terminal

  1. Make sure you have an installation of ROS.
    • If you installed ROS on your (presumably Ubuntu) computer or if you have a monitor plugged in to your car, you are good to go.
    • Otherwise, run Docker (because the fishberg/racecar image has an installation of ROS) and mount to a folder on your host machine. (Good luck! Hehe.)
  2. Use terminal commands to navigate to a folder that holds programs.
    The terminal command for navigating to a folder is cd <path_to_folder>/.
    • If using a racecar, navigate to the "~/racecar_ws/src/scripts/" folder.
    • If using your own computer, navigate to wherever makes sense.
    • If using Docker on your computer, navigate to your mount folder (in either your host machine terminal or the Docker machine terminal).
    Some Common Folders, For Reference
    • "/" is the folder that holds all other folders
    • "~/" is the home folder
    • "./" is the current folder
    • "../" is the folder that holds the current folder
    • "~/racecar_ws/src/scripts/" is a good folder for store programs on the racecars
  3. Create a new folder for this lab's programs, and name it "example_ROS_files".
    The terminal command is mkdir <new_folder_name>.
  4. Download the ROS lab starter files from here on Google Drive and move them to the folder you just created.
    The terminal command for moving files is
    mv <folder_path_to_copy_from>/<file_name> <folder_path_to_copy_into>/<new_file_name>.
    • If you're directly on the car, make sure that your car's router is plugged into an active ethernet port, or just connect the car to Wifi network.
    • If you're using Docker, you'll want to do this on your host machine. If you've mounted correctly, the files should also appear in the Docker machine's mount folder.

  5. Creating a ROS Network from Scratch

  6. In a terminal that has ROS, run roscore.
    In short, roscore is a sort of master node looks at all the other nodes’ publishers and subscribers and connects them appropriately. See the "Connecting Nodes" section of the ROS Reference Page.
  7. Take a look at and try to predict what it does.
    (i.e. open it with some text editor)
    If you still aren’t sure what’s going on after about 5 min, just move on to the next step.
  8. In another window/tab of terminal, run
    The terminal command is <path_to_file>/<python_file_name>.
    This works because we have #!/usr/bin/env python at the top of our python files. Otherwise we would need to use python <path_to_file>/<python_file_name> to run our file as a python program.
    Does your code not run at all (no Python errors or anything)? Has your permission been denied? Well then folks, it’s debugging time!
    • What’s probably going on is you don’t have the permissions set to let your programs be executable. We can check this by trying ls -la while in your program’s folder. If your terminal spits back "-rw-r--r--" preceding your filename (""), that is indeed what's happening.
    • Add executable permission by running chmod +x <file_name>.
    • Hopefully you'll see something different if you run ls -la again.
  9. Try rosnode list, then rostopic list, then rostopic echo blah, then rostopic echo blah/data. Then take a look at "" again.
    • Just use one more window/tab; you don’t need to run these all at the same time.
    • Where exactly in "" do you see some of the names that rosnode list and rostopic list spat out?
    • Take note of the small difference between "blah" and "blah/data". It will become more important as we begin to deal with messages that have many attributes.
    • Now if there’s a detail about the node that still doesn’t make sense, please ask your squad members or your TA’s what’s the situation here because the rest of the lab builds upon this.
    • See the ROS Command Line Cheatsheet for more fun and informative ROS commands.
  10. Now take a look at and fill it in to make it work like
    In case you haven’t heard of classes before, we created a class in "". Used this way, the class structure simply helps organization. We will not expect you to write classes from scratch, but that said, classes are good to know if you plan on working with object-oriented programming long-term.
  11. Now fill out "" so that it subscribes to the "blah" topic and prints out the messages it receives. Run it at the same time as "".
    See the "Subscribers" section of the ROS Reference Page for a review of subscribers and callback functions if needed.
  12. Say you called your messages "msg". Try printing "msg" versus "" to tell the difference between the two.
    You should see a similar difference as to when you tried echoing "blah" vs "blah/data".
  13. While the nodes are running, try rqt_graph.
    Is this the graph you anticipate? If not, please ask your squad members or your TA’s what’s going on here because this is decently important to understanding ROS.