Archive for 2009

WPILib Test Harness Released!

Saturday, March 14th, 2009

So after *far* too much time spent on this, I am happy to announce the release of my WPILib Test Harness! For those who aren’t aware, WPILib is the name of the C++ library that FIRST gives to FIRST Robotics Teams to control the robots. The control system is a PowerPC running on a cRio platform designed and produced by National Instruments.

It had occurred to me towards the end of the build season this year that it was really annoying that I could only easily test code while our team was meeting, and of course I stay up late (as evidenced by this post time). So I wrote some stubs, but at some point I realized it would just be easier to make a giant stub for WPILib, since its just a set of classes with some hardware interfaces. It was extremely useful, and as I evolved it I was even able to find bugs in WPILib and the program for our bot.

At some point I decided to bring it in the direction that it is now, and I’ve spent the last week adding things and making the GUI a bit shinier. I’m pretty happy with the results so far, but theres a long way to go before every bot program will run under it. There’s a lot of things that do work, but there’s also a lot of things that don’t work.
(more…)

Debug STL errors with __GLIBCXX_DEBUG

Friday, March 13th, 2009

Ever got one of those *really* annoying glibc errors that don’t give you a whole lot of information except “something bad happened, and it was memory related, but we’re not going to tell you where the problem is!”? You know, in the form of

*** glibc detected *** ./test: double free or corruption (out): 0x0000000001e52440 ***
======= Backtrace: =========
/lib/libc.so.6[0x7f27a9fd5a58]
/lib/libc.so.6(cfree+0x76)[0x7f27a9fd80a6]
./test[0x401e51]
./test[0x401e83]
./test[0x402118]
./test[0x402159]
./test[0x40155b]
./test[0x40167d]
/lib/libc.so.6(__libc_start_main+0xe6)[0x7f27a9f7a466]
./test[0x400cd9]
======= Memory map: ========
... and so on ...

I’ve encountered this cryptic and annoying error (I mean c’mon, usually the memory addresses referenced in the trace don’t resolve to anything in gdb) a few times for really random and weird memory-related errors, many times when I’m doing something with the STL.

Turns out, you can define __GLIBCXX_DEBUG in your program (using -D__GLIBCXX_DEBUG on the g++ command line), and instead of an annoying message you may get an assert that is far more helpful and looks like this:

/usr/include/c++/4.3/debug/vector:267:error: attempt to access an element
    in an empty container.

Objects involved in the operation:
sequence "this" @ 0x0x7fff5ee0f420 {
  type = NSt7__debug6vectorIiSaIiEEE;
}

Now at least you know what you did wrong. However, for optimal usage you should be attached with GDB, and then as soon as the error occurs you can do a backtrace with the debugger and you should know exactly where the bug is. The only caveat is that there is a noticeable performance hit when you enable this (especially if you use the STL heavily), so in general you don’t want to define it all the time.

Hope that saves you some time! I know it helped me!

Swerve Drive Model Spreadsheet

Monday, March 9th, 2009

Our robot this year uses a ‘swerve drive’ mechanism, with 4 independently steerable wheels. I wasn’t quite sure exactly of the best way to describe the robot’s motion in terms of basic parameters (speed, heading, rotation) , so I went google searching. I found a PPT by Ian Mackenzie talking about different types of omnidirectional drive systems, and it was extremely helpful.

After thinking about it some more,  I created this spreadsheet to help describe the motion parameters to the students I was working with. Its pretty sweet — it uses scatter plots to show the angle of each wheel and the ideal velocity to obtain the motion desired based on the speed/rotation/angle parameters of the overall robot motion. The implementation in C++ was straightforward after that, and it worked out extremely well (unfortunately there is the whole issue of controlling it intuitively with a joystick… we haven’t quite got that down yet).

Download it at my FRC resources download page

FRC Driver Station Test Program

Sunday, March 8th, 2009

This is another resource that I’ve created for the Kwarqs FIRST Robotics team this season that I’ve found useful, and hopefully others will find it useful as well.

This particular program is stupidly simple, but really nice to have around in case you think your driver station is being screwy, or you want to verify that your switches work *before* running your actual code on it (not that you would run something without testing it, right? ;) ). As you can see from the code, it displays the driver station inputs on the LCD panel of the driver station. It uses a modified version of the DriverStationLCD class posted at http://thinktank.wpi.edu/article/144

(more…)

PID parameter calculation spreadsheet

Thursday, January 29th, 2009

While working on some code for the FIRST team that I’m on, I had decided we were going to need PID control for some portions of our robot. Unfortunately, I have not done a lot of this stuff.. I took a control systems theory class in college, but I never quite saw the value of it at the time (which, I’ve come around now that I’ve seen some practical applications). So, to understand how it works more, I created this spreadsheet with adjustable P/I/D parameters.  I found this to be a useful tool in understanding the output of a PID control system.

Of course, its strictly an ideal model and not particularly realistic (try setting the P parameter to 1)… but its primarily useful for getting that basic understanding. Theres a number of ways it could be improved… feel free to improve it. :)

Download the PID spreadsheet

Updates and such

Tuesday, January 6th, 2009

Well, I have a *ton* of things going on right now… I am very busy mentoring for a FIRST team that my company sponsors (the Kwarqs), and some important deadlines coming up at work.. and trying to get my massive updates to Roadnav integrated in.

Speaking of which, I’ve bundled all of my R* and B+ tree code into a library called libsdbx… I need to write more in depth about it, but its a nice header-only C++ library that allows usage of generic R* and B+ trees with either a memory backend or a file-based backend. Its really nice to use, but I think I’m going to hold off on releasing it in a formal package until a final release of libroadnav is created (which will definitely iron out any lingering performance issues or bugs).

Libsdbx can be found in Roadnav SVN at https://roadnav.svn.sourceforge.net/svnroot/roadnav/libsdbx/trunk/.

As I create neat FIRST-related stuff, I’ll be sure to post some of that up here also. I’m really excited about this open source thrust that FIRST seems to be going down lately, its definitely encouraging and makes me want to contribute.