Skip to content

Gibbot User Interface Communication v1

mjc401 edited this page Jul 30, 2014 · 25 revisions

Communication Method

To communication between the robot and a PC, XBee wireless communication is being used. One XBee is connected to the PC being used for the user interface, while the second XBee is attached to the primary control board inside the robot. Currently, the baud rate being used for this communication is 115,200 bps; however, it should be noted that this speed for the XBee is really 111,111 bps.

Communication Protocol

As of \today, the current protocol involves sending a command to the robot to initiate the data transfer. In the code at present this character is 'q'. Once the robot receives this command, it will request all the data (encoder values, current, IMU data, etc.) and convert all of them from counts to their real-world value (i.e. angles (degrees), angular accelerations (degrees/s), linear accelearation (g), etc.).

Converting the values on the dsPIC as opposed to the PC as the benefit that if the resolution of any of the sensors is changed, the data received by the PC will already be updated to these changes; whereas, if the data is converted on the PC, changing sensor resolution on the board will result in changing code on the PC.

Another benefit is that if the robot is not moving, some of the data, such as the encoder values and others, are not going to be changing, thusly the time between updates can be slowed down if wanted during these idle times and then sped back up during active times.

String Format

After converting all the data to their real-world values, the data was then made into a string using the sprintf command. After this was completed, the data was sent over the XBee link using the printf command. The main benefit of this format is that when the data is received, no typecasting or conversion is necessary as all the data is human-readable.

Information about the data sent can be found in Table \ref{tab:string_sensor}, where the first entry corresponds to the first data value sent out.

\begin{table}[h] \centering \begin{tabular}{|l|l|l|} \hline Sensor Data & \textbf{\large{Units}} & \textbf{\large{Data Type}} \ \hline Lower Magnet Angle & \textdegree & %i \ \hline Motor Angle & \textdegree & %i \ \hline Top Magnet Angle & \textdegree & %i \ \hline Motor Current & A & %05.2f \ \hline Motor Torque & mNm & %05.2f \ \hline Motor Temperature & \textdegree~C & %5.2f \ \hline Battery Voltage & V (or percentage) & %4.2f \ \hline Accelerometer-X (Primary) & g & %5.4f \ \hline Accelerometer-Y (Primary) & g & %5.4f \ \hline Accelerometer-Z (Primary) & g & %5.4f \ \hline Gyroscope-X (Primary) & \textdegree/s & %5.4f \ \hline Gyroscope-Y (Primary) & \textdegree/s & %5.4f \ \hline Gyroscope-Z (Primary) & \textdegree/s & %5.4f \ \hline Accelerometer-X (Secondary) & g & %5.4f \ \hline Accelerometer-Y (Secondary) & g & %5.4f \ \hline Accelerometer-Z (Secondary) & g & %5.4f \ \hline Gyroscope-X (Secondary) & \textdegree/s & %5.4f \ \hline Gyroscope-Y (Secondary) & \textdegree/s & %5.4f \ \hline Gyroscope-Z (Secondary) & \textdegree/s & %5.4f \ \hline \end{tabular} \caption{Sensor Data for String Format} \label{tab:string_sensor} \end{table}

Although this method works and has its benefits, there are some problems with sending all the data out in a string. The main issue has to deal with the speed of sending. Once the dsPIC receives the command to start the data transfer until completion was timed at about 60 ms. This corresponds to roughly 16Hz if it was constantly streaming out data. This is much slower than the 30Hz update rate desired for the user interface GUI.

After timing different functions during the data transfer, it was discovered that the primary culprit for the slow speed was the sprintf function, which took about 33-40 ms with printf taking 11 ms. To increase the data transfer speed and meet the 30Hz goal, the string format was abandoned and replaced with a data stream format discussed more in Section \ref{sec:datastream}.

Data Stream Format

In the data stream format, the functions sprintf and printf are no longer used as they slowed down the data transfer rate to a speed below the desired 30Hz update rate. Instead, a struct was used. After converting all the counts to their corresponding real-world values, they are put into a struct, before the whole struct is sent out in a stream of characters.

Information about how the data is sent out in the data stream format can be seen in Table \ref{tab:datastream}, where the first entry corresponds to the first data value sent out.

\begin{table}[h] \centering \begin{tabular}{|l|l|l|l|} \hline \textbf{\large{Sensor Data}} & \textbf{\large{Units}} & \textbf{\large{Data Type}} & \textbf{\large{# of Bytes}} \ \hline Lower Magnet Angle & \textdegree & int & 2 \ \hline Motor Angle & \textdegree & int & 2 \ \hline Top Magnet Angle & \textdegree & int & 2 \ \hline Motor Current & A & float & 4 \ \hline Motor Torque & mNm & float & 4 \ \hline Motor Temperature & \textdegree~C & float & 4 \ \hline Battery Voltage & V (or percentage) & float & 4 \ \hline Accelerometer-X (Primary) & g & float & 4 \ \hline Accelerometer-Y (Primary) & g & float & 4 \ \hline Accelerometer-Z (Primary) & g & float & 4 \ \hline Gyroscope-X (Primary) & \textdegree/s & float & 4 \ \hline Gyroscope-Y (Primary) & \textdegree/s & float & 4 \ \hline Gyroscope-Z (Primary) & \textdegree/s & float & 4 \ \hline Accelerometer-X (Secondary) & g & float & 4 \ \hline Accelerometer-Y (Secondary) & g & float & 4 \ \hline Accelerometer-Z (Secondary) & g & float & 4 \ \hline Gyroscope-X (Secondary) & \textdegree/s & float & 4 \ \hline Gyroscope-Y (Secondary) & \textdegree/s & float & 4 \ \hline Gyroscope-Z (Secondary) & \textdegree/s & float & 4 \ \hline \textbf{Total} & & & \textbf{70} \ \hline \end{tabular} \caption{Sensor Data for Data Stream} \label{tab:datastream} \end{table}

Although the data received is no longer human-readable, there is a huge improvement as to the data transfer speed. The total time from when the start transfer command was received until completion was only 10 ms as compared to 60 ms when the string format was utilized. This would allow for 100Hz if constantly streaming, thus meeting the 30Hz goal and allowing additional time for sending the command over. \label{sec:datastream}

\end{document}