Saturday, May 4, 2013

Communication over Sockets


The android application communicates with the robot over TCP and UDP sockets. There are three main sockets on the android application side which are all clients to the servers created on the robot.
The three sockets are used for:
  • TCP Socket for the Video Stream: This socket connects to the TCP server which is hosting the video stream. The TCP socket connects to the server over the PORT:5000 . The video stream is transmitted over this socket connection.
  • UDP Socket for the sending the control data from the application to the robot: The UDP socket is used to send the accelerometer data as well as the slider input to the robot. The UDP socket was chosen so that the there is no delay in the transmission of the control signals from the application to the robot. The same socket is also used to send the ping sensor distance readings to the android application. The application receives the ping data over the this socket and it displays the data on the User Interface.
  • TCP Socket for Commands: This third socket is used to send start and stop signals to the robot. The start signal is encoded as hex byte 0x02. When the robot receives this signal it opens the UDP port and starts listening for control data from the application and also starts transmitting the ping distance. The hex byte 0x01 is used to inform the robot to stop. The table given below shows messages and their corresponding codes:
    Commands Code
    Start 0x02
    Stop 0x01
    Ping Enable 0x50
    Ping Disable 0x51
    Stop at 10cm 0x0A
    Stop at 15cm 0x0F
    Stop at 20cm 0x14
    Stop at 30cm 0x1E
    Stop at 40cm 0x28


No comments:

Post a Comment