/ROS-Instructions

This is the reading of a future robotics course, serves as a quick start to ROS and remainder of cumbersome details.

Installation

Make your life easier: http://wiki.ros.org/turtlebot/Tutorials/indigo/Turtlebot%20Installation. Under the section 1.1.1 on the page linked above, find the ISO with ROS and Turtlebot software installed.

It is highly recommand to find an old and NON-FANCY laptop to run linux on. Something like a fancy gaming laptop or Surface often have custimized motherboards which make installing linux and dual-booting a little harder, but if that's the only option, it's still doable.

Consult your TA, professor and online community often, don't get stuck. The process can be irritating.

WARNING: The Macbook pro 2016 or newer (the one with touchbar) seems not supporting ubuntu for now.

Talk keynote 1: ROS Basics — Topics, Service, Actions

A ROS system is made up of many different programs running simultaneously. Each program is called a node. The nodes are communicating with one another with a peer-to-peer manner by passing messages. That means messages are not passing through the roscore , each node just uses roscore to find each other.

  • Messages are nothing fancy, but data structures. Here is an example of a message:

This message is called Point. It represents a point in a coordinate system. It has three float values x, y, z. A message is like a structs or class without methods. You will use a lot of this in the future. Anytime you want to do anything in ROS system, you have to have some kind of message to talk to the system (of course, you can create your own message which will be introduced later).

  • Topics are names for streams of some messages with defined types. For example, the lidar sensor(the one is spinning on top of the turtlebot) is constantly publishing message LaserScan on the topic named scan. In ROS, there are countless topics, nodes are posting messages on topics each time(with various rate). One classic way you want to manipulate the ros system is through taking the messages from topics, making use of them and posting some messages on some topics back. In ROS, it's called Publish and Subscribe. Lots of nodes are basically following this model.

    A natural question to ask is: How do I know what topics are there? It's nice and easy, just use command rostopic list. This will list all the topics that are currently existing in the system. What I mean by that is there are countless topic, but each time in your system there are only few nodes posting messages on some topics. I just need to care about ones that are currently existing.

    ROS gives a very convinient way of working with topics.

    rostopic info /odom to view the odom topic.

    /odom is the odometry information currently in the system. As shown in the picture, the gazebo simulator is publishing odom and the android/virtual_joystick is subscribing this and the message type is nav_msgs/Odometry.

    rostopic echo /odom to view the data in real time.

    keep in mind these three command, you will use them a lot.
  • Services are synchronous remote procedure calls. This term has the same meaning here as in elsewhere. For topics, subscribing and publishing are all happening on where the node is running. For services, after setting up the server, when you make a service call, the computation is sent to the server which is another node. A service call would look excactly like a normal function call, except the fact that it will wait for the result from server.

    alt text

    The add_two_ints() is the local proxy function. It's obtained by asking from rospy(underlying ROS system). 'add_two_ints' is the name of the service, which has been advertised before. The second parameter is the type of the service, which has to be defined before in a similar way as defining messages. The the call add_two_ints(1, 2), is actually sent to other node to be computed. Read more.

    The ROS system takes care of all the communication behind the scene. It's a good way to distribute the computation workload. Service calls are well suited to things that you only need to do occasionally and that take a bounded time to complete. For example, letting the robot navigate to a destination is not a well suited task for the service model, since you have no idea about when it can be done or if it can be done and you don't want to wait at the service call forever.

  • Actions are designed to solve this problem. ROS actions are the best way to implement interfaces to time-extended, goal-oriented behaviors like navigation. This will be introduced more throughfully in the future talk - Navigation in ROS. An action is defined with three part: goal, result and feedback. Each of them is some kind of data structure. Usually, actions, services and topics uses the same set of data structure for a easy communication. For actions, it's like service model, you have to have a server which is another node. The server will take a goal, react accordingly and send back a result. Also, you can set up a feedback which will be sent back to the client. (remember: feedbacks, results, and goals are all just messages, don't be confused.)

