Raspberry Pi Overview

The Raspberry Pi subsystem is responsible for inter-communication among Algorithm, Android and Adruino subsystems. It processes and relays messages, including commands and readings from and to different subsystems. In addition, it also performs processing, recognizing and locating images in the maze as the robot traverses through the maze. 

Raspberry Pi set up and configuration


Raspberry Pi set up is initially through Raspbian Software with the command-line tool. After the remote SSH is set up and accessible, RPi is accessed with a remote SSH client and the following will be configured:

  1. Setting up the RPi as a Wifi hotspot, which acts as an access point by enabling the WiFi interface and configuring the IP address, which is necessary for communication with the PC. After a DHCP server is installed and configured, the RPi can be used as a gateway to the Internet for easier development.
  2. Setting up the Bluetooth on RPi using the “hcitool” command to establish a Bluetooth connection with the Android Tablet. Autoconnection also needs to be implemented for faster and easier communication with the Android team.
  3. Setting up the USB interface between RPi and Arduino board through their respective USB ports. The USB port assembles a serial port based on ACM (Abstract Control Model) serial interface which is supported by Raspbian. Since the interface file (/dev/tty/ACM0) is automatically created in the RPi upon connection, no further configuration is needed for functional communication between the Arduino board and RPi.

Inter-communication between subsystems


Communications with different subsystems are established using different protocols, namely, wireless Internet Protocol (IP) with Algorithm Subsystem, ACM (serial) Protocol with Arduino, and RFCOMM Bluetooth wireless with Android Subsystem.

Parameters

Parameters defined for communication protocols include WiFi IP address and port number for PC server, N7 Mac Address and UUID for Bluetooth Server and Baud rate and SER_PORT0 and SER_PORT1 for Arduino connection.

WIFI_IP = “192.168.16.16”
WIFI_PORT = 9123

BAUD = 115200
SER_PORT0 = “/dev/ttyACM0”
SER_PORT1 = “/dev/ttyACM1”

N7_MAC = “68:B3:5E:58:97:4F”
UUID= “00001101-0000-1000-8000-00805F9B34FB”

 

Communication with PC

 

Communication with Arduino

 

Communication with Android

 

Communication with image recognition

 

Integrator Code Example

The integrator (RpiMain.py) is implemented using multithreading using the thread library in python. Three readthreads are created with one for each terminal to read the message from the other two terminals. Upon successful connection with all three terminals, the integrator will be able to run three thread simultaneously which allows inter-communication between PC, Android, and Arduino.

 

import _thread
import os

from ArduinoV3 import *
from PCV3 import *
from AndroidV3 import *


class Main:
   def __init__(self):
      os.system("sudo hciconfig hci0 piscan")
      print("Please wait...")
      self.arduino = ArduinoV3()
      self.pc = PCV3()
      self.android = AndroidV3()

   def test(self):
      #        self.pc.connectImg()

      while True:
         if self.arduino.connected == False:
            result = self.arduino.connect()

            if (result == 0):
               continue

            try:
               _thread.start_new_thread(self.arduino.readThread, (self.pc, self.android))
               print("Arduino thread started.")
            except Exception as e:
               print("Arduino threading error: %s" % str(e))

         if self.pc.connected == False:
            self.pc.connect()

            if self.pc.connected == True:
               try:
                  _thread.start_new_thread(self.pc.readThread, (self.arduino, self.android))
                  print("PC thread started.")
               except Exception as e:
                  print("PC threading error: %s" % str(e))

         if self.android.connected == False:
            self.android.connect()

            if self.android.connected == True:
               try:
                  _thread.start_new_thread(self.android.readThread, (self.arduino, self.pc))
                  print("Android thread started.")
               except Exception as e:
                  print("Android threading error: %s" % str(e))

   def disconnectAll(self):
      try:
         self.android.disconnect()
         self.pc.disconnect()
      except:
         pass


if __name__ == "__main__":
   a = Main()

   try:
      a.test()
   except KeyboardInterrupt:
      print("Terminating program...")
      a.disconnectAll()

Image Recognition