Archive - C++\Java Porting Guide - 2014 to 2015
When C++ and Java teams look at the WPILib APIs for 2015 they should see something that looks very familiar. Where possible we have tried to keep the APIs the same as they were on the cRIO, but in some cases we chose to make changes we had been holding off for a long time to maintain compatibility while we were on the cRIO system and there are also a number of changes that were made to support the changes in the roboRIO system.
The SimpleRobot base class has been renamed to SampleRobot to encourage people to use it only for the simplest of programs. Instead we encourage the use of the Command-based and Iterative template projects available on the New Project menus in eclipse. Teams that understand how SimpleRobot works and have a reason to continue using it may still do so under the new name.
Sensor Start/Stop methods
Gyros, Counters and Encoders have had the Start() and Stop() methods removed. These sensors now start counting on creation/instantiation. The reset methods still exist to zero the values on the specific objects to set the values before starting a measurement.
AnalogChannel -> AnalogInput
The AnalogChannel class has been renamed to AnalogInput to match DigitalInput and avoid confusion with the addition of AnalogOutput. This is just a change in the name and the functionality is unchanged.
The Analog and Digital module classes (AnalogModule and DigitalModule) have been removed. Methods that set module-wide parameters in past implementations have been moved to static (class) methods on the respective channel classes. For more information see the Java and C++ documentation.
DS IO, Enhanced IO, and Kinect
The Cypress Firsttouch board support and Kinect server support has been removed from the DS so these classes have been removed from WPILib. Teams can use the Dashboard or USB HID devices to replace the Cypress board functionality. The TI Launchpad and 16 Hertz Leonardo++ included in your Kit of Parts can both be programmed to appear as HID devices to be used for custom I/O (click the links for more info). Teams wishing to use the Kinect as an input device will need to modify the Kinect server to send data directly to the robot using Network Tables or one of the ports available on the field network.
DS User Messages / DriverStation LCD
The User messages window on the Driver Station has been removed, therefore this functionality (DriverStationLCD class) has been removed from WPILib. As a replacement, the default Dashboard contains a number of controls and indicators of different types on the "Basic" tab that teams may wish to use to display robot information or provide input. To write to these controls, use the SmartDashboard class, the key names to use are listed on the Dashboard. More information can be found in Using the LabVIEW Dashboard with C++\Java Code.
The default controller for RobotDrive has changed from Jaguar to Talon. To use RobotDrive with Jaguars, users will now need to construct the speed controllers beforehand and pass them into the RobotDrive constructor.
The Compressor class has been replaced an updated version that uses the PCM (Pneumatics Control Module). There is no need to instantiate this class when using the module if automatic closed-loop feedback is all that is required. You only need to create Solenoid objects to cause the PCM to be initialized and started. If you wish to turn off the close-loop feedback, then the Compressor object is required. The previous Solenoid class now uses the PCM exclusively.
The existing Solenoid and Double Solenoid class APIs were not modified significantly (with the exception of the module number changing to a PCM CAN ID), however additional methods were added to expose the additional functionality of the PCM.
Channel and Module Numbers
The roboRIO does not have separate modules so the module number has been removed from constructors.
Channel numbers are now zero-based as shown on the plastic cases for all the components.
CAN Jaguars have been completely reimplemented and now support fully non-blocking calls along with brown-out code that will reset the operating parameters should a Jaguar reboot while the RoboRIO is still running. Setting operating modes, i.e. PercentMode, VoltageMode, etc. are documented in the API docs here:
You can no longer get your team number. In place of getting your team number, teams are recommended to use the roboRIO hostname. In C++ this can be retrieved by calling gethostname() from unistd.h. In Java teams can use the code snippet shown above to get the result of the "hostname" command.
DS User Data
Driver station user data APIs have been removed in favor of NetworkTables to communicate with your laptops.
User LED and Button
The User LED APIs are removed (there is no User LED on the roboRIO) and you can now read the user button.
I2C and SPI
The I2C and SPI APIs have changed to accommodate the changed architecture of these buses on the roboRIO and to better align the API in the two languages, with the largest change occurring in the Java SPI API. See the API docs for documentation on the new APIs:
One change not entirely obvious from the class documentation is the I2C bus changed from taking 8-bit addresses on the cRIO (e.g. 0x3A for the ADXL345) to 7-bit addresses on the roboRIO (e.g. 0x1D for the ADXL345).
Analog triggers are now supported.
Interrupts are now supported.
Accelerometer is now an interface that is implemented by ADXL345_I2C, ADXL345_SPI and BuiltInAccelerometer. The AnalogAccelerometer will likely also implement that interface in the future.
Several new methods have been added to the DriverStation class.
The Command-Based template has been tweaked to better align template and RobotBuilder projects. CommandBase has been removed in favor of instantiating the Subsystems and OI objects from the main robot class.
MXP Channel Numbers
MXP port numbers are just continuations of the digital, analog, and PWM channel numbering scheme from the connectors along the outside of the RoboRIO.
You now have access to all the NI Vision APIs in C++ by referencing the documented functions and Java through a set of Java Native Interfaces (JNI) to the NI libraries. See the sample programs for some examples of using the libraries from either language.
On the cRIO, user code could store files to C:\ or to subfolders created there. On the roboRIO, users should store files to /home/lvuser or subfolders created there.
C++ Synchronized and Task
The header files for the C++ Synchronized class and Task class were moved into the OSAL subfolder (OS Abstraction Layer).
Java Networking and File IO
For Java development we have switched to the full Java 8 SE Embedded compiler. In the past many of the APIs were non-standard for things like file I/O and were located in the javax package. Now you can use the same APIs as desktop Java for accessing files on the flash drive of your roboRIO or for networking.
A number of new classes have been created to support the new capabilities of the roboRIO and the 2015 Control System
There is a new PowerDistributionPanel class that supports the current sensing features of the PDP. You can instantiate this object and read the currents from each of the motor channels.
PWM Speed Controller Classes
VictorSP and TalonSRX classes have been created for using these devices connected via PWM
A CANTalon class has been created to support control of the TalonSRX over the CAN bus.
The RoboRIO built-in accelerometer is supported through the BuiltInAccelerometer class.
The ControllerPower class contains methods for querying information about the roboRIO power (input current and voltage and voltage, current, status, and fault counts for each of the user rails).
The analog output channels on the MXP connector are supported through the AnalogOutput class.
There is now an AnalogPotentiometer class that will return angles in degrees rather than voltages that need to be converted. The class uses ratiometric scaling, that is it is based on the actual bus voltages rather than using the constant 5 for the maximum voltage when computing the rotation angle.
Changes to the development tools
- C++ and Java are now both based on Eclipse rather than WindRiver Workbench and Netbeans. Download a current copy of Eclipse (Luna or better) and add the FRC plugins as described in the Getting Started documentation. Once installed you can create either Java or C++ projects from the "New" -> "Project..." menu.
- The WPILib development tools, libraries, header files, and documentation is created in the WPILib directory contained inside your user directory. The WPILib directory is created when a version of eclipse with the plugins is first run for any user account on the system.
- Software simulation of robot programs is available using the Gazebo robot simulator. Currently only supplied models can be used, but they can be programmed using WPILib either with C++ or Java and most methods and classes. The simulator only runs on Linux so to try it, you need to install Linux as described in the Simulation instructions and install the Linux WPILib plugins to get all the tools and libraries required. See the FRCSim documentation on this site.
- There is a full set of doxygen-based library API documentation supplied on-line: C++: http://first.wpi.edu/FRC/roborio/release/docs/cpp Java: http://first.wpi.edu/FRC/roborio/release/docs/java We will try to have the documentation supplied locally in an upcoming release.
- Java 8 is running on the RoboRIO so features like lambdas, enums, generics, etc. are all available to robot programs. For C++ programmers, a current version of gcc is supported so that you will be able to use all the C++ 11 features.
- Eclipse uses mDNS to communicate with the RoboRIO. Make sure that your development system has mDNS name resolution support included. With Linux development systems you might need to explicitly turn on mDNS. With Mac and Windows development systems, the DHCP setting will fail-over to mDNS if there is no DHCP server on the robot network.