Vehicle Mechatronics Control Everybody loves ROS Slides Jari
Vehicle Mechatronics: Control Everybody loves ROS Slides: Jari Vepsäläinen & Pavithra Gopalakrishnan July 1, 2020
Contents 1. ROS Basics • • What is ROS? ROS Tools These lecture slides have been inspired by • ROS wiki (wiki. ros. org) • Stanford ASL course AA 274: Principles of Robot Autonomy 1 • Robot Ignite Academy: ROS Basics 2. ROS Architecture • Master, Nodes, Messages, Workspace, Packages and Launch Files 3. ROS Development • Packages and ROS program files (Node, launch files, …) 4. ROS Applications • Example application 5. ROS Debug
ROS development
Contents Packages 1. Catkin workspace – place for ROS packages 2. Create a package – how to do it? 3. Existing Packages – how to get them? ROS program files 1. Nodes – simple node 2. Launch files – simple launch file 3. Services – simple service server
Catkin workspace The directory for ROS packages • Usually referred to as catkin_ws. • Packages must be in catkin_ws in order to be usable by ROS.
ROS Packages • Packages are like "project" folders of ROS • Create your own, download online and share your own • Packages contain. . . • Nodes • launch files • custom messages • custom services messages
<Package> directory • src folder: Contains source files (your python programs) • CMake. Lists. txt: list of cmake rules for compilation • package. xml: Package information and dependencies Optional • Launch folder: Contains launch files • msg folder: Contains custom message files • srv folder: Contains custom service message files
Creating a package 1) Go to your catkin workspace source directory $ cd ~/catkin_ws/src 2) Create an empty package $ catkin_create_pkg <name> [depend 1] [depend 2] [depend 3] $ package catkin_create_pkg test_pkg rospy roscpp std_msgs 3) (Optional) modify basic information in package. xml • <name> <version> <description> <maintainer> <licence> <url> <author>
Building a package When you have downloaded a package, you must build it before using it Make sure you are in the catkin workspace directory $ cd ~/catkin_ws or $ roscd; cd. . 1) Build a specific package $ catkin_make [make_targets] 2) Build all packages $ catkin_make
Importing an existing package 1. Go to catkin workspace source folder 2. Clone a package folder from e. g. Git. Hub 3. Build the workspace (or just the package) $ cd ~/catkin_ws/src/ $ git clone https: //github. com/ROBOTIS-GIT/open_manipulator. git $ cd ~/catkin_ws && catkin_make
ROS program files
ROS Nodes • Create to the source folder of the package <your_pkg>/src/ • Make sure that they’re executable $ chmod +x <your_node>. py • In the terminal, executable files are written in green • Simple node: # /usr/bin/env python import rospy. init_node(‘simple. Node’) print “This is a simple node that only prints this line once”
ROS Node, continuous loop • Usually nodes are kept active, in a loop • Simple node, continuous loop: # /usr/bin/env python import rospy rate = rospy. Rate(1) # Rate object of 1 hz rospy. init_node(‘simple. Node’) While not rospy. is_shutdown(): # Endless loop print “This node prints this line once every second, forever” rate. sleep()
ROS Node, publisher # /usr/bin/env python import rospy from geometry_msgs. msg import Twist # Twist is under topic /cmd_vel rospy. init_node(‘move. Node’) pub = rospy. Publisher('/cmd_vel', Twist, queue_size=1) move = Twist() # create a message object move. linear. x = 0. 3 # move forward move. angular. z = 0. 2 # turning to left rate = rospy. Rate(1) While not rospy. is_shutdown(): # Endless loop publish(move) # what is the turtlebot doing forever? rate. sleep()
Note: Struct type variables • Topics usually publish messages in struct format • This means that the information is "nested" or "layered" • For example part of /odom published the nav_masg is: To access x position value, call: <msg>. pose. position. x
ROS Launch Files XML files that … • Launch one or multiple ROS nodes • Set parameters for the nodes • Start ROS master when run $roslaunch <package> <file>. launch Example: Launch file for initializing talker and listener nodes
ROS Launch file example <launch> <node pkg="my_package” type="simple_loop. py” name=”Simple. Loop" output="screen"> </node> </launch> Package of the launch file (and nodes) Name of a node to be launched Name of the launched program (decide yourself) Where are info/logs about the program sent? - - > “screen” refers to the terminal
ROS Service Server • Is a node • Located in <pkg>/src/ • Coded in python or C++ • Provides a functionality that can be called
ROS Service Server • Request • From Client to Server • Simplest service message in ROS is Empty() • The request part of that message is Empty. Request • Response • The response part of Empty() is Empty. Response Empty message is, nothing. The point to use is for invoking a service without sending any additional information in the request
Simple service server node # /usr/bin/env python import rospy from std_srvs. srv import Empty, Empty. Response def callback(request): print “Simple service called!" return Empty. Response() # the service Response class, in this case rospy. init_node(‘simple_service_server') my_service = rospy. Service(‘/simple_service', Empty , callback) rospy. spin() # maintain the service open (loop)
Launch service <launch> <node pkg=”simple_service_pkg” type="simple_service_server. py” name=”Simple. Server" output="screen"> </node> </launch> Package of the launch file Name of a node to be launched Name of the launched program (decide yourself) Where are info/logs about the program sent? - - > “screen” refers to the terminal
Call for a service $ rosservice call /the_service_name TAB-TAB means a double-tap of tab, to get show the default msg to be send to the server. In the example case: $ rosservice call /simple_service “{}”
End of second ROS session – Thank you!
- Slides: 23