Now Updated for Ultimate Goal 2020-21
Some older hardware doesn't support Java FX 3D scenes. This runs on several circa 2015-16 Windows 10 and 8 systems we have tested on, but not on a 2008 laptop (which was originally Vista, now Windows 10). If your system does not support the 3D version, the original 2D version is available here: virtual_robot.
A 3D simulator to help beginning Java programmers learn to program for FTC Robotics.
This is a JavaFX application developed using the (free) IntelliJ IDEA Community Edition IDE. The repository can be downloaded and unzipped, then opened with IntelliJ.
Two robot configurations are currently available: BetaBot (for the Skystone game) and UltimateBot (for the Ultimate Goal game). Each has four mecanum wheels. Distance between the centers of front and back wheels is 14 inches, and distance between the centers of left and right wheels is 16 inches. Each has a downward-facing color sensor at the center of the robot, distance sensors on all four sides, and a BNO055 IMU. Wheel diameters for both robots are 4 inches. Each robot is 18 inches wide.
BetaBot has a wheeled intake in back and a vertical lift with horizontal slider and grabbing mechanism in front. The lift and intake are powered by DC motors, the slider by a CR Servo, and the grabbing mechanism by a servo.
UltimateBot has a wheeled intake and a ring-shooting mechanism in front. The intake is powered by a DC motor. The shooter is powered by a DC motor, with triggering by a servo. The vertical shooting angle is controlled by a servo as well.
The field can be thought of as 12 feet wide. The field graphic (currently the Skystone field) is obtained from a bitmap (.bmp) image. The color sensor detects the field color beneath the center of the robot. The field graphic is easily changed by providing a different .bmp image in the virtual_robot.config.Config class. The .bmp image is the skysone_field648.bmp file in the virtual_robot.assets folder. As is, the 3D display scene is 800x800 pixels. This can be increased or decreased by changing the value of SUBSCENE_WIDTH in the virtual_robot.config.Config.java class. Note: changing the subscene width does not require a change in the field graphic.
An abridged approximation of the FTC SDK is provided.
User-defined OpModes must be placed in the org.firstinspires.ftc.teamcode package, and must extend OpMode (or LinearOpMode). OpModes are registered by placing a @TeleOp or @Autonomous annotation immediately above the class declaration.
The OpMode (and therefore LinearOpMode) class in the simulator provides access to:
- A HardwareMap object, which in turn provides access to the DCMotor objects, the gyro sensor, distance sensors, the servo, and the color sensor;
- Two GamePads(actual hardware gamepads, though there is an option to use a "virtual gamepad -- see Log of Changes below");
- A Telemetry object.
Several example OpModes are provided in the org.firstinspires.ftc.teamcode package.
New robot configurations can be created by extending the VirtualBot class; this requires some familiarity with the JavaFX 3D API and the Ode4J API. Questions about this are welcome (via "Issues").
To use:
- Make sure you have the Java 8 JDK installed on your PC. Also, install the free Community Edition of JetBrains IntelliJ IDEA.
- Download the vr_physics.zip, and extract contents. Open the project in IntelliJ. You'll see three modules in the project (Controller, TeamCode, and virtual_robot) -- the only module you'll need to touch is TeamCode. It contains the org.firstinspires.ftc.teamcode package.
- Write your OpModes in the org.firstinspires.ftc.teamcode package; make sure to include a @TeleOp or @Autonomous annotation. These must extend the OpMode class (may either extend OpMode OR LinearOpMode). OpMode must provide init() and loop() methods; LinearOpMode must provide runOpMode() method.
- Make sure at least one gamepad is plugged in to the computer.
- Run the application (by clicking the green arrowhead at the toolbar).
- Press start-A or start-B on gamepad(s) to select which is gamepad1 vs. gamepad2.
- Use Configuration dropdown box to select a robot configuration. The configuration will be displayed.
- Use the Op Mode drop down box to select the desired OpMode.
- Prior to initialization, position the robot on the field by left-mouse-clicking the field (for robot position), and right-mouse-clicking (for robot orientation). This must be done with 3D camera in overhead view (center button).
- Use the INIT/START/STOP button as you would on the FTC Driver Station.
- Use the Camera buttons on the left to change the position of the 3D camera. Also once you've selected any camera position other than the overhead view, you can use mouse-drag to reposition camera: Left-drag to move camera around field, Alt-Left-drag to zoom in/out, and Right-drag to pan side to side or up-down.
- If desired use the sliders to introduce random and systematic motor error, and inertia.
LOG OF CHANGES
CHANGES 10/26/2020 Added Ultimate Goal game and robot option. Select the game (Skystone or Ultimate Goal) in the Config.java file. Brought code more or less up to date with the current version of virtual_robot (the 2D project).
NOTE: with Ultimate Goal, the physics engine will occasionally crash due to a problem with collision detection
when persistently trying to push the wobble goals against the wall. No bug fix is anticipated for this issue
CHANGES 2/28/2020 Added Foundations to the SkyStone field.
CHANGES 2/16/2020 Modified to use the Ode4J (a Java port of the ODE physics engine) for physics-based simulation, including intake and manipulation of stones by the robot.
CHANGES 1/7/2020 Added 3D Utilities to make creation of robot configurations easier. Changed appearance of mechanum bot. Changed latency of IMU and MR-style gyro to 10 ms (it was 175 ms, much longer than is now seen with the "real" IMU). Added 3D SkyStone bridge to the scene.
CHANGES 12/31/2019 Modified the original Virtual Robot application to use JavaFX 3D graphics. It is possible to create new robot configurations, but for the 3D version this is done completely in Java code.s a mecanum-wheeled bot.
CHANGES 11/29/2019 Range class and additional op modes contributed by FTC Team 16072. Servo interface (and ServoImpl class) enhanced with more features of the actual FTC SDK: ability to reverse direction and to scale position range.
CHANGES 10/6/2019 Added the option of using "Virtual GamePad" instead of real GamePad. To do this, go to the Config.java class in the virtual_robot.config package (within the Controller module), and assign "true" to the USE_VIRTUAL_GAMEPAD constant. Other constants in this class include the field image (BACKGROUND) and the field width in pixels (FIELD_WIDTH). If changing FIELD_WIDTH, need to supply a square bitmap (.bmp) field image that is FIELD_WIDTH pixels wide.
CHANGES 8/17/2019 RUN_TO_POSITION mode is now available for DcMotor, with setTargetPosition, getTargetPosition, and isBusy methods. Added 175 ms of latency to the BNO055IMU.
CHANGES 7/10/2019 To improve plug and play with OpModes copied and pasted from Android Studio, multiple packages were renamed. In addition, Continuous Rotation Servo capability was added. The XDrive Bot now has a CR Servo in the back rather than a standard servo. The XDriveBotDemo op mode demonstrates the use of this servo, using gamepad2.
NOTE: OpModes copied directly from Android Studio to Virtual Robot do not automatically compile when pasted into
Virtual Robot in IntelliJ, and won't show up in the OpModes dropdown box until they are compiled. Three different
methods to force compilation are: 1) Right click the file and select "Recompile"; 2) From the "Build" menu,
select "Rebuild Project"; or, 3) Make any change at all to the OpMode file (e.g., add a comment). Any one of these
methods is sufficient.
CHANGES 7/06/2019 Now uses @TeleOp, @Autonomous, and @Disabled class annotations to control the display of OpModes in the OpMode combobox. For @TeleOp and @Autonomous, a name parameter must be specified. The group parameter is optional (default group is "default"). GamePad setJoystickDeadzone capability contributed by FTC team 16072.
CHANGES 7/01/2019 Now supports two GamePads instead of just one. Use start-A and start-B to select gamepad1 and gamepad2, as you would in the FTC SDK. Two op modes for Mecanum Bot contributed by FTC team 16072, including a nice demonstration of field-centric drive using the IMU. These are in the org.firstinspires.ftc.teamcode.ftc16072 package.
CHANGES 6/25/2019 Contribution from Alan Smith (alan412): now supports "regular" op modes in addition to linear op modes.