Setting Up Pure Simulation¶
This section describes the software settings required to simulate the entire robot (including vision devices) with AdvantageScope.
MonarchVision Settings¶
Turn on simulation mode in Constants.java:
public static final Mode simMode = Mode.SIM;
Settings for Field Vision¶
If you are using vision devices to detect apriltags for determining the placement of the robot on the virtual field, edit the Java code as follows:
-
Turn off hardware-in-the-loop mode for apriltag detection in
FieldVisionConstants.java:/** Are we running a physics simulator, but with a real camera connected. */ public static boolean hardwareInTheLoop = false; -
If necessary, change
robotCamerasinFieldVisionConstants.javawhich defines the camera(s) on the robot to be used for detecting apriltags. EachCameraSpecspecifies the type of camera, its name, and its position and orientation relative to the center of the robot. In the example below, there are two Limelight cameras, one of the front and one on the back, both pointing up.// The following is a definition of all cameras on the real robot. These are also used // by simulation public static CameraSpec[] robotCameras = { new CameraSpec( VisionType.LIMELIGHT, "front_camera", new Transform3d( Constants.robotLengthInMeters / 2.0, 0.0, 0.2, new Rotation3d(0.0, -0.4, 0.0))), new CameraSpec( VisionType.LIMELIGHT, "back_camera", new Transform3d( -Constants.robotLengthInMeters / 2.0, 0.0, 0.2, new Rotation3d(0.0, -0.4, Math.PI))) };
Settings for Object Detection¶
If you are using vision devices to detect objects, edit the Java code as follows:
-
Turn off hardware-in-the-loop for object detection in
ObjectVisionConstants.java:/** Are we running a physics simulator, but with a real camera connected. */ public static boolean hardwareInTheLoop = false; -
If necessary, change
robotCamerasinObjectVisionConstants.javawhich defines the camera(s) on the robot to be used for detecting objects. EachCameraSpecspecifies the type of camera, its name, and its position and orientation relative to the center of the robot. In the example below, there is a single Rubik / PhotonVision camera on the front of the robot, pointing down.
// The following is a definition of all cameras on the real robot used for object detection.
// These are also used by simulation
public static CameraSpec[] robotCameras = {
new CameraSpec(
VisionType.PHOTONVISION,
"object_camera",
new Transform3d(
Constants.robotLengthInMeters / 2.0, // On front of robot
0.0,
Units.inchesToMeters(20.5),
new Rotation3d(
0.0,
Math.toRadians(35.), // Positive points down!!! See above.
0.))) // Facing forwards
};
Virtual Game Pieces¶
You can define the locations of virtual game pieces by editing the file fuel_layout.json which should be in the deploy/objectvision directory. Below is an example which which shows six fuel game pieces displayed on the virtual field, along the its associated .json file.
{
"gamePiecesArray": [
{
"className": "Fuel",
"fieldPositions": [
{
"x": 2.540,
"y": 1.453,
"z": 0.075
},
{
"x": 2.322,
"y": 1.560,
"z": 0.075
},
{
"x": 2.431,
"y": 1.781,
"z": 0.075
},
{
"x": 2.761,
"y": 1.894,
"z": 0.075
},
{
"x": 2.655,
"y": 1.671,
"z": 0.075
},
{
"x": 2.871,
"y": 2.009,
"z": 0.075
}
]
}
]
}