Friday, February 20, 2015

And Now For Something Completely Different

Alright. My Android code is cleaned up enough to share with the masses. So here's the github link:

https://github.com/meatheadmike/robie_rover_android

Please don't judge me too harshly. This is literally my first ever Android project. So there's lots that could/should be improved/revised.

Here's what it looks like once compiled and installed on my Cyanogenmod 12 Lollipop-toting Samsung Galaxy S5:


As you can see the real-time video feed is in the center of the screen. This code was mostly pilfered from the simplemjpegview project. No sense in reinventing the wheel, right? The code I worked on was the control code.

The text in the upper left-hand corner of the screen shows the value we're sending to each of the motors. It will be in the range of -100 to 100 for either side and is interpreted as a duty cycle percentage to send to the Pi.

The navigation communication happens over UDP. Because it's UDP it's got less latency than TCP. We don't have to wait for acknowledgements or anything like that. But it's also less reliable. That's ok for motor speed control because we're flooding the Pi with speed data. If one or two packets don't make it through nobody will notice. You'll note though that when the app pauses or exits I make sure to send 3 stop requests to the Pi (see the RoverLoop/run function here). It would really suck if Robie kept moving when the app shut down! I suppose this still could happen in a force-close or system reboot situation though.

There are currently 2 buttons on the main interface. The spin button on the right currently does nothing. But I'll eventually make it so that it can spin in place (i.e. the left and right wheels move in opposite directions). The rove button basically turns on and off the motors. We default to off so that Robie doesn't immediately spring to life the second the app opens. That could be a bit awkward.

There are probably a few things I'll like to add in the future. First off will be that spin button that I mentioned. But I'd also like to have a mode selector. Since I'm going to have one on Robie as well, this means that I'll need some way of sending data from Robie to the phone so they can sync up. This either means I need to set up a UDP server on the phone or switch to TCP for the communications. Either approach has pluses and minuses. So I'll have to mull it over a bit before I move down that path. For now I have a functional bot.

No comments:

Post a Comment