Skip to content
This repository was archived by the owner on Sep 4, 2022. It is now read-only.

ROS 101

simonireland edited this page Apr 4, 2015 · 5 revisions

A ros tutorial program which is much more intuitive than the ros wiki: Ros tutorial

ROS works by having topics to which publishers (programs) can write/add messages that subscribers (other programs) can read from.

ROS programs are contained in folders called Catkin Workspaces, this is the folder that you run catkin_make to compile your code.

Everytime you work on ros code you need to cd to the folder that contains your workspace and then run "source devel/setup.bash". If you do not do this your code may not run or run correctly

A ros workspace has the following files in it:

src - this contains your ros packages devel - this contains configuration build - this contains lots of build files

Each workspace is broken up into a set of packages, these are contained in the src folder. Each package contains two files Package.xml and CMakeLists.txt these files control how the package is built. < It also contains a src folder. This is where you put in your c++ code.

Add c++ files to a package

When you add a c++ file to your package you need to add it to CMakeLists.txt in that packages source folder. This makes sure it is built.
To do this add the following lines of code:
add_executable([node_name] src/[node_name].cpp)
target_link_libraries([node_name] ${catkin_LIBRARIES})
add_dependencies([node_name] ${catkin_EXPORTED_TARGETS})

Where [node_name] is the name of you file without .cpp on the end

Building your code

Go to your catkin_workspace directory. (That is the directory that contains the src folder that contains your package, not the directory that contains package.xml). Then run the following: catkin_make

Basic Publisher

This sends out a ros message Please see here: navigator.cpp (sorry couldn't get quotes to work properly in this wiki)

Basic Subscriber

This get ros messages sent by over nodes Please see here: sender.cpp (sorry couldn't get quotes to work properly in this wiki) The function reciveMessage is called everytime it gets a new message.

Note: a single file can contain both a publisher and a subscriber I will add more detail ASAP.

[If using Eclipse and you want to be able to resolve ros functions add: /opt/ros/groovy/include in: project->properties->C/C++ general->Paths & Symbole in the includes tab under GNU C++]

Clone this wiki locally