Showing posts with label servos. Show all posts
Showing posts with label servos. Show all posts

July 17, 2009

Back to Work

I have been working this whole time (well, except last week), even though I've kept pretty quiet about it on the blogging front. I think it's about time for an update.
The DynamixelNetwork code is just about finished. That is, it feels very well-rounded, it's densely-commented, and it'll do everything we need it to do. (In fact I think there's now more comments in it than actual code... but I did it for Doxygen, so that you don't even have to open the source code now to find out everything you need to know about it.) There are still one or two problems with it--a couple obscure functions of the servos aren't yet supported, and the latency is pretty high--which I'm hoping to get the chance to iron out before I leave, but I still think it's a nice bit of code, and better than anything else available for Linux for these servos. I hope the university will choose a license for it soon, so I can post a link. It's my first real contribution to the "open-source community", and hopefully not the last. I hope it gets a good response.
On the robot front, I'm making good progress writing the pan-tilt unit module to integrate into the software framework. That's kind of minimal, though--just a bit of code to accept and send messages, which talks to the servos with my library. I've also been tasked with designing the hardware for the robot body... somehow. Heh. When I first got here I started in on the pan-tilt unit, and I had never designed hardware before. What I'm doing isn't really too complicated, it's just a bit of CAD... but I had never done it before, and I didn't have any idea where to start. I did it, though, and it was pretty fun. It turns out that by doing that, I became the most experienced person on the team when it came to hardware. So I was the natural choice to design everything else.
I'm not complaining, though. I'm learning some valuable new skills, and I do like to tinker with gadgets every now and then. It's staves off the drudgery of programming 24/7, and I'm getting better at it, too. So on Tuesday I'm going to take the robot apart again, pull off a few things, walk to the workshop with an armful of aluminum, and slap it all together. Fun times.

I'm leaving Germany on the 12th of August. That means I've got three weeks left to finish up. If I finish the hardware next week, I should be able to get the software wrapped up before I leave. It's really strange to be leaving so soon. Three months isn't really much time at all. It's okay, though--it wasn't long enough to get overly attached to the place, but it was long enough to get a whole lot of stuff done, and get some memorable moments in there, too. I'm not really excited about jumping right back into school again, though...

June 19, 2009

These servos are fun!

Driver code: Just about finished.

Today and yesterday were a bit of a grind. Although I was being productive, the type of work I was doing wasn't exactly mentally stimulating. But it had to be done. A lot of the functions of the servos--almost all of them, in fact--are controlled by setting registers. There are a few variations, but in the end the bulk of the class falls into four or five private methods, and the dozens of public methods are only there to provide a user-friendly interface to the servo registers. I tried to find a simpler way, but the data varied too much to make anything very consistent--for example, some of the values are stored in two registers (for values over 0xFF) with the high-byte and low-byte swapped, some are restricted to a smaller range of values, and some are just bit flags. So the class is now chock full of tons of one-line functions, but it should be pretty simple to use--abstract enough for anyone to have an easy time using it, detailed enough for someone familiar with the servos to do anything they want, and secure enough to prevent anyone from breaking anything without explicitly trying to (for the most part).
I wouldn't call this completely finished--there are still one or two functions which I haven't implemented yet, there are a few aesthetic decisions that I might change, and I've still got to write most of the comments. But right now, for the project I'm working on, the code will do everything we need it to do. I feel accomplished.

June 15, 2009

It compiled! It compiled!

Okay, it's not a gigantic achievement. But it is a significant milestone, and it took me a lot of work to get here (more than it ought to have taken, honestly...). I finally compiled my first C++ class. I mean, besides the little ten-line classes that I wrote in school when I was still learning what object-oriented programming was. This is the first real object-oriented code I've written, and although it's not finished, a firm groundwork has been laid.
What I've got now is a "DynamixelNetwork" class that controls a serial port with an arbitrary amount of Dynamixel servos on it (we're using RX-10's, but I believe the communication protocol for other Dynamixel models is very similar, if not fully compatible). The reason for having one "Network" class instead of individual objects for each servo is because they can be daisy-chained together, so the communications all have to share the same serial port. Plus, there's not a whole lot that an individual servo class would do. The main requirement is simply an interface to the communications protocol, and that can just as well be centralized and used for any arbitrary servo. I may uncover additional requirements as I finish up the class, but I'm doing my best to keep the code flexible.
What's been taking me so long is just figuring out how to write to and read from the serial port. It seems to me that it's one of those tasks that just seems to be harder than it needs to be. I'm using the termios.h interface, which is archaic, difficult, and fugly, to say the best, but at least it's a standard. Right now I've got a working "sendMessage" method, and the "getResponse" method is mostly working, but giving me some weird errors. I don't understand what's wrong just yet, but I've mostly isolated the problem, and once I get that solved I'll have just about all I need. After some little difficulty I rolled those into a working class, got the .h and .cpp files all nice and neat-looking, and poked it with a sharp stick until it compiled. Once that was working, adding additional functionality was almost as simple as just finding which registers to write to (in the servo), and sticking in a few more methods. I also took some time along the way to add some bounds checking, sprinkle in some custom exceptions, and put in a few routines to improve general performance (like one that instructs the servos to stop sending status packets back after each instruction, to save the time it takes to wait for each one).
It's not all a cakewalk from here, though. What I have to do now, and I hope to finish this before Thursday, is to finally get the getResponse method working, organize the inheritance of my exceptions into a more logical structure (right now they're all inherited from the base exception class), write a udev rule for the USB serial port adaptor, fully comment the code, and add in baud rate switching. This last one's the hardest, because if you make a mistake switching the baud rate, you could end up with a servo that refuses to listen to you. (Because of the way the baud rate is set within the servos, it might even be possible to switch it to a rate that the PC serial port isn't capable of using... I think that's my biggest fear right now.) I might also add in a few "scan for servos on network" methods, but that's on low priority for now, because we're going to be working with a known configuration for this project. Eventually I'd like to add it, though, so that this could become a good general-purpose C++ library for the Dynamixel servos. I searched pretty thoroughly before deciding to roll my own, but now that I'm putting all this work into it I'd like to make it a contribution to others who don't want to put in this much effort (and also don't want to use .NET).

Well, that was an unnecessary amount of detail. Hope you enjoyed it. It's good to get all my thoughts laid out in text, though.