02. Linux, ROS alapismeretek
Elmélet
Linux principles

- Only OS supported by ROS
 - Security
 - Efficieny
 - Open-source
 - Community support
 - User freedom
 - Distributions: Ubuntu, Linux Mint, Debian, etc.
 - Terminal usage more dominant
 
Suggestion
Install Terminator terminal emulator:
sudo apt update
sudo apt install terminator
Linux commands
See some basic commands below:
- Run as administrator with 
sudo - Manual of command 
man, e.g.man cp - Package management 
apt, e.g.apt update,apt install - Navigation 
cd - List directory contents 
ls - Copy file 
cp - Move file 
mv - Remove file 
rm - Make directory 
mkdir - Remove directory 
rmdir - Make a file executable 
chmod +x <filename> - Safe restart: Crtl + Alt + PrtScr + REISUB
 - If not sure, just google the command
 
ROS principles
ROS file system
ROS package principle
Enough functionality to be useful, but not too much that the package is heavyweight and difficult to use from other software.
ROS package
- Main unit to organize software in ROS
 - Buildable and redistributable unit of ROS code
 - Consosts of:
- Manifest (package.xml): information about package
- name
 - version
 - description
 - dependencies
 - etc.
 
 - CMakeLists.txt: input for the CMake build system
 - Anything else
 
 - Manifest (package.xml): information about package
 rosrun turtlesim turtlesim_node
ROS node
- Executable part of ROS:
- python scripts
 - compiled C++ code
 
 - A process that performs computation
 - Inter-node communication:
- ROS topics (streams)
 - ROS parameter server
 - Remote Procedure Calls (RPC)
 - ROS services
 - ROS actions
 
 - Meant to operate at a fine-grained scale
 - Typically, a robot control system consists of many nodes, like:
- Trajectory planning
 - Localization
 - Read sensory data
 - Process sensory data
 - Motor control
 - User interface
 - etc.
 
 
ROS build system---Catkin
- System for building software packages in ROS
 
ROS workspace
Catkin workspace
A folder where catkin packages are modified, built, and installed.
- Source space:
- Source code of catkin packages
 - Space where you can extract/checkout/clone source code for the packages you want to build
 
 - Build space
- CMake is invoked here to build the catkin packages
 - CMake and catkin keep intermediate files here
 
 - Devel space:
- Built target are placed here prior to being installed
 
 
Environmental setup file
- setup.bash
 - generated during init process of a new workspace
 - extends shell environment
 - ROS can find any resources that have been installed or built to that location
 
source ~/catkin_ws/devel/setup.bash
ROS master
roscore
- 
Registers:
- Nodes
 - Topics
 - Services
 - Parameters
 
 - 
One per system
 roslaunchlaunches ROS master automatically
Gyakorlat
Figyelem!
Az óra végén a forráskódokat mindenkinek fel kell tölteni Moodle-re egy zip archívumba csomagolva!
1: Turtlesim
- 
Indítsuk el a ROS mastert,
turtlesim_node-ot és aturtle_teleop_keynode-ot az alábbi parancsokkal, külö-külön terminál ablakokban:Tip
Terminator-ban
Ctrl-Shift-O,Ctrl-Shift-Ebillentyű kombinációkkal oszthatjuk tovább az adott ablakot.Ctrl-Shift-Wbezárja az aktív ablakot.roscore rosrun turtlesim turtlesim_node rosrun turtlesim turtle_teleop_keyFuttatás megszakítása
Ctrl-C
 - 
Az alábbi parancs segítségével jeleníttessük meg a futó rendszer node-jait és topic-jait:
rosrun rqt_graph rqt_graph
 - 
Az alábbi ROS parancsok futtatása hasznos információkkal szolgálhat:
roswtf rospack list rospack find turtlesim rosnode list rosnode info rosnode info /turtlesim rostopic list rostopic info /turtle1/cmd_vel rosmsg show geometry_msgs/Twist rostopic echo /turtle1/cmd_vel
 - 
