ros-drivers/rosserial — pull request #57 by tongtybj (2013-08-08 13:45:55+00:00)
Title: Several modification of rosserial for high speed commnunication 

Now we use arduino as the basic controller for the attitude control of quadcopter. Meanwhile, we add a on-board compact computer on the quadcopter. In this system, we use rosserial to connect the arduino and computer. However, with the convetional rossreial version, we faced several troubles about serial communication, especially under the situation of high speed data transmission.

The main problems are as follows:
1) Occurrence of Exception while reading from serial port
2) The overflow on the tx data buffer of arduino after sending SIGINT (Ctrl-c) to rosserial node
3) The duplicate registration of subscriber and publisher, while receiving TopicInfo for arduino

The first problem occurs when there are lots of routing processes within the arduino, such as the attitude controller module. We found that the process of rosserial often fell into halt, because of the exception while
calling the function of "self.port.read(x)" in the SerialClient.py. As we observed, the main exceptions were IOError
and OSError. We thought that those exceptions would occur when the resource of serial port was temporarily unavailable. As a solution we add exception handling ("try" and "exception") to ignore those temporal errors which lead to the halt of rosserial node. After all, we consider that the exception handling is fairly necessary.

The second problem occurs when we interrupt the process of rosserial by using Ctrl-c, especially under the situation that the bps of tx data form arduino is quite high. We thought that if the bps of the tx data form arduino is quite fast, it would fill out the buffer before (c_time - last_sync_receive_time) > (SYNC_SECONDS*2200). In other word, the tx data buffer will fall into overflow, before the arduino stops publishing message. As a result, the arduino will stop all of the serial communication, unless reboot the board. Because we often use Ctrl-c to stop the process, we considered that signal handler is necessary. Put it concretely, we add an additional process which will send tx stop request to arduino after the node of rosserial receives SIGINT. At the side of arduino, the tx stop request can stop the arduino publishing data. To realize this point, we add the id of ID_TX_STOP to TopicInfo.msg.

The third problem occurs when the node of rosserial receives the response of self.requestTopics() from arduino for several times. The duplicate registration of publisher will lead to the multiple publishing of message from rosserial node to arduino, which is undesirable. Therefore, we add simple conditional expression before registraion. That is, if the publisher / subscriber has been already added to the lists.

Although most of those modifications are unrefined, they lead to the achievement of the high speed communication between arduino and computer. We hope those modification will help.