Skip to content

A bunch of scripts and maybe more to cover some basics in ROS

Notifications You must be signed in to change notification settings

mtc-20/ROS_Basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 

Repository files navigation

ROS_Basics

A bunch of scripts (Python) and maybe more to cover some basics in ROS. The idea is to explain basic functionality (nodes and launch files) all under a single package. These are based on various tutorials from across the ROS Wiki, that tries to consolidate them under relevant headings.
MTC 161019

Sections

  1. Packages
  2. Nodes
  3. Launch Files
  4. Further Reading

These are all under the assumption that you've already created your catkin workspace. If not, follow this link here, before proceeding further.

Packages

Packages are directories that house nodes of similar functionality. Let's create a package basic_ros in the catkin workspace, as follows

$ catkin_create_pkg basic_ros std_msgs rospy

then run catkin_make and source the bash file

$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash

Tip: Instead of sourcing the bash file in every new terminal, you could add it to the ~/.bashrc file. This can also be done via command line as follows

$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
$ source ~/.bashrc

In the above line, std_msgs rospy are the package dependencies. Use the rospack command to find all the dependencies of a ROS package.

Tip: In case you forgot to specify certain dependencies or want to add more dependencies to a package, you can do so by modifying the package.xml to include them using the <build_depend> and <run_depend> tags.

Nodes

Nodes in ROS can be compared to apps in an OS, they need to be executed to perform a certain or any operation. The most basic types of nodes are a publisher node and subscriber node, more details can be found in the ROS Wiki.
All the nodes, written in python, can be found in the scripts folder. Just download the entire folder into the basic_ros package/directory, and make sure all the files are executable

chmod +x talker.py

before executing them as follows

$ rosrun basic_ros talker.py

Of course, remember that you need to have 'roscore' running in another terminal for 'rosrun' to work. Alternatively, go to the scripts directory and run

$ python basic_ros talker.py

In case this didn't work, you may have to run catkin_make.

Tip: A neat shortcut to check if your package has been built properly is to use the autocomplete feature with roscd or rosrun command. Basically type the first two or three letters of your package name and double press the tab button,if the autocomplete doesn't work, it implies that you either haven't sourced the workspace or havent built your packages yet.

  • Talker

File - talker.py
A simple publisher node that publishes a string message, "hello world" with a time stamp, at the rate of 1 per second to the talker topic.

  • Listener

File - listener.py
A simple subscriber node that subscribes to the talker and bingo topics and prints the message to the log file. Notice running the listener.py node without any active publisher nodes doesn't produce any output.

  • Bingo

File - call_bingo.py
Another publisher node that publishes a random number between 1 and 100 as a string message to the bingo topic.

  • Talker with Parameters

File - talker_param.py
A modified talker node that now accepts a ROS parameter to modify it's frequency of printing mesages to the server. By default, it will print 1 message every 2 seconds(0.5Hz). This parameter can be changed to 3Hz via command line as follows

$ rosrun basic_ros talker_param.py _freq:=3

NOTE: Make sure rospy.get_param() is declared after rospy.init_node().

Launch Files

Each node is normally executed using the rosrun command, which implies that a new terminal has to be opened for every node required. This is circumvented by a launch file, XML files that run the different nodes serially.
All the launch files are maintained in the launch folder in basic_ros and these are called using the roslaunch command.

$ roslaunch basic_ros chat.launch
  • Chat

File - chat.launch
A simple launch file that 'launches' three of the above nodes.
Notice nothing is output/printed to the terminal. However, using the rostopic echo shows that the talker are in fact publishing. The rosnode info tool will show all the subscriptions/publications to the corresponding nodes.

  • Chat with Arguments

File - chat_param.launch
A simple launch file that 'launches' the listener and talker_param nodes, accepts arguments and outputs the listener node. Notice running this launch file sets the talker_param node's default frequency to 3 instead of 0.5Hz. Arguments can be provided in command line as follows

$ roslaunch basic_ros chat_param.launch freq:=1

PLANNED

  • ROS Messages, Services, Action clients
  • More on rosparams
  • Useful tools: like rqt, roswtf, rospack, etc. : shifted to a new repo, can be found here

FURTHER READING

Releases

No releases published

Packages

No packages published

Languages