Now that I have a working program for the camera, I decided to start working on the robot control.
First of all, I installed the NXT Fantom driver found on LEGO’s website [source]. Then, I installed LeJOS NXJ and flashed my robot with LeJOS NXJ firmware flasher [source]. Finally, I configured my Eclipse to allow it to compile my programs directly on the robot thanks to the step four of this tutorial [source].
Now that I had a working development environment, I implemented the Bluetooth connection function coded by Severin Fichtl : a function that is simply waiting for a Bluetooth connection and display its state on the robot’s screen.
That’s all for today! The next step will be to code an Android application that communicates with the robot over Bluetooth.
As I was not really happy of my first design because it was quite weak and not adapted to the HTC Android, I did some research on internet to find a better design to build. I finally found was looking for : a 3 wheels car chassis to have a well design chassis to build the telephone holder on [source].
So here are the photos of the new robot 3D model and the final implementation in real life.
Because I have already coded a a great part of the project, I am thinking that I could perhaps write a android version of JCSP : a version of JCSP that would contain some libraries that gives a parallel access to the camera and to the GUI of the phone with active graphical components (the one provided by JCSP won’t work because they are based on AWT).
By doing this, I would be able to code the phone’s applications the parallel way. This is just an idea that I could perhaps try to implement if I finish my project too early.
I am now working on the little picto that indicates the transfer status between the three states of the connection.
Something that I thought would take a couple of minutes finally took me 5 hours!
First of all, to make the code as clean as possible, I implemented a onChange event in the ServerSocket class [source].
Then, in the TransferStatusChangeListener, I simply called the transfer status ImageView component. And I got a really unexpected exception : “CalledFromWrongThreadException : Only the original thread that created a view hierarchy can touch its views”. Which means that you cannot edit a UI component if you are not in the main Thread.
I have searched for hours for a solution on Google because everyone was leading me the wrong way : On all the forums, I was told to use AsyncTask to solve my problem but this class was really not appropriated to my problem : AsyncTask allows to have access to a thread from an other one but can only be called once and have to be created from the class we want to access.
I finally found the solution in the Activity reference [source] : runOnUiThread that allows any thread to access the UI at any moment as long as we have a reference of the main Activity.
I realize that the reason why I have a very low frame-rate is because I am sending the images in their original format (5 megapixels), so It is really heavy to send over Wi-Fi. The problem is that the only function that is supposed to control the size of the image doesn’t work with my Callback function.
So I now really believe that I am working on a very buggy version of Android. So I am starting to look for a way to upgrade my phone to a higher version of Android, and unfortunately, even if an upgrade to Android 2.1 is available on HTC’s website, I cannot install it on my HTC Hero because I got it from Orange and so I have to wait for them to release the upgrade… And the problem is that, they are quite slow for this kind of things… So instead of waiting for a couple of month for the upgrade to be released, I decided to debrand it following this french tutorial [source]. As predicted, as soon as my phone got debreanded, I received the 2.1 upgrade.
Now that I have Android 2.1, I decided to get back to the preview callback method instead of the take picture that requires a loop that triggers the picture shot. And as predicted, my application doesn’t work anymore. Two problems that I had to solve :
– The preview size cannot be a custom size, it has to be one of the sizes given by getPossiblePreviewSize(). Which are for the HTC Hero :
- width:1280, height:720
- width:800, height:480
- width:720, height:480
- width:640, height:480
- width:576, height:432
- width:480, height:320
- width:400, height:240
- width:384, height:288
- width:352, height:288
- width:320, height:240
- width:272, height:272
- width:240, height:240
- width:240, height:160
- width:176, height:144
– The preview container has to be the exact same as the one set with setPreviewSize()
And it’s a success : As predicted, the setPreviewSize() bug is fixed on Android 2.1 and I now have a frame rate of a little bit bigger than 1 image/sec.