I spent a bunch of time working on software in the last few weeks.
I ended up rewriting the computer->AVR protocol to be much more lightweight; it can send arbitrary length packets of bytes which can then be interpreted as different size numbers - 8 bit ints, floats, whatever. I also added a CRC-16 check which is TOTALLY UNNECESSARY but it was an interesting task and it might just keep the robot from driving off a cliff one day.
I abstracted some of my old libraries a bit better and wrote some new ones. Most notably, a time library for checking time deltas and other things. I ended up using it quite a bit.
I learned enough python in a couple of weeks to write a new robot server using asynchronous sockets and ended up completing some IRL work tasks with python as well. Python is very fancy and I plan to use it throughout the project on the robot's main computer and on the client side using wxpython. My plan is to have a very snazzy interface that shows motor RPM, amp draw, temperatures, fault notices, lots of buttons to turn stuff on and off, etc, etc.
All that is pretty boring though. CHECK THIS OUT
The motors are officially installed and working! In the video I just have them connected to the power supply so nothing too fancy software-wise. I wrote a reactive PID controller though, more on that in a second. BUT FIRST
It's actually doing something! Turning in place with a 6WD drive robot has one nuance that you have to account for. The corner wheels will drag and this will cause a great deal of power to overcome. The solution is easy - just mount the middle wheels lower to the ground so that the corner wheels barely touch. As I add more weight to the robot, I'll probably need to continue to lower the middle wheels even more, but this test showed that the solution does work.
Now for the really fun stuff! Reactive PID controllers. On my previous robots I just controlled the throttle using PWM directly. This has some drawbacks. As the robot traverses different surfaces, inclines, etc, it speeds up and slows down as the load changes. It also introduces a bit of drift in direction as each side of the drive train will not always be working with equal efficiency. What I really wanted was to tell my robot STOP YOUR STUPID MOTOR WHINING AND JUST GO THE SPEED I TELL YOU. Thus, I read things like books and wiki pages.
- http://en.wikipedia.org/wiki/PID_controller
- Designing Mobile Autonomous Robots - John Holland, Chapter 5
It's not eas easy as it sounds. The idea is to write an algorithm that will automatically adjust the motor power based on feedback on it's rpm. First, you need to actually measure the RPM, which means using an encoder - like an opto-encoder or hall sensor - and using that as a hardware interrupt on the microcontroller. Then you do math, but not very good math because it involves tweaking numbers that are pretty arbitrary unless you do extremely good math. Extremely good math involves modeling your entire robot - the physics, the electrical characteristics of all the components, and probably even the temperature and the orientation of the moon and what astrology sign you are. That's what it says on the wiki page. Literally, reactive PIDs were invented so that you could just solve it the American way, with a hammer and shocking yourself repeatedly.
Long story short, here is the core of my motor controller: WARNING HERE BE (probably bad) CODE: http://pastebin.com/4G8hWunz Note that I when I say stuff like pwm_init(), I'm calling yet another library I wrote. Apparently in arduino land this is all done for you, but I like doing things the hard way.
It works surprising well after a bit of tweaking (burning a new image on the avr chip ten thousand times). I't pretty cool to listen to both motors spin in sync even when you load one of them down by pinching it and burning yourself. And blowing up capacitors. I have a fire extinguisher now.
The motor driver has served me well, but it's pretty primitive. Just a basic H-Bridge with a failure mode of blowing up. I found a much nicer package, again through http://www.pololu.com/, but this one has some pretty neat features - current and temp limiting, fault indicators, and best of all, current signal, which means I can measure that on the microcontroller and show the client how many amps each motor is pulling. Pretty cool!
http://www.pololu.com/catalog/product/712
I have some prototyping boards on the way and I've got most of the circuit mapped out. Next up will be building the power bus, logic circuits, and making the robot do things without an umbilical chord.
Comments
You can follow this conversation by subscribing to the comment feed for this post.