Talk keynote 2: ROS Development — Workspace, Packages, Rosrun

Coding in ROS is actually straightforward, but the non-coding part can sometimes be frustrating. First of all, you have to know the idea of workspace and packages.

  • Workspace is in where all your ROS code lives. It's nothing but a directory(a folder, to make it even clearer). Besides the code in underlying ROS system, all code in you want to use should be in the workspace. You can have multiple workspaces, but each time there can be only one in effect.

    How does the system know which one and where it is?

    • Everytime you want to start working on your code, you have to source a setup shell script file in the workspace. So that the system knows this particular workspace and code in your packages are what you are talking about. A lot of times, the reason people run into "package not found" error is because they forgot to source the setup file in the workspace. It's a pain to type in all the commands everytime you open a terminal. To aviod that, put in the source command in the .bashrc file, so that the terminal runs this command automatically.

      echo "source ~/(YOUR WORK SPACE)/devel/setup.bash" >> ~/.bashrc

      Conventionally, the workspace is named as �something like catkin_ws. (What's catkin?)

      Quick exmaple of commands for create a workspace(just for saving you some time and headache):

      1. source /opt/ros/indigo/setup.bash This sources system-wise ROS setup file, so that the terminal can find the commands in ROS.
      2. mkdir -p ~/catkin_ws/src and cd ~/catkin_ws/src
      3. catkin_init_workspace This command creates a workspace directory call catkin_ws. (If you forgot to source, you will run in to a command-not-found error)
      4. cd ~/catkin_ws
      5. catkin_make This command will build the all the code and meta-data into executables that you can run. The underlying ROS takes care of all that. If you use C++, you will have to call this every time you made some changes in your code. Since we are using python. We don't really pay a lot attention to this.
      6. source /catkin_ws/devel/setup.bash Source the setup file in your package, so that the system can find it.

      ROS organizes the softwares into packages. All your packages will be in the src folder in your workspace.

  • Packages store all your code, data and metadat.

    cd ~/catkin_ws/src & catkin_create_pkg (WHATEVER-NAME-YOU-LIKE) rospy

    Simple as that, you made a ROS package. Congratultions, you can start coding!

  • Programming Languages

    In theory, you can code for ROS in almost any main stream languages, but most people do it in python and c++. They will be our main focus. Due to the CMake structure, there are lots of annoying details if you are working with c++. This is complicated. It's strongly recommanded to watch and follow exactly this video.
    IMAGE ALT TEXT HERE

  • Learn Python in ROS After finishing following the first tutorial, now do the same to this tutorial. After that, you will find out how much your life will be easier with python.

    IMAGE ALT TEXT HERE

  • Your friends

    Remember these are your friends:

    • rostopic list

    • rostopic info /(The_Topic_You_Want_To_Know_More)

    • rostopic echo /(The_Topic_You_Want_To_Know_More_In_Real_Time)

    • rosmsg show (The_Message_You_Want_To_Know)

    • The AMAZING community

    • GOOGLE!

      Quick exmaple of commands for create a workspace(just for saving you some time and headache):

      1. source /opt/ros/indigo/setup.bash This sources system-wise ROS setup file, so that the terminal can find the commands in ROS.
      2. mkdir -p ~/catkin_ws/src and cd ~/catkin_ws/src
      3. catkin_init_workspace This command creates a workspace directory call catkin_ws. (If you forgot to source, you will run in to a command-not-found error)
      4. cd ~/catkin_ws
      5. catkin_make This command will build the all the code and meta-data into executables that you can run. The underlying ROS takes care of all that. If you use C++, you will have to call this every time you made some changes in your code. Since we are using python. We don't really pay a lot attention to this.
      6. source /catkin_ws/devel/setup.bash Source the setup file in your package, so that the system can find it.

      ROS organizes the softwares into packages. All your packages will be in the src folder in your workspace.

  • Packages store all your code, data and metadat.

    cd ~/catkin_ws/src & catkin_create_pkg (WHATEVER-NAME-YOU-LIKE) rospy

    Simple as that, you made a ROS package. Congratultions, you can start coding!

  • Programming Languages

    In theory, you can code for ROS in almost any main stream languages, but most people do it in python and c++. They will be our main focus. Due to the CMake structure, there are lots of annoying details if you are working with c++. This is complicated. It's strongly recommanded to watch and follow exactly this video.
    IMAGE ALT TEXT HERE

  • Learn Python in ROS After finishing following the first tutorial, now do the same to this tutorial. After that, you will find out how much your life will be easier with python.

    IMAGE ALT TEXT HERE

  • Your friends

    Remember these are your friends:

    • rostopic list
    • rostopic info /(The_Topic_You_Want_To_Know_More)
    • rostopic echo /(The_Topic_You_Want_To_Know_More_In_Real_Time)
    • rosmsg show (The_Message_You_Want_To_Know)
    • The AMAZING community
    • GOOGLE!

Talk Keynote 2.5: Recipe for Scan Subscriber

  • Before getting started, you should have a workspace ready. Suppose the workspace name is /catkin_ws.
  • Recipe:
    • Initialize a package
      • $ cd /catkin_ws/src cd to the src of your workspace first.
      • $ catkin_create_pkg scan_monitor std_msgs rospy Create a new package called scan_monitor that depends on std_msgs and rospy.
    • Create your code.
      • $ cd /scan_monitor/src
      • $ gedit scan_subscriber.py
      • Copy pasted the following code.
      #!/usr/bin/env python
      # Be sure to include the shebang line!!! 
      # You should figure out what's the shebang line for your system. 
      import rospy #import the ros python package
      from sensor_msgs.msg import LaserScan #You have to import the message
      from Tkinter import *  #a Python UI library
      
      class ScanMonitor:
        def __init__(self, scan_topic):
          self.scan_topic_name = scan_topic
          
        def scanCallback(self,msg):
          print("Range array has "+str(len(msg.ranges))+" elements.")
          print("Angle Increment is "+str(msg.angle_increment))
          print(str(len(msg.ranges)*msg.angle_increment))
          #this is going to print out 
          #how many elements are there in the Range array of the message
      
        def start(self):
          root = Tk() #Bring up the UI, for now there's nothing
          rospy.Subscriber(self.scan_topic_name,LaserScan,self.scanCallback)
          #Every time you receive a new message, the scanCallback will be called. 
          root.mainloop() #This just goes into an infinite loop and stops the program from exiting. 
      
          
      def main():
        rospy.init_node('scan_monitor') 
        #The first time to do is always initialize the node.
        scan_monitor = ScanMonitor("/scan")  
        scan_monitor.start()
      
      if __name__ == '__main__':
        main()
      • We are subscribing for the scan topic and we get message type LaserScan
      • rostopic list to see all topics
      • rostopic show /scan to see the detail of scan topic
      • rosmsg show LaserScan to see the message(data structure). You can also see it online from here. For all kinds of message types, you can always just google it. You will get a well-structure wiki of this type of message.
      • save and quit.
      • $ chmod +x scan_subscriber.py This command will make your code executable. If you $ ls, you would the scan_subscriber.py is marked green. That means it became executable. Now you can $ python scan_subscriber.py to run it, but it's recommended to build this in the ROS environment.
      • $ cd to go back to the home folder. $ cd /catkin_ws/src again.
      • $ catkin_make to build. Remember you have to do it in the root of your workspace.
    • Run it!
      • $ source ~/catkin_ws/devel/setup.bash, if haven't done so. This command will enable your system to know the it can run stuffs in your workspace. You can also add this line to your bashrc file of your terminal, so that you don't need to type that every time.
      • $ roslaunch turtlebot_gazebo turtlebot_world.launch Bring up your (simulated)robot first.
      • $ roslaunch turtlebot_teleop keyboard_teleop.launch Open the controller for turtlebot. Select the window to use the controller.
      • $ rosrun scan_monitor scan_subscriber.py run it! You can call this anywhere. You will see a stream of printing on your console.
      • Now you can play with your code. Anytime you changed something, you just need to save and call rosrun.

Talk keynote 3: Navigation in ROS — SLAM, Localization, Navigation Stack

  • What is SLAM?

    Simultaneous localization and mapping (SLAM) is the computational problem of constructing or updating a map of an unknown environment while simultaneously keeping track of an agent's location within it (wikipedia).

    IMAGE ALT TEXT HERE

    IMAGE ALT TEXT HERE

    Watch two videos, they are happening the same time.

    The map is save as a pgm image file and a yaml configuration file. They are all human-readable and easy to understand. Open them and see what's going on.

    Assignment: Read chapter 9 and 10. Build and save the map of turtlebot_world in simulator. Upload the map file you made, the yaml file and a writeup of what are they. Also List all the commands you used and tell what they do.

    In ROS, the robot uses amcl package to localize itself in a map.

  • AMCL stands for Adaptive Monte Carlo localization (original paper).

    In ROS, the implementation is in a package called amcl. It basically takes all your sensor data, combines them, and tries to predict where the robot is in the map. The amcl package computes a set of poses associated with possiblity, the one with highest possiblity with be published.

  • Navigation Stack

    Navigation is usually not an easy task. The one of the reason ROS is so powerful is that the navigation functionality is came in out-of-box. In ROS, you can simply send a goal to the navigation stack(this's an action). It will plan the path and navigate the robot for you. You can do it use API or Human interface to send this goal.

    • Navigation with RVIZ IMAGE ALT TEXT HERE

    • Navigation with API

      In Real World:

      IMAGE ALT TEXT HERE

      In real world, there are far more problems than in a simulator. Small things could cause failed navigation and localization.

<<<<<<< HEAD

Talk Keynote 2.5: Recipe for Scan Subscriber

  • Before getting started, you should have a workspace ready. Suppose the workspace name is /catkin_ws.
  • Recipe:
    • Initialize a package
      • $ cd /catkin_ws/src cd to the src of your workspace first.
      • $ catkin_create_pkg scan_monitor std_msgs rospy Create a new package called scan_monitor that depends on std_msgs and rospy.
    • Create your code.
      • $ cd /scan_monitor/src
      • $ gedit scan_subscriber.py
      • Copy pasted the following code.
      #!/usr/bin/env python
      # Be sure to include the shebang line!!! 
      # You should figure out what's the shebang line for your system. 
      import rospy #import the ros python package
      from sensor_msgs.msg import LaserScan #You have to import the message
      from Tkinter import *  #a Python UI library
      
      class ScanMonitor:
        def __init__(self, scan_topic):
          self.scan_topic_name = scan_topic
          
        def scanCallback(self,msg):
          print("Range array has "+str(len(msg.ranges))+" elements.")
          print("Angle Increment is "+str(msg.angle_increment))
          print(str(len(msg.ranges)*msg.angle_increment))
          #this is going to print out 
          #how many elements are there in the Range array of the message
      
        def start(self):
          root = Tk() #Bring up the UI, for now there's nothing
          rospy.Subscriber(self.scan_topic_name,LaserScan,self.scanCallback)
          #Every time you receive a new message, the scanCallback will be called. 
          root.mainloop() #This just goes into an infinite loop and stops the program from exiting. 
      
          
      def main():
        rospy.init_node('scan_monitor') 
        #The first time to do is always initialize the node.
        scan_monitor = ScanMonitor("/scan")  
        scan_monitor.start()
      
      if __name__ == '__main__':
        main()
      • We are subscribing for the scan topic and we get message type LaserScan
      • rostopic list to see all topics
      • rostopic show /scan to see the detail of scan topic
      • rosmsg show LaserScan to see the message(data structure). You can also see it online from here. For all kinds of message types, you can always just google it. You will get a well-structure wiki of this type of message.
      • save and quit.
      • $ chmod +x scan_subscriber.py This command will make your code executable. If you $ ls, you would the scan_subscriber.py is marked green. That means it became executable. Now you can $ python scan_subscriber.py to run it, but it's recommended to build this in the ROS environment.
      • $ cd to go back to the home folder. $ cd /catkin_ws/src again.
      • $ catkin_make to build. Remember you have to do it in the root of your workspace.
    • Run it!
      • $ source ~/catkin_ws/devel/setup.bash, if haven't done so. This command will enable your system to know the it can run stuffs in your workspace. You can also add this line to your bashrc file of your terminal, so that you don't need to type that every time.
      • $ roslaunch turtlebot_gazebo turtlebot_world.launch Bring up your (simulated)robot first.
      • $ roslaunch turtlebot_teleop keyboard_teleop.launch Open the controller for turtlebot. Select the window to use the controller.
      • $ ros�run scan_monitor scan_subscriber.py run it! You can call this anywhere. You will see a stream of printing on your console.
      • Now you can �play with your code. Anytime you changed something, you just need to save and call rosrun.

ROS-MAZE Challenge

  • This challenge is designed for getting known of ROS and utilizing data from sensors.
  • Implement an algorithm that will solve the maze bellow. Your code should be able to run on both the Turtlebot3 and simulators (gazebo, stdr...).
  • The team takes the least time to solve this maze in the physical world will win.
  • This maze will built in the lab, you should test your algorithm there a lot.
  • All walls will be built by blocks which you used in mbot maze.

  • General guide:
    • Draw this map and test your code in STDR first.
    • Test well in simulator first and then deploy your code to the physical robot.
    • There is no guarantee that your code will automatically work in the real world, if your code works well in the simulator. But you will get a sense of if your algorithm and logic are right.
    • The simulated robot will behave a lot differently than the physical one. Take that into account.

Talk keynote 3: Navigation in ROS — SLAM, Localization, Navigation Stack

Join the community

  • Sign up an account and start asking question on ROS answers. The community, instead of any perticular person, always knows the answer. You will find it super useful.

Drive your simulated turtlebot around...

The very Basic: custom messages, publish & subscribe messages

Mobile Application

Mapping in Turtlebot

  • Step by Step commands:
    1. source /opt/ros/indigo/setup.bash

    2. roslaunch turtlebot_gazebo turtlebot_world.launch Open the simulator.

    3. roslaunch turtlebot_teleop keyboard_teleop.launch Open the controller for turtlebot.

    4. roslaunch turtlebot_rviz_launchers view_navigation.launch

    5. roslaunch turtlebot_gazebo gmapping_demo.launch

    6. roslaunch turtlebot_gazebo amcl_demo.launch Enable automatic navigation.

    7. rosrun map_server map_saver Save the map. map.pgm and map.yaml will be saved to disk. map.pgm can be viewed by a standard image viewer.

      rosrun map_server map_server map.yaml to reuse a safed map.


Robotics Keyword Dictionary

  • Arduino
  • Raspberry pi
  • Mbot

  • ROS

    It stands for Robot Operating System. http://www.ros.org/

  • Turtlebot

  • LIDAR

  • SLAMA* search algorithm

  • amcl AMCL stands for Adaptive Monte Carlo Localization. amcl is a probabilistic Dijkstralocalization system for a robot moving in 2D. It implements the adaptive (or KLD-sampling) Monte Carlo localization approach (as described by Dieter Fox), which uses a particle filter to track the pose of a robot against a known map.

  • Message - msg

  • Topic

  • Publish

  • Subscribe

  • roscore

  • roslaunch


Resource