Írjuk be a következő parancsot terminálba:
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]' 
2: Catkin workspace
- 
Telepítsük a catkin build tools csomagot:
sudo apt update sudo apt-get install python3-catkin-tools python3-osrf-pycommon
 - 
Másoljuk az alábbi sort a
~/.bashrcfájl végére:source /opt/ros/noetic/setup.bash # replace noetic by whatever your ROS distribution is
 - 
Hozzuk létre a workspace-t:
source /opt/ros/noetic/setup.bash mkdir -p ~/catkin_ws/src cd ~/catkin_ws catkin init 
3: ROS package létrehozása
- 
Hozzunk létre új ROS package-et
ros_coursenévvel.cd ~/catkin_ws/src catkin create pkg ros_course --catkin-deps std_msgs rospy roscppSzintaxis
catkin create pkg <PKG_NAME> --catkin-deps <DEP_1> <DEP_2>
 - 
Nyissuk meg a
package.xmlfájlt, és töltsük fel a következő tag-eket:<description>The beginner_tutorials package</description> <maintainer email="you@yourdomain.tld">Your Name</maintainer>
 - 
Build-eljük a workspace-t.
cd ~/catkin_ws catkin buildDanger
Soha ne használjuk a
catkin buildés acatkin_makeparancsokat ugyanabban a workspace-ben!
 - 
A
~/.bashrcfájl végére illesszük be az alábbi sort:source ~/catkin_ws/devel/setup.bash 
4: Publisher implementálása Python-ban
- 
Hozzunk létre egy mappát
scriptsnévvel aros_coursepackage-ben.cd ~catkin_ws/src/ros_course mkdir scripts cd scripts
 - 
Navigáljunk a
scriptsmappába és hozzuk létre atalker.pyfájlt az alábbi tartalommal.import rospy from std_msgs.msg import String def talker(): rospy.init_node('talker', anonymous=True) pub = rospy.Publisher('chatter', String, queue_size=10) rate = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): hello_str = "hello world %s" % rospy.get_time() print(hello_str) pub.publish(hello_str) rate.sleep() if __name__ == '__main__': try: talker() except rospy.ROSInterruptException: pass
 - 
A
CMakeLists.txt-hez adjuk hozzá a következőt:catkin_install_python(PROGRAMS scripts/talker.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
 - 
Build-eljük és futtassuk a node-ot:
cd ~/catkin_ws catkin build rosrun ros_course talker.pyTip
A node futtatásához szükség van a ROS masterre. Egy külön terminál ablakban indítsuk el a
roscoreparanccsal.
 - 
Ellenőrizzük le a node kimenetét a
rostopic echoparancs használatával. 
5: Subscriber implementálása Python-ban
- 
Navigáljunk a
scriptsmappába és hozzuk létre alistener.pyfájlt az alábbi tartalommal.import rospy from std_msgs.msg import String def callback(data): print(rospy.get_caller_id() + "I heard %s", data.data) def listener(): # In ROS, nodes are uniquely named. If two nodes with the same # name are launched, the previous one is kicked off. The # anonymous=True flag means that rospy will choose a unique # name for our 'listener' node so that multiple listeners can # run simultaneously. rospy.init_node('listener', anonymous=True) rospy.Subscriber("chatter", String, callback) # spin() simply keeps python from exiting until this node is stopped rospy.spin() if __name__ == '__main__': listener()
 - 
A
CMakeLists.txt-hez adjuk hozzá a következőt:catkin_install_python(PROGRAMS scripts/talker.py scripts/listener.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
 - 
Build-eljük és futtassuk mind a 2 node-ot:
cd ~/catkin_ws catkin build rosrun ros_course talker.pyrosrun ros_course listener.py
 - 
rqt_graphhasználatával jeleníttessük meg a futó rendszer node-jait és topic-jait:rosrun rqt_graph rqt_graph 
Figyelem!
Az óra végén a forráskódokat mindenkinek fel kell tölteni Moodle-re egy zip archívumba csomagolva!