Sunday, February 15, 2015

Command And Control

So first a followup: The answer to the issue I was facing with the WiFi dropping out did indeed turn out to be power related. Unfortunately I don't have an ammeter. This would be hugely beneficial at the moment. But through some trial and error I discovered that the dc-dc step up module was sucking too much juice. This meant the Pi and the WiFi dongle were starved for power. I'm actually surprised it didn't completely shut down on me. So it seems that for now I'll need to run the step up module & the motors on their own power source. I tried running the motors off of 5v and it was pretty sad how slow it ran :( Let's hope that LiPo charging board gets here soon!

Alright... On to more pressing matters. I've been mired in Android (Java) code for the past couple of days. I want to be able to control Robie by tilting my phone forward, back, left and right. It turns out this is a bit more complicated than I had initially envisioned.

I'm using the orientation sensor in the Android SDK. It says it's deprecated, but it still works in Lollipop. There are ways to work around the deprecated feature, but I'm fairly new to Android so I went with the simpler option. Use it till I lose it, right?

Orientation gives you angles of rotation. So if I have my phone flat relative to the earth I get 0 degrees of rotation for both the Z and Y axis (the ones I care about). If you tilt forward, you'll get negative numbers out of the Z axis. Tilting backwards will get you positive numbers. If you tilt left you'll get positive numbers out of the Y axis and naturally right will get you negative numbers.

So the first thing that I found was that you don't want to just map rotation numbers directly to the PWM duty cycle of the motor control. If you did, you'd have to tilt your phone 90 degrees so that the phone's screen is completely facing away from you to go full speed forward. And by extension, you don't really want the starting point to be at 0 degrees for your forward/back control. That's not a natural way to hold the phone. You probably hold your phone at something closer to -25 degrees. What's needed is a way to specify bounds. So that if you tilt your phone beyond a certain point it's not going to go any faster.



So before going further I decided to sketch out an idea of how I wanted the control mechanism to work. I came up with the drawing you see above. The thinking was that you don't want Robie moving around if your hands are at rest. So I'd include a "buffer" zone where rotation values would be ignored and simply output as 0 movement.

Then I thought wouldn't it be cool if Robie could spin in place if he's not going forward or backwards? If you're going forward and to the left for example, both wheels are moving forward but the right wheel is going to move faster than the left wheel.  If you are spinning in place then both wheels are moving at the same speed but in opposite directions.

I'm not totally convinced this will play out perfectly in practice though. Because if you're tilting back to slow down and then you cross the buffer zone all of a sudden Robie is going to suddenly start spinning. I think this might be too jarring. I don't know. I'll have to test it out to find out for sure!


Here's a teaser shot of some of the Java code. I'd share the rest but it's a horrible mess at the moment :( I promise to put up a Github link once all the basics are sorted out and she actually functions.

No comments:

Post a Comment