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!

TSS Symposium Preview – Throw Away All The Rules. Now What Process Do You Follow?

I'm Speaking at TheServerSide Java Symposium As previously mentioned, Scott and I are both be presenting talks at TheServerSide Java Symposium in March. In preparation for the conference, we are providing sneak peaks of talks this week on the blog.  Scott gave a sneak preview of his GWT lecture.  He has so much information it didn’t all fit in his slides!

I’m giving a talk titled Throw Away All The Rules. Now What Process Do You Follow?” Here are just a few points from my upcoming conference talk:

  1. Testing – for anyone who knows me it isn’t a surprise that I consider regression critical.  But it isn’t always easy to get started.  And yet, the pain of not having it is large.  See how a testing strategy can evolve.
  2. Deployment – a repeatable deployment sounds like a corporate bureaucratic thing.  Yet knowing what is in production and how to get there quickly is an agile concept.
  3. Leader – Note I said leader and not project manager.  Even if you don’t have a project manager, someone needs to be running the show.  Or in the case of Scrum – the team is the leader.

Hope you enjoyed this sneak peak of my conference talk.  For more, consider coming to my session at the conference. If you register with the coderanch discount code, you can save $200.

a virus encounter

Due to my struggles with Open Office Impress, I decided to take advantage of Microsoft’s at home use program and install Office 2007 on my home computer.  Short story, I had a dormant virus on my machine that showed up as soon as I installed Office 2007.  This reminds me why I avoid Microsoft products like Internet Explorer – way too tightly coupled to the operating system.  Longer story:

Symptoms

Right after I installed Office 2007, my Windows XP computer started exhibiting a number of odd problems:

  1. Took 30-45 minutes to shut down the computer
  2. When downloading an attachment from Firefox, Firefox hangs.  Killing it in the task manager and re-launching Firefox keeping the tabs intact indicates the file is still downloading and it completes.
  3. Starting postgres via a shortcut opens a DOS window saying “starting” and hanging.
  4. Starting the postgres process in Services gives:

    Error 1053: The service did not respond to the start or control request in a timely fashion

  5. Internet Explorer does not open.  (I can’t say when the last time this worked was.  I only tried in hopes I could use the Windows Update site.
  6. Add/remove programs shows an empty list.  (Meaning I can’t uninstall Office 2007)

What I unsuccessfully tried to fix it

  1. sfc scan now from Yahoo answers
  2. Running three registry commands from Microsoft knowledge base (also mentioned at Yahoo but I wasn’t about to touch my registry on the advice of a third party site.)  The first gave an error, the other two ran.
  3. Microsoft’s registry fix.  I was able to download it (painfully), but got “install server not responding”
  4. Avast full scan – it hung on the file “c:\windows\system32\drivers\acpiec.sys” about 10% through my hard drive.

What finally worked

Avast’s boot time scan is supposed to run before the drivers are loaded.  Since there was clearly an issue in the driver directory, I decided to try this.  I still didn’t think I had a virus at this point.  The problem CLEARLY showed up right after installing Office 2007, making it Office 2007’s fault, no?

I tried a few times to run the boot scan.  This took a while because each shut down took so long.  And the first two were “unsuccessful shutdowns” where Avast didn’t get the cue that it was supposed to run before Windows launched.

Luckily the boot scan logs everything it finds so you don’t have to watch it.  The process ran for a number of hours and then logged to C:\Documents and Settings\All Users\Application Data\Alwil Software\Avast5\report.

The boot scan found a few corrupt zip files (Apache ant documentation, some class file jars) and a bad Open Office OLE file – all of which it logged and ignored.  It then found seven infected files.

Infected by “Java:Jade-“

Avast says this is caused by old Java exploits.  I don’t think these are a problem and am virtually certain they aren’t the cause of my issue.  However since they are in the cache and I hardly use NetBeans, I just deleted them.  (I use Eclipse for development.  NetBeans is only installed for the FIRST robotics plugin code.)

File C:\Documents and Settings\me\Application Data\Sun\Java\Deployment\cache\6.0\19\66c54313-5302a8c6|>c.class is infected by Java:Jade-A [Heur],

File C:\Documents and Settings\me\Application Data\Sun\Java\Deployment\cache\6.0\52\59ec2974-343db254|>vload.class is infected by Java:Jade-C [Heur], Deleted

Infected by “Win32:Alureon-KG”

Microsoft describes this trojan as being responsible for a range of harmful activities.  None of them look particularly relevant to the problem I’m having.  But they are in a temp directory so no harm in seeing them go.

File C:\Documents and Settings\me\Local Settings\Temp\encrawsxmo.tmp is infected by Win32:Alureon-KG [Trj], Moved to chest
File C:\Documents and Settings\me\Local Settings\Temp\masneowxrc.tmp is infected by Win32:Alureon-KG [Trj], Moved to chest

Infected by “Win32:Malware-gen”

This isn’t good but I don’t have any Symantec products installed anymore.  I switched from Norton to Avast over a year or two ago.

File C:\Program Files\Common Files\Symantec Shared\CCPD-LC\symlcrst.dll is infected by Win32:Malware-gen, Moved to chest

Infected by “Win32:Malware-gen” (part 2)

Eureka! Two dlls are infected by something.  I don’t know which of these was the root cause of my problem, but it was clearly one of them.  I went to check what each of them are for since removing a system file is risky.  dkvcm.exe is a known virus file.  I couldn’t find anything on the dll good or bad.

File C:\System Volume Information\_restore{202550A8-7A33-4BCA-9586-051D24DDBF8F}\RP1238\A0204372.dll is infected by Win32:Malware-gen, Moved to chest

File C:\WINDOWS\system32\dkvcm.exe is infected by Win32:Malware-gen, Moved to chest

Conclusion

I seem to have had a virus lurking that came to life when I installed Office 2007.  Thanks to Avast, all the symptoms are gone now and my machine is back to normal.