3 plus/3 minus in WPILibj robotics library

WPILibJ is a library used for FIRST robotics code when programming in Java.  Helping the Stuypulse team gave me the opportunity to look at some of the code.  In honor of ship date this year, I decided to blog some thoughts on the library.  You can see the JavaDoc to follow along.

Good design point #1
The class names have strong ties to the “business.”  Class names like Joystick , DigitalInput and SpeedController are very clear and provide a mapping to a good concept.  They also encourage good object oriented code.

Good design point #2
For the most part the documentation is good and the classes logical.  Many classes have useful comments and tips on usage.

Good design point #3
There are patches released through the competition season.  Care is taken for changes to be backward compatible and not break existing code.  Much appreciated on a six week project.

Surprise #1
In the Image class, care appears to be taken for immutability (classes that cannot be changed.)  It has a package private constructor.  Only getters are provided.  The object can be written to a file, but you need to create a new object if you want to read from a file.  Then comes the surprise.  The image instance field is public!  And that public field is of type Pointer – a wrapper to native memory.   Eek.  Memory leak if you mess with it without being careful?

Surprise #2
The CANJaguar class had the biggest surprise.   When you instantiate an object, you pass the control mode.  Straightforward.  I expect the code to behave differently when different modes are passed.  Then you try to call setVoltageRampRate.  The JavaDoc clearly states what it does:

Set the maximum voltage change rate. When in percent voltage output mode, the rate at which the voltage changes can be limited to reduce current spikes. Set this to 0.0 to disable rate limiting.

Then there is what it does in reality.  If the control mode is kPercentVBus or kVoltage, a formula is used to set the ramp rate.  For the other three modes, the method does nothing.  That’s right nothing.  It doesn’t throw an exception or set it to zero or log an error or anything.  Which means you don’t realize it doesn’t do anything without reading the code.

Surprise #3
I can’t really call this a surprise as I’ve known about it since beta testing.  But I was surprised then.  Last year, there was a Dashboard class for custom output.  It was hard to use and they added a SmartDashboard class this year.  And logically, they added an interface IDashboard for the commonalities between them.  There aren’t many commonalities, but that’s not what I find surprising about the interface.

To use the old Dashboard, you write:


Dashboard d = DriverStation.getInstance().getDashboardPackerLow()
d.addXXX();

To use the new SimpleDashboard, you write:
SmartDashboard.init();
SmartDashboard.logXXX();

That’s right – the new one uses statics. This is where the interface becomes confusing. If we are calling static methods, an interface doesn’t make sense.

The worst bug
The worst bug we encountered wasn’t actually in the WPILib code.  It was in the underlying National Instruments code and affected all three wrapper APIs (Java, C++ and LabView.)  The Encoder class works in an illogical manner. In particular, it only lets you use the first, third, fifth and eighth encoders to get the rate of movement.  (No, that isn’t a typo.  It is a seemingly random collection of orders rather than every other.)  That’s if you are in one mode.  In another mode, the working encoders change.  We have to fool the low level code by creating dummy ones to the “real” encoders get the proper constructor call ordering.  While this was documented on chief delphi (the unofficial FIRST robotics forums), we wasted a lot of time assuming we were doing something wrong.

Conclusion
The longer text for the surprises doesn’t mean that the code is bad.  Just that there is more to write about unexpected things. All in all, I appreciate all the API gives us. Congratulations to team #694 (Stuypulse) on a great build season and for completing an awesome robot on time!

cropping video fast for dummies

I wanted to edit a three minute video down to less than 15 seconds.  I’ve never done this before and don’t have any special software.  And I needed to do it in an hour.  What to do?  What to do?

Why the urgency?

I was giving an Ignite style presentation on Stuy Pulse’s journey this season (FIRST Robotics team #694).  Since Ignite slides are 15 seconds in length, I originally decided to go with a static picture.  The night before my presentation, an alum of the team sent out a really good 3 minute video.  I thought it would make my presentation much better to include one 15 second “slide” of video.

Where I started

The original video is 3 minutes and 36 seconds.  I decided it would be nice to show kicking a goal in autonomous (no humans involved), driving over the bump/ramp and hanging.

How I did it

  1. Note that I have Windows Movie Maker on my machine which I can use for basic editing.  The shortcut disappeared, but I can create a new one pointing to C:\Program Files\Movie Maker\moviemk.exe.
  2. Download the video using ClipNabber so I would have a copy of it locally.  This downloaded the clip as an .mp4 file.
  3. Since Windows media player doesn’t support .mp4 files, I needed to convert it to another format.  I downloaded the free QuickMedia converter which was a 45 MB file.  Thanks to the Microsoft forum for the idea.  Converting the file from .mp4 to .wmv took 2 minutes.
  4. In Windows Movie Maker, import the .wmv file.
  5. Play the video using the navigation icons to split the video into pieces.  The relevant buttons were:
    1. Play – to start it
    2. Split – to create a clip boundary (start of end the clip)
    3. Previous/Next frame for precision
  6. Drag the three completed clips to the storyboard
  7. File > Save movie file

How did it work?

This process was good for some rough editing.  I met my goal of having a clip under 15 seconds showing these three things.  For “real” editing, you’d want a better product of course.

The final product

The completed video does show what I wanted.  I didn’t edit out the sound because I knew the speakers would be off during my presentation.  The words that went with that slide were:

red al-liance! ,<clap><clap>, <clap><clap><clap>

blue al-liance! ,<clap><clap>, <clap><clap><clap>

hang! hang! hang!

if 694 wins this, we go to nationals!

<pause>

Then the next slide is a screenshot of the congratulations message; the one at the beginning of this post.

And yes, I got permission from the video creator to do this and blog about it.