Serial communication between the Ranger and Java


#1

I just uploaded the latest version of my serial communications library to Github. With this Java library, you are able to communicate with the Ranger from a Java application on your PC. That was my test setup at least, since I only have a ranger to test with.

The library contains an example RunClient application to display how it works. It also contains an mBlock save file written on mBlock 3.

Currently, I have been able to play sounds, controll the onboard LEDs, move, and read the light sensor. I have even been able to poll the light sensor once per second and, based on the current light intensity, turn the onboard LED’s on or off as a sort of automated light switch.

Since all this works equally well with the serial cable as it does with the bluetooth dongle, this could be used to setup some sort of network with a PC as the main hub controlling everything.

The only drawback as off now is the interval between the commands send to the ranger. 1 second intervals work great, 10 ms, not so much. With too short an interval, injecting ad-hoc commands based on sensor readings becomes impossible.

You can find the library here:

I’ll probably be looking into some sort of command queue so injecting ad-hoc commands works better, and the whole thing is less dependent on a timer between commands.


#2

What speed is your serial connection?


#3

I have currently intriduced a forced 1 second delay betwee the sending of commands. But this is mainly because I have two seperate threads both sending commands on the same connection.
My plan is to spend some more time on the client and rewrite it so a single thread handles the sending of commands and a second thread handles the receiving of commands.
I have built such a setup before for socket communication, so it shouldn’t be too hard to convert that code to work here as well.
Depending on how much time I get to spend on this over the coming week, I should have something workable, with a higher throughput, by the end of the week.


#4

Major ugrade to the library. It now supports full multithreading soe the sending is done on its own thread. This made it possible to greatly increase throughput speed.

There is still a limitation there, but that’s because the speed with which you can send messages is linked to the interval with which the robot reads the messages. Currently, I have the robot read every 0.2 seconds, and the Java application sends every 0.4 seconds. That seems to work just fine.

I also updated the documentation significantly, so everything should be a lot clearer now.