Share your Java Utilities and Object Classes

So I am sure just about every team has written a class for something that isn’t in the library, or some other utility to aid in code development/testing. In the spirit of Gracious Professionalism and Open Source, I would love to have us share our creations.

For my contributions:

XboxController Class that is compatible with the CommandBase OI Button and Scheduler system. It also assists by using subclasses for the buttons and axises to alleviate memorizing the button/axis numbers.
XboxController

Threaded RaspberryPi Socket Connection. This is a little more specifically written to our uses, but it is likely useful for any co-processor using a TCP Socket Connection in a separate thread to prevent the robot from crashing if the thread crashes.
ThreadedPi
ThreadedberryPi (subsystem)

Then I have python code for a RaspberryPi for processing images and using a TCP Socket Server. This was not written by me, but we used it on our competition robot which has perfect killer accuracy. It calculated Distance(in millifeet) and pixels from center. The distance wasn’t quite accurate, but was consistently inaccurate(useful if you recorded target points).
PyGoalFinder

I hope these helps someone. And thanks for sharing if you do so!

Here is our current code, we have quite a few of these things,

  • util.CoupledTalons is a class we have to run two talons in sync with eachother, it also ramps the power on them.
  • calibrations.* are classes that let us calibrate sensors and get usable numbers from them, we have one for an encoder with a limit switch at one end of it’s travel, and one for a pot with one on each end.
  • limitSwitches.* are classes that make using limit switches easier. There is NCLimitSwitch which is a wrapper for the normal digital input class that inverts the input so we can’t forget to do it. LimitSwitchSystem is an interface for a class that helps with using limit switches as bounds, SingleLimitSwitchSystem is one that just has one limit switch, DualLimitSwitchSystem is for two. They both return values of the LimitSwitchState enumeration, which has values for when the switches are pressed and for when they aren’t.
  • controllers.* are classes that generalize motor control using the calibrations and limit switch systems. There is SimpleController which works exactly like a normal motor controller, except for the fact that it uses the limit switch states to limit the motion. StringPotPidController and EncoderPIDController add PID on top of the simple controller.

The code isn’t commented very thoroughly yet as the code is still changing and we haven’t had a lot of time to comment it, so don’t hesitate to PM me with questions.

Thanks for the thread, thanks for the posts. Always good to read other people’s code. I do not have much to contribute, but we have found this library useful for Math functions that Java ME does not provide: http://javolution.org.

Does anyone know a simple lib for formatting floating-point numbers since printf is not available?

gixxy’s is probably superior, but here is a link to a mapping file we use for XBox gamepads (We just use the Joystick class and these mapping values).

Does anyone know a simple lib for formatting floating-point numbers since printf is not available?

If you just want to fix to a specific number of decimal points x, you could make a simple helper class/method that multiplies it by 10^x and casts to an integer, then divides it back down to a float… but you probably already thought of that :slight_smile:

We bit-banged an SPI-interface for the Raspberry Pi, but assuming nettables doesn’t interrupt your solution, yours looks much better. :wink:

Our team also wrote code for a Raspberry Pi that we intended to use on the robot (we couldn’t due to weight limitations), and we used C++ and OpenCV to create an image processing program. Our team intends on publishing a Raspberry Pi image designed for FIRST this summer. Thanks for publishing this.

A TCP Socket Connection is basically Serial over a Network. While I’m not going to say Net Tables CAN’T cause a problem, I would find it very peculiar if it did.

We used the RPi (with said posted code) at competition this year and besides issues with autonomous (if it wasn’t fully booted in time) it worked perfectly!

I’m not sure how relevant this is, since the topic seems kind of old, but I wrote this up last season and think it was extremely useful. It’s a set of classes that can be extended to automatically set up a way to edit autonomous code on the fly so you don’t have to re-download and restart the CRio just to change a simple variable. This makes having multiple autonomous sequences easy to manage, and brings extreme flexibility to that section of the game. The only downside that it only works for teams using the command base, and it is a little tricky to set up.

https://github.com/Ipiano/Parsable_Autonomous