Jump to content

Embedded control systems/Experiences/Roomba

From Wikiversity

Introduction of this page, small explanation of lay out and content. Maybe split over several pages.

Hardware setup

[edit | edit source]

The robotic setup consists of :

  1. The iRobot Roomba 620
    Thanks to the publications of the Open Interface Specifications, we have the commands needed to have access to the actuators and sensors of the Roomba.
  2. The RoboPeakLidar
    Detailed information and software created by the developers can be found on the official website.
  3. Raspberry Pi 1 Model B+ with 8GB SD card
    Communication between external PC, Roomba and Lidar
  4. TPLink Rooter
    For a local Wi-Fi Network, easy management of static IP's for each Pi

Software setup

[edit | edit source]

Introduction

[edit | edit source]

The software needed for the communication between the PC, Raspberry Pi, Robot Roomba and RoboPeakLidar will be presented here.

Files and directory’s used on Pi

[edit | edit source]
  • ~/server/udp_receive.py Communication between the computer and Roomba. No input required , because by using manufacturer information, the pi assigns automatically /dev/roomba when it is connected. A lot of information is given to the user by executing it in the terminal and showing the prinf’s.
  • ~/server/udp_lidar.py Communication between the computer and Lidar. No input required, because by using manufacturer information, the pi assigns automatically /dev/rplidar when it is connected. A lot of information is given to the user by executing it in the terminal and showing the prinf’s.
  • ~/RPLidarPi/Debug/RPLidarPi This is the C++ folder and executable, which needs as input /dev/rplidar. This file is launched automatically by udp_lidar.py..
  • crontab The crontab is used to execute a set of scripts at startup of the Pi. The crontab can be accessed with:
    sudo crontab -e
    
[edit | edit source]

The Pi is used as a simple repeater. The correct sequence f bytes is made by a MATLAB toolbox, based on the Open Interface Specifications. The Pi knows when it has to merely repeat the bytes to the Roomba or when it has to read the serial port to send information back to the user (sensor measurements). By using manufacturer information, the pi assigns automatically /dev/roomba when it is connected. At this moment, all bytes have to be converted to strings to be send over UDP (Python2). Also, incoming data has to be converted from strings to bytes.

In order to be more efficient, Python3 could be used to be able to send bytes over UDP (this will be much more efficient !). Also, using only the MATLAB udp communication could also speed up the process.

[edit | edit source]

The Lidar is controlled by a C++ program, which transfers the measurement data over UDP to the local host on port 7070 (the raspberry pi) and then, to the PC on port 7070. This is done by the python program ~/server/udp_lidar.py. The PC has to send the start byte 201 to the Pi before receiving any Lidar data. This, so that the Pi know the IP of the client.

C++ program quick start

[edit | edit source]

In case you need to change something in the C++ code, here are the steps needed to compile a working executable for the Pi, using Eclipse. Skip this part if you don’t need to change anything to the existent code.

Settings for Eclipse
[edit | edit source]
  1. Install Eclipse
  2. Unzip C++ code (RPLidar.zip)
  3. Create a C++ project in Eclipse
  4. Drag the unzipped files in the project
  5. Add the necessary paths in eclipse.
    • right click project
    • C/C++ build
    • Settings
      • GCC C++
        • Include, add the following paths (click on workspace, add graphically)
          • sdk/include
          • sdk/src
          • skd/src/arch
          • sdk/src/hal
  6. Add the necessary libraries :
    • right click projec
    • C/CC++ build
    • Settings
      • GCC C++
        • Linker libraries
          • pthread
  7. Build
  8. Left click on arrow next to run
    • Run configurations
    • new launch configurations
    • Arguments '/dev/rplidar'
Cross compiling
[edit | edit source]

By following the link, or the CrossComple.pdf, you will learn how to cross compile a C++ program for the Raspberry Pi on a regular PC.

Increase Pi output current

[edit | edit source]

In order to get currect measurements (not datasend=0), a small change has to be made in the config file of the boot partition of the pi. in /boot/config.txt (solution found on this link) : max_usb_current=1 (last line)

Problem solving guide

[edit | edit source]

Introduction

[edit | edit source]

Here are described some systematic steps to analyse and identify where the problem In the communication between your computer, Pi, Roomba and Lidar. Numbers indicate the steps to be followed sequentially. Bullet points indicate the steps to take if there is a problem. All text written in a code block represents the input you need to type in the command line of your Linux computer.

Before anything else

[edit | edit source]
  1. A ssh connection is required to the Pi. In order to do this, please follow Pi Communication.
  2. One major problem of this robotic platform, is due to the malfunction of the Roomba when it hits a low battery level. Typical problems, in order of decreasing battery level are :
    • Actuator power decreases
    • Sensor data becomes unreliable (especially the encoders, but after also tactical sensors)
    • Pi can get power, but can’t make any connection with the Roomba

Checking communication with the Pi

