Let's Make Robots!

R3's eye, and trying to aim the robot

Rudolph's picture

So I'm trying to add an "eye" to R3. Mechanically it's simple enough, I just stuck an LDR between ground and one of the analog inputs. Since the input has a built-in pullup resistor that should effectively create a voltage divider. No problem, that works as expected. Now I want the robot to spin in place, stopping every 45 degrees to take a light reading. Since the motors are just modified servos with no feedback it took some fiddling. After a bit of trial and error I find that running both motors for 300 millis rotates the bot 1/8 turn. So, spin for 300, stop, take a light reading, if the light reading is lighter than the last one replace last high reading and store which step in the spin it is, repeat. As usual, the code to make that happen is shorter than the sentence describing it in English. No problem.

Here's where it gets fun. Because of the way R3 drives (the spinny motion described on the project page), to aim for a specific location the "right" wheel needs to be pointing towards the target at the start of the drive cycle. Since I saved which position had the highest light reading, and I know which position I end in, it's simple math to figure out how many 1/8 steps the right wheel is away from pointing at the target. I should just have to run the motors for 300*steps millis to be lined up correctly. Except this part just fails to work every time. R3 ends up pointing it's right wheel nowhere near the intended target. I know it's likely a bonehead screwup in my math. Now I've tweaked the function so much I don't remember where I started. The best shot is probably to delete that part, grab the notebook, and work it all out again from scratch.

Damn this would be easier if I'd just used wheel encoders. Why in the hell did I decide to try it with as low of a parts count as possible? Is there a moral to this story? Probably not, just generalized ranting, and a reason to put off grabbing a pencil and thinking about math that I shouldn't have this much trouble with.

Update

I rewrote/reorganized about half of the light-finding function. Now the steps are named 1 through 8 (inclusive) instead of 0 to 7. That makes it a bit easier to calculate how many steps out of aim the bot is. Easier makes for less code too ;) Another big change is making the final rotate happen in steps, as discussed below with emuller. Finally I just moved the order of things a bit, now it moves then takes a reading, instead of reading then moving. Minor change, but for some reason my brain wrapped around that easier too. I blame the Rum.

Now I've realized a new problem. Fortunately it's not a major one. The 300 ms delay and/or the speed at which the servo is driven are likely to be wrong when I remove the Serial.print() debugging lines from the routine... Dammit... I blame the Rum. LOL

Update 2

Nevermind about the Serial.print screwing with the timing. I'm not printing to the console while it's driving, only while it's sitting still. That was a "duh" moment. Yup, blaming the Rum again ;)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ezekiel181's picture

I`m doing hand timed turns too, until I work out what the hecks wrong with my wheel encoders anyway, but unless your motors are powered through a regulator any drop in battery level is going to throw the calculations off a little.

Other than battery voltage it could come down to drive wheel slipping. Oh I just looked at the robot page, yeah the CDs would slip on carpet. Do you have any of that plastic-y lino to try it on? Or like a rubber place mat?

Rudolph's picture

Ya, the motors are being powered by the 5V reg. Wheel slippage was slightly different, but still noticeable on lino. I've since added more traction by wrapping a fabric medical tape around the wheels.That helped a bit at least, didn't cure it though.

I'll be happy if I can get it to aim within 15 degrees of where I want. With the slipping, general stupidity of the bot, and goofus drive method, it'll never make it anyway :)

Rudolph's picture

Oh it's definitely possible. It's just a matter of getting it properly thunk out ;)

As it sits now, using your example, I'm turning 600ms. You have a very good point that turning 2x 300ms might give more predictable results. That's an easy change to make too, so I'll give that a shot before rewriting the whole damned function.

edit = D'oh! I failed to hit the reply link for this to be threaded correctly. Dammit.

emuller's picture

Don't go the way of the encoder..

Acutally, I don't know if you should or not, but this is interesting news - in my blog I was intending to discover if what you are doing is possible, and I'm dissapointed that it seems not to be.

However, can I just get clarification on the process? You are saving the number of 1/8th turns needed to point to the brighest light. Let' say it's 2*1/8 from where you are now, so that means you'd have to turn 2*300 ms right? do you do that as 600ms, or as two times 300ms? Tehre's probably and element of momentum and static friction too, so if you were to do it in two sets of 300ms, then you might have more success..?