23 February 2008

Bits!!!

Found the bits ...

So last night I connected a pot to V+ as a way of experimenting with different voltages and seeing what I values are read. Figured I'd notice something ... And I did. I got screwey values, but they tended to be bimodal. I put the pot in the middle and it reads some 2091 value. And then some -14295's. And then back to 2091. And back to -14295's. So I drop to 0V, or as near as the pot can get to it. And get -8197 and 8188. With +5V: just -12301.

Two high bits are random!

And that makes total sense when thinking about what the MCP3301 datasheet said. For the first two clocks the data out is held at high impedance. Which means random data is read. Next is a 0 bit followed by the value, sign bit first.

Change my code to check the sign bit and set the high three bits appropriately. Now everything is cool. Pot all the way left is -4. Middle is 1904. All the way right is 4083.

So that's 12 bits. As I'm getting a -4 that means I should be able to go down to near -4095 for the other bit. Probably just need to adjust Vref.

10 February 2008

More bits!!!

So, it seems like the 'bots problem balancing has a few possible factors ...

Height: First problem might be the 'bots height. Finally broke down and did a goog search to see how others do this. Most are short stumpy things. Perhaps my robots height is making things harder. I can move the components to a shorter chunk of wood pretty easily, but first want to try other things.

Weight: Large chunk of wood means lot's of inertia and momentum. Perhaps that is keeping the bot from moving things early enough, and keeping them moving when motors reverse direction. Again, want to try other things before going small. I think that a swarm of tall bots is much cooler than a swarm of pygmies.

Speed: Even with the RM2's the motors only go about 120 RPM. Seems like a lot do 200-400 RPM. I've got faster motors, but will need to rebuild a lot of stuff to use them. So let's try something else first.

Tuning: The PID loop is tuned poorly at best. I'm still struggling to get it set up right.

More bits: And lastly, seems like the resolution of the IDG300 might be a problem ... IDG300 will do 300 degrees per second. When we start falling, we get maybe a few degrees per second. Rate is reported at .002v/degree/second. Atmega has a 10 bit A2D with a reference voltage of 5 volts. Or .005 volts per unit. So, falling 3 degrees per second shows up as a one unit change in A2D value. 5 degrees per second shows up as 2 units. At best I'm getting 4-6 units of change ...

That's a good hypothesis ... but there is a contrary data point. Botka. A balancing bot using the IDG300. Perhaps it's PID loop is tuned better. Or maybe it's something else. Or maybe it's that it's shorter. Or it's body or motors. Or ... But no matter, there's no way to know. There's not enough details about how Botka works, so I gotta go on my own ...

I figure the next thing to try is a higher resolution A2D. Have discovered the MCP3301, a 13bit A2D. With it I get at least 8 times the resolution. As it also has full differential inputs and a reference voltage. I should be able to set the high and low voltage to .1v above 0 degree per second and .1V below 0 degree per second. That will let me measure up to 50 degrees per second either way with 13 bits precision. 100 degrees/8000 units means lots 'o resolution!!!!!

Off to wire it up

...

And ... Gak, breadboarded the thing up for just basic testing. Vref at +5, V- at 0. Tried V+ at both 0 and +5. Wildly weird values for both. Every step is a pain in the ... Ummm, make that every step is a chance to learn more.

Done for tonight. Try again later tomorrow or the next day ...