[edit | edit source]
  1. Check connection with pi Where # is the number of your Roomba
    ping 192.168.1.10#
    
    If you don't receive a response time of your ping :
    • Are you connected to Wifi_Roomba ?
    • Is the Pi connected to Wifi_Roomba ?
      • Connect Pi to a screen, reboot and watch booting sequence.
      • If Kernel Panic occurs, you will have to rewrite the SD card, with the backup
      • If you arrive at the login, login: pi, password: pi
      • Check your IP address by
        ifconfig
        
        If you have a valid IP address, but it is not ending by the correct #, please contact a Teaching Assistant, and tell him that the static IP address has changed. This could be due to a change of MAC address of the Wi-Fi module (= is not the original Wi-Fi module). In the current implementation, it is the Rooter who manages the static IP addresses by checking the MAC addresses of each Wi-Fi module/dogle connected to the pi.
      • If you don't see any valid IP address under wlan0 try
        wicd-curses
        
    • Follow the instructions on the interface and try to connect to Wifi_Roomba
  1. Connect via ssh to the pi to gain access to the terminal. Password is pi. Now that your are connected to the pi, we can start debugging the other problems, where # is the number of the Roomba.
    ssh pi@192.168.1.10#
    

Checking communication with the Roomba

[edit | edit source]
  1. Once you're are connected via the Pi kill any processes that could interfere with the debugging :
    ps aux | grep udp
    
    This will show all the programs that contains "udp". You will have to kill the program "udp_receive" with the correct "process id" (4 numbers normally) at the start of the display generated by the entered command.
    sudo kill ####
    
  2. Go to the server directory, in order to execute the udp_roomba and to get feedback of the running python program
    cd server/
    python udp_receive
    
  3. Now, the Roomba will beep and go in full modus (buttons on the Roomba won't work).
    • If this doesn't work, the chances are high that the Roomba has a low battery level (see Before anything else)
  4. Send the commands to the Roomba with your MATLAB script. Normally you will see :
    DATA RECEIVED = [#########]
    DATA SEND     = [#########]
    
    • If data send = [], the Pi hasn't received any information from the Roomba, this will usually mean that the Roomba has a low battery level.
    • If data send is not in a correct space, incoherent data bytes (cfr. Open Interface Specifications), this will usually mean that the Roomba has a low battery level.
    • If Data send is what you expect, but you don?t receive it on your PC then :
      • Go to the server folder of the RoombaCommunicationToolbox
      • In getDataUDP, display the string data you get by displaying it. If this is good, this means something is going wrong in the conversion to bytes.

Checking communication with the Lidar

[edit | edit source]
  1. Once you're are connected via the Pi kill any processes that could interfere with the debugging :
    ps aux | grep lidar
    
    This will show all the programs that contains "lidar". You will have to kill the program "udp_lidar" and "RPLidarPi/Debug/./RPLidarPi" with the correct "process id" (4 numbers normally) at the start. Having multiple instances of the latter one (c++ code for the lidar communication) will definitely make your program crash.
    sudo kill ####
    sudo kill ####
    
  2. Go to the server directory, in order to execute the udp_lidar and to get feedback of the running python program and follow the instructions / information on the screen.
    cd server/
    python udp_receive
    
  3. First, the code waits for the start signal 201 on port 7071. By sending this code, the program will start and now the IP address of the client
  4. Now, the python code will run the C++ program, which will also display some information.
    • If segmentation error occurs,  kill all programs as described in step 1 and execute program again in step 2. This will normally solve the problem
    • If the output of the C++ program that controls the lidar displays "data send = 0" Change the output current of the Pi by modifying /boot/config.txt and putting max_usb_current=1 (last line) (solution found on this link) :

Back up and copy a SD-cart to "clone" the Pi

[edit | edit source]

To be more flexible, we will back up the root and the boot partition separately.

  1. Identify the location of the sd cart. Partition name will be boot(1) and root(2).
    df -h
    
  2. Backup up boot (* the letter you found in step 1, b if you have one partition on your computer). Take a short time (seconds). This will make boot.iso in home folder. If is input file, of is output file, order is NOT important.
    sudo dd if=/dev/dev/sd*1 of=~boot.iso
    
  3. Backup up root (* the letter you found in step 1, b if you have one partition on your computer). Takes up to 30min. This will make root.iso in home folder
    sudo dd if=/dev/dev/sd*2 of=~root.iso
    
  4. Copy to clean sd. Small preparation in Gparted (gui for partition manager). Make a first partition on 100MB formatted to fat16. Rest is ext4. Make sure the size of your root.iso is smaller as this second partition. If this is not the case, use Gparted to shrink the original SD cart, and repeat step 3. Copying root.iso can take up to 30min
    sudo dd of=/dev/dev/sd*1 if=~boot.iso bs=4M
    sudo dd of=/dev/dev/sd*2 if=~root.iso bs=4M
    
    If your SD cart doesn't work (kernel panic), don't use the bs=4M, but much slower copying (up to one hour).

MISC: Useful command codes

[edit | edit source]

Listen to port #### :

netcat -ul ####

Secure copy : copying folders and file over the same network

scp -r path/to/your/directory/you/want/to/copy username@ipadress:/path/to/the/dir/you/want/to/put/your/folder