Search
During this lab, you should learn how to use the Singularity, the tmux, the terminal commands of Robot Operating System (ROS), and how to program a simple python subscriber/publisher node.
The Singularity is software for virtualization via containers that allows you to program and test ARO homeworks and semestral work without installing all ROS dependencies on your computer.
git clone https://gitlab.fel.cvut.cz/robolab/deploy.git ./deploy/scripts/install_singularity ./deploy/scripts/download_singularity_aro ./deploy/scripts/start_singularity_aro source /opt/ros/aro/setup.bash
Tmux allows you to switch easily between several windows in one terminal., detach them (they keep running in the background) and reattach them to a different terminal. To start Tmux use:
tmux
tmux a
Inside tmux session, press $prefixctrl+b followed by any of the keys below to controll the session:
ctrl+b
+ d
+ c
+ w
+ n
+ p
+ ,
+ %
+ “
Robot Operating System (ROS) https://www.ros.org/ is a set of software libraries that allows you to build a complex robotic system. It is not an operating system but rather a very convenient middleware for sharing data (messages) between different parts of the robot's software (nodes). When using ROS you can leverage the work of others and use an already very large code base of implemented packages for, e.g., mapping, localization, control, planning, and sensor interfacing.
Key aspects/buzzwords to know are:
roscore
The code for your projects with ROS is stored in a workspace. You can create your own workspace in some folder by running the following commands in started singularity image:
cd <where_you_want_the_workspace> source /opt/ros/aro/setup.bash mkdir -p catkin_ws/src cd catkin_ws catkin build source devel/setup.bash
ROS has many handy command line programs that you can learn.
rosnode list/info <node_name>/ping <node_name>/kill <node_name>
rostopic list/info <topic_name>/hz <topic_name>/echo <topic_name>/type <topic_name>/pub <topic_name> <topic_type> <data>
rosmsg list/show <message_type>/package
roslaunch <package_name> <launch_filename>
rosbag record/play/info
roscd <package_name>
rosrun <package_name> <node_name>
catkin build/clean/init/config
Test the following individual commands. Use the tab for suggestions of node names, topic names, message types, etc.
rosnode
rostopic pub /new std_msgs/String "data: 'whaaat'" -r 10
rosmsg list
In ROS noetic we will use python 3. The most important library that enables interfacing with ROS is rospy. The typical content of a package folder in, e.g., catkin_ws/src/my_package/ is:
Always make sure the python node is a runnable script chmod u+x <filename>.py, otherwise you can not start it with rosrun or roslaunch. Always make sure to source devel/setup.bash in your workspace after you build your workspace with catkin build. You need to build the workspace if you have new package, if you change c++ code or, e.g., message definitions. Changing python code does not require rebuilding.
chmod u+x <filename>.py
source devel/setup.bash
catkin build
At the beginning of a python script you need to initialize the node such that it is registered within the ROS with rospy.init_node('my_node') command. Afterwards you can initialize all your subscribers, publishers, threaded workers, etc. Finally you need to run rospy.spin() which internally runs the messaging system of the node (especially important for subscribers to run callbacks for new messages).
rospy.init_node('my_node')
rospy.spin()
You can print messages within your package with different severity levels using:
rospy.loginfo('your message')
rospy.logwarn('your warning message')
rospy.logerr('your error message')
Messages are data structures used to send data over topics. They are composed of either simple or complex data types. Simple types are, e.g.: bool, int<N>, uint<N>, float<N> (with N being {8, 16, 32, 64}), String, Time, Duration (see standard messages rosmsg package std_msgs). Complex data types are composed of simple ones or their arrays (see, e.g., rosmsg info std_msgs/Header ). Custom message files can be defined in message files and their respective c++ headers and python objects are generated during build.
rosmsg package std_msgs
rosmsg info std_msgs/Header
Publisher is an object assigned to a specific topic and message type that you can use to send messages from your node to other nodes. You can create publisher object using: publisher = rospy.Publisher('mytopic', AROMessage, queue_size=10). Then every time you want to send a message you create a new message object msg = AROMessage() , then fill it with your data (msg.message=“ahoj”) and publish it to ROS using publisher.publish(msg).
publisher = rospy.Publisher('mytopic', AROMessage, queue_size=10)
msg = AROMessage()
msg.message=“ahoj”
publisher.publish(msg)
Subscriber is an object that basically assigns a callback function to received messages of a given topic name and message type. You can create the subscriber using: subscriber = rospy.Subscriber('mytopic', AROMessage , callback) ,where the callback is a custom function (def callback(msg):) that handles the received message.
subscriber = rospy.Subscriber('mytopic', AROMessage , callback)
def callback(msg):
Implement a simple publisher and subscriber nodes as specified below. Follow the TODOs inside the code. You can get inspiration on how to write such python nodes in the following ROS tutorial.
publisher.py
lab01_demo.launch
subscriber.py
num_messages
Follow the assignment of the homework HW1 which requires only some additional work compared to the lab task above.