GearsBot is a simple demo robot that is used to demonstrate writing WPILib programming. There are two sets of talks using it available on youtube: one with RobotBuilder and the other with just NetBeans. The example program provided is very similar to the code written in those talks, but it does have a few extra features to make it more simulation friendly.
There are two major differences for supporting simulation. The first is
taking advantage Encoder.setDistancePerPulse() and the AnalogPotentiometer to convert the readings into meaningful units such as feet and degrees. The simulator returns values in these more meaningful units by default and by
21converting the readings from the real robot to these units the code can be written at a higher level that runs in both simulation and on the real robot. The second major difference is that the PID values are different on the real robot and on the simulated robot. While it would be ideal if they could be the same, the reality is that the model isn’t accurate enough and for
better performance they use different PID values.
All of the other code is the same, so it’s one codebase that can be run in
two different ways. In order for the code to know whether or not it is run- ning on the real robot or in simulation, there are two convenience methods: Robot.isReal() and Robot.isSimulation() which return booleans. Any code that is specific to either the real or the simulated robot is wrapped in an if statement with a call to one of these methods so that it only runs in the right configuration.
The example program has an operator interface for a PS3 controller that allows basic teleoperated control. The robot is driven using the left and right joysticks y-axis to control the corresponding left and right motor speeds. The left and right bumpers provide access to semi-autonomous control and the D-pad provides more granular control over the claw and elevator.