Thursday, 24 September 2015

Week 9

As mentioned in my previous post, the battery that I ordered arrived on Monday.


It's a 2 cell lithium polymer battery, giving it an output voltage of 7.4V (just over the servos' rating of 6V, which is fine), with a capacity of 3300mAh and a maximum current output of around 100A. Holy crap. Suffice it to say that I won't have any current problems any more, since the maximum current that I can expect the whole robot to draw is around 2A.

Unfortunately, the battery is even bigger and heavier than I had feared, so getting it mounted on/in the hexapod could be challenging, and the weight of the battery could be a serious problem, but we won't know until it gets mounted.

Regardless of these looming problems, I'm comfortable that I can say that I have a working v1.0 now. Having achieved the awkward walk using the leftover test code, I rewrote the entire code base using object orientation and best coding practice. This took me maybe 3 hours in total, much of which was consumed by packaging the Hexapod class and its subclasses as an Arduino library to get around some annoying linking issues. The OO structure of the library is reasonably simple:


The need for a separate class for left legs and right legs is due to how the servos handle angles. They're all the same insomuch as they have the same points of reference and rotate the same way given the same input, but that is exactly why they react differently depending on which side they're on. If a servo is in a left knee, for example, then increasing the angle value will cause the knee to bend inwards. However, in a right knee, everything is mirrored, except for the servo's idea of direction, meaning that increasing the angle value will cause the knee to extend. This means that in order to have a function FlexKnee(int degrees) that behaves the same for all legs, it needs to be a different function depending on which side the leg is on. This is the only (significant) difference between the classes.

In order to use my library, I simply instantiate a new Hexapod object. In the default constructor, the legs are instantiated with hard-coded parameters (for servo pins and positions) specifically for my hexapod. This isn't the most extensible approach, since you have to modify the library to change those values, but I've already taken some liberties in assuming that this library will only be used for my hexapod (at least, without any tweaking), and it's nice to simply be able to call Hexapod(), rather than trying to pass 36 parameters. That said, it wouldn't be too hard to adapt the class to a similarly structured hexapod.

The library's code can be viewed [ here ].

Having migrated away from the monstrous test file that was controlling the walking in my last post, I tweaked all of the stored servo position values to ensure that they were level when holding themselves in the rest position. This meant that I had a good reference point for the walking algorithm, which ultimately works by applying a series of offsets to the rest position. The result of this rewrite and retweak is a much smoother walk. I can also increase the speed much more reliably. The video below displays the new walk.



I'm hoping that the in-place rotation algorithm will be as simple as modifying the walking algorithm such that the slow-moving legs move in the other direction. We'll see in the coming week.

No comments:

Post a Comment