The moment I've been waiting for has finally arrived. Testing the algorithm!
So it turns out, the code I wrote originally is more or less workable. With a few simple tweaks, I am able to get everything working. With the following exceptions:
- The battery cannot be mounted in the top rack
- If bbot over-corrects at any point, it's all over. It may take 1 second, it may take 4 seconds, but the oscillation will ultimately be its downfall
- Torque is tricky
The very first problem I ran into was that I couldn't juice enough torque from my motors. It would either be too slow, or too weak. So I swapped out the 12v steppers with 3v steppers (which have a higher amperage rating), and then proceeded to experiment with over-clocking the voltage in order to increase the torque.
I'm using L293D H-Bridge drivers which, as it turns out, are ancient relics of a less civilized age. They have serious voltage drop, which I think explains why I'm getting such awful torque.
Many voltages later, I still can't get it to overcome gravity. It's so close, but the angle-of-attack at which critical-failure happens is just too dang low. As a reality check, I removed the battery pack from inside bbot, effectively reducing the overall weight significantly. Lo and behold - it actually works (mostly)!
I'm planning to redesign the robot such that the battery pack is housed at the lower level. This might work. Idk. My other idea is to add yet another battery to increase torque. But I need to be careful, as I'm nearing the amperage limit.
By the way, I forgot to mention that I cast the HMC5883L asunder. It's truly not great for my application. The sheer sensitivity to magnetic fields, the inconsistent readings, the fact it never really quite worked... *sigh*
I've invested (a whole 3$) into an ADXL335 triple-axis accelerometer. This thing is badass. No calibration required and no sensitivity to magnetic fields = pure happiness. It just worked right out of the box.
So all that calibration work I focused on earlier was for naught. But that's okay - it was actually a lot of fun to explore the limitations of the HMC5883L. Knowledge is power! And I learned that particular unit wasn't for me.