No, I'm not an antisocial, misanthropic individual.
I just have a fascination with the physics of flinging small bits of plastic in a controlled fashion.

Wednesday, April 11, 2007

Trackin fool

Refactoring to allow for testing is sooooo a good thing.

I finally had the brainstorm. I'd been developing two separate projects for this. One is down-n-dirty, get 'er in. Test it out. Oops..that's ugly but it works.

And one "nice, pristine, how it's supposed-to-be".

I'll let you guess which one actually made progress. For a while.

The pretty one was essentially used as a testing ground for nunit. And therefore has a nice bunch of unit tests.

And then it happened in the "real" project. Ka-blam. Hit a wall. Why isn't this working?!! It should work. The logic is right. Those d!$#m gremlins are getting in between the parsing and compiling stages. I just know it.

Deep breath. Back off. Put the mouse down. Take a walk.

Then it hits me. I'm having so much trouble (partially) because I'm having to do so much crufty liberal insertion of system.diagnostic.debug.writeline.

(true confessions, here)

And it's a PITA to debug. Because...well...things are so tightly coupled I'm not quite sure WHERE to put in the debug statements and even when I do I'm making assumptions about other pieces working and that leads to...

Well, we all know what happens when you assume.

So in a fit of brilliantly obvious inspiration, I did two things.

1.) I ported the unit tests over to the "really/working but somewhat crufty" implementation.

2.) Did some decoupling. Specifically there were two pieces:

determine which way way I'm supposed to go based on where I am and the target is

issue a command to move the robot ( myrobot.moveright() )

translate the moveright into actual motor directions (move motor b @ 70% power in the left direction)

The third had already been isolated. But I was doing 1 and 2 in the same function. I pulled them apart. Now a parent function says "where should we go?" and the fxn returns a "left, down" or somesuch.

NOW we're cookin. Unit tests were written for each of 4 quadrants, like so:

In the end all was happy. Except tracking was much less precise than I'd like. Gear slop and imprecision in initial calibration were affecting things far more than I'd like.

So...where are we at?

The laser tracking worked best for precision...but it suffered from light refractions and went somewhat nuts in anything but a nice, lowlight environment. Oh, and if the beam was scattered or at an angle (think: shining a laser pointer on a table at a steep angle), things went wonky. Chasing butterflies.

2 comments:

It's funny how you can spend so much effort on a problem, only to find that someone else has been working on the same thing at the same time and documented their thoughts on the way through. I am most impressed with your model & blog.

I have been hastely trying to get my launcher working properly. It's quite a different design to yours but has a similar effect. You can see some vids & pics at - http://tinyurl.com/2l7m2m. I am planning on hooking it up to RoboRealm to do some tracking (if time permits), so I'll be interested to see how you get on. Thanks for providing such an interesting read.

About Me

To pay the rent, he tests software, writes software, and writes software to automate testing software. Systems admin, network monkey, husband, developer-for-hire, qa engineer, father, devops grunt, and test automation lackey for more years than he cares to remember.
(back in *my* day we had an actual "turbo!" button on the front of the PC ... to switch from 4.77 to a blistering 10 megahertz. Good times.)
In his spare time he tinkers with electronics, epoxy, 3d printing, string, and whatever the kids need built/melted/experimented with at the moment.
He resides with his lovely wife, four children, one dog, and five cats.