NXT-Spy – More thoughts about JCSPae

Because I really want this project to be fully CSP-coded project, I looked deeper in how I could code an Android version of JCSP. So I analised what needed to be modified :

– First of all, the Android programing template is completely different : instead of calling a  “main” function, we are calling an “Activity” that loads the application and reads the manifest file. From this class, we can call the method onCreate that is triggered when the app is created to execute any code. It will probably be in this method that I am going to work in to launch my parallel process.
– Then, as I had already noticed in this post one month ago, there is not AWT on Android, so I will have to code my own “active components” based on android’s graphical components located in the package android.widget of Android’s API.

NXT-Spy – Better frame-rate for the camera app.

Today, I came back to the camera app because I really wanted to have a better frame rate than the current 1/sec.
So first of all I tried to find which process is guilty for this low rate, the most obvious one was the heavy decodeYUV function that is ran before sending the current frame from the phone.
So to fix this problem, I decided to send the raw YUV image to the computer which will then decode it as a RGB image.

The main problem I faced while doing this was to convert the RGB int array to a RGB BufferedImage [source].
I now have a way more acceptable frame-rate of something like 3/sec. I will also soon probably code a timer to know exactly the frame-rate I am currently at in order to enhance it still more.

Here is a video showing the current frame rate I have obtained:
[yframe url=’http://www.youtube.com/watch?v=148Qd3x6IeQ’]

NXT-Spy – The robot control from the phone works!!

It is 2am but I did it!

Motivated by this afternoon’s success, I decided to work on the control of the motors in parallel using Jon Kerridge’s JCSPre. As I had worked on it last year, I coded a little program that controlled the robot with the robot’s 4 buttons quite quickly. This achievement done, I really thought that it would be silly to stop there for today, so I decided to put the hole thing together and control the robot in real time from the phone.

Because I didn’t want to do a GUI on Android’s horrible XML-style interface, I thought that it would be easier to use the phone’s trackball to control the robot. Surprinsigly it didn’t take me that long to code this part of the project because I already studied and experimented most of its components :

  • A working JCSPre-ready robot
  • A working Bluetooth connection between the phone and the robot
  • The possibility to send orders to the motors in real time from the robot.
  • A lot of training on Java sockets, Threads and Android’s framework (all the time I spent on the Camera part of the project)

So finally, here is how it works :

  • First, of all, I initialize the Bluetooth connection between the two devices
  • Then, the phone is sending requests to the robot continuously with the desired speed for both motors (a thread is calculating the speed of the robot from the trackball values) in the format “{leftMotorSpeed}A{rightMotorSpeed}” (I used an “A” as separator because I am using the function writeUTF and I didn’t want to have any troubles with UTF encoding of special characters).
  • So the robot meanwhile is reading continuously the phone’s requests, it splits and converts the string in order to retrieve the desired speeds for each motors as integers. And finally writes the values to each motors.

And that’s it and it works quite better as I thought, because I am really proud of today’s fantastic advances on the project, I did a little video to show how well it works.

[yframe url=’http://www.youtube.com/watch?v=_VrLqfqWhlg’]

NXT-Spy – First successful connection between the phone and the robot

After a lot of work and research on how to send and receive data over Bluetooth on Android and LeJOS, I finally managed to send a “Hello robot” message from the phone to the robot.

The main problem was that the LeJOS’s PC API is not compatible with Android (it is based on Bluecove). To solve this problem, I took a look at the few examples available on Android’s website to understand how to initiate a Bluetooth connection with an other Bluetooth equipment [source]. But event if these examples helped me to start coding my Android application, it also lead me to a lot of problems as the examples only involved Android to Android communications so it did not work with my situation.

So now I had the phone and the NXT brick ready to communicate with both Bluetooth socket initiated and ready but, for a really mysterious reason, they could not communicate. I finally found the answer on Google [source] : the problem was that my UUID was not right (only adapted for Android to Android communication).

Now that I made the connection between the two devices, it was time to send data… An easy task I thought, but actually not at all : To begin, I decided to send an integer. So the android sent a random number to its output stream, I told the NXT brick to read and display it and the brick just stopped, throwing an exception on the DataInputStream.readInt() function. After several hours of little tweaks on both devices, it happened that I just could not manage to send my number.

So, in a final desperate burst of motivation, I finally tried to send a string and it worked !

To conclude I still don’t know why a string sent with DataOutputStream.writeInt and received with DataInputStream readInt is throwing exceptions but with a string sent with DataOutputStream.writeUTF and received with DataInputStream.read function, it works perfectly.