2: ROS at a high level slides |

A quick flyby of the most important concepts of ROS

ROS Fundamentals

  • A distributed “operating system”
  • A process coordinator and an inter-process communications model
  • Different parts (nodes) can run on different computers
  • They all need to be connected by a network via TCP/IP

Connecting via Network

  • It could be a wired or wireless network
  • Each participating computer must have an IP address
  • An IP address can be represented as a subdomain name, e.g. robb.dyn.brandeis.edu
  • And all participants must be “visible” to each other on the network

What are the possible participants?

  • Computers (running any OS potentially)
    1. The robot itself
    2. Your ROS cluster account
  • Really any computer with ROS installed
  • Of course they need to be on the/a network
  • EDUROAM or some other network.
  • Somehow they need to know about each other
  • Virtual Private Network

Writing ROS software

  • Can be written in Python or C++. We will be using Python exclusively
  • Built up from multiple independent programs called Nodes
  • Each node is implemented as a separate program
  • It can use all the python features: classes, functions, imported packages, etc

ROS Nodes - the basic unit

  • Fundamental concept in ROS
  • ROS runs a number of collaborating processes called “nodes”
  • Think of it as a program or a process which forms part of a system
    1. A real robot will have dozens to hundreds of nodes
    2. You can write nodes in Python (we will do) or C++
  • Nodes talk to each other by publishing and subscribing to messages

Example of a very simple node


#!/usr/bin/env python
# Don't forget to chmod +x topic_publisher.py

import rospy
from std_msgs.msg import Int32

# Make this into a ROS node.
rospy.init_node('my_publisher_node')

# Prepare to publish topic `counter`
pub = rospy.Publisher('counter', Int32, queue_size=10)

# sleep at 2 loops per second
rate = rospy.Rate(2)
count = 0

# loop until ^c
while not rospy.is_shutdown():
    pub.publish(count)
    count += 1
    rate.sleep()
    rospy.sleep(0.5)

ROSCORE

  • Program that acts as global coordinator of all the nodes
  • It is run once at a known ip address or domain name
  • Any other node will make contact with it to announce itself
  • When one node talks to another, roscore helps them find each other and then steps out of the way.
  • Everything starts with the ‘traffic-cop’ roscore
    1. Once roscore runs, additional nodes can run
  • Each node is essentially a separate program, maybe even a single file
    1. A node can be written in Python or C++ (or really technically any language)
    2. We will use Python mostly

“Running” a ROS application

  • Consists of several fairly independent nodes
  • They all have to be launched
  • Together they form the whole ROS application

ROS shell commands

  • Also known as the ROS CLI - command line interface
  • They take care of setting up the environment
  • Here are the ones you must learn and get used to
    1. rosrun - runs a single ROS node
    2. roslaunch - launches a sequence of ROS Nodes
    3. rostopic - Inspect ROS topics
    4. roscd - change directory to a ROS package
    5. catkin_make (alias cm)

Our built-in aliases: See labnotebook aliases

ALERT The most common explanation for weird result is that your environment variables are not set up
  • Reset environment: cs
  • Rebuild cm
  • My own IP address: myip
  • My own vpn IP address myvpnip

ROS Directory Structure

  • This is the standard directory structure

# top level directories. Once per system. This will already exist.
./catkin_ws
  /devel
  /build
  /src
     /cosi119_src/
        /src
        /...etc
        

Inside ./src there are directories each with a ROS package. They all have a standard shape as well and can be nested inside each other.


# Here is an example
 ./turtlebot3_gazebo
  /launch
    turtlebot3_stage_1.launch
    .
    .
  /src
    run_world.py
    turtlebot3_drive.cpp
  ... and other directories
  CMAkeLists.txt
  package.xml