Embedded control systems/Experiences/Roomba

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

Hardware setup
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

Introduction
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

 * ~/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:

Software related to the Roomba
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.

Software related to the Lidar
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
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

 * 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.
 * 6) * right click project
 * 7) * C/C++ build
 * 8) * Settings
 * 9) ** GCC C++
 * 10) *** Include, add the following paths (click on workspace, add graphically)
 * 11) **** sdk/include
 * 12) **** sdk/src
 * 13) **** skd/src/arch
 * 14) **** sdk/src/hal
 * 15) Add the necessary libraries :
 * 16) * right click projec
 * 17) * C/CC++ build
 * 18) * Settings
 * 19) ** GCC C++
 * 20) *** Linker libraries
 * 21) **** pthread
 * 22) Build
 * 23) Left click on arrow next to run
 * 24) * Run configurations
 * 25) * new launch configurations
 * 26) * Arguments '/dev/rplidar'

Cross compiling
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
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)

Introduction
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

 * 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 :
 * 3) *Actuator power decreases
 * 4) *Sensor data becomes unreliable (especially the encoders, but after also tactical sensors)
 * 5) *Pi can get power, but can’t make any connection with the Roomba

Checking communication with the Pi

 * 1) Check connection with pi Where # is the number of your Roomba If you don't receive a response time of your ping :
 * 2) *Are you connected to Wifi_Roomba ?
 * 3) *Is the Pi connected to Wifi_Roomba ?
 * 4) **Connect Pi to a screen, reboot and watch booting sequence.
 * 5) **If Kernel Panic occurs, you will have to rewrite the SD card, with the backup
 * 6) **If you arrive at the login, login: pi, password: pi
 * 7) **Check your IP address by 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.
 * 8) **If you don't see any valid IP address under wlan0 try


 * 1) *Follow the instructions on the interface and try to connect to Wifi_Roomba
 * 2) 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.

Checking communication with the Roomba

 * 1) Once you're are connected via the Pi kill any processes that could interfere with the debugging : 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.
 * 2) Go to the server directory, in order to execute the udp_roomba and to get feedback of the running python program
 * 3) Now, the Roomba will beep and go in full modus (buttons on the Roomba won't work).
 * 4) * If this doesn't work, the chances are high that the Roomba has a low battery level (see Before anything else)
 * 5) Send the commands to the Roomba with your MATLAB script. Normally you will see :
 * 6) * 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.
 * 7) * 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.
 * 8) * If Data send is what you expect, but you don?t receive it on your PC then :
 * 9) ** Go to the server folder of the RoombaCommunicationToolbox
 * 10) ** 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

 * 1) Once you're are connected via the Pi kill any processes that could interfere with the debugging : 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.
 * 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.
 * 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.
 * 5) * 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
 * 6) * 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
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).
 * 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.
 * 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
 * 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 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
Listen to port #### : Secure copy : copying folders and file over the same network