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’]

Leave a Reply

Your email address will not be published. Required fields are marked *