# Setting Up The Virtual Robot Environment

In this lesson, we will be teaching you how to set up your very own Virtual Robot Environment in the JetBrains IntelliJ IDEA so you can simulate a robot’s OpModes within the comfort of your own home.

## Installing

### Installing Java SE Development Kit 8

This section may be skipped if you already have the Java Development Kit.

{% embed url="https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html" %}

Navigate to the link above and download the appropriate Java SE Development Kit 8u251 installer for your system.

![SE Development Kit Downloads](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F370d6e5f74be37f7fbf47454df3f1d48867379ee.png?generation=1592497325465237\&alt=media)

Next, run the installer and follow the instructions to install the JDK.

### Installing IntelliJ

This section may be skipped if you already have IntelliJ installed.

{% embed url="https://www.jetbrains.com/idea/" %}

Navigate to the link above and click on the download button in the middle left.

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2Fa17dba50704bb356bf4d408c3149e741f04f45cc.png?generation=1592497327501295\&alt=media)

Next, download the appropriate Community Version installer for your computer.

![Choose the Community Version to download.](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F4b98662e89d5090969e20d9d6f18d1111cd86427.png?generation=1592497319514086\&alt=media)

Run the installer and follow the instructions, accepting the defaults.

## Downloading the Virtual Robot Project

Next, we are going to download the Virtual Robot Project from Github. Go to the link below and click on the Clone or Download button.

{% embed url="https://github.com/Beta8397/virtual_robot" %}

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F892bc20f60afe2cc122ba326ea2a9f31bd0d4e8e.png?generation=1592497320376907\&alt=media)

Copy the web URL to your clipboard, and run IntelliJ IDEA.

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F1d3d529df3e9616224538d82c171684214395db0.png?generation=1592497326622496\&alt=media)

Create a new project by selecting “Check out from Version Control” and then selecting Git.

![Creating a New Project](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F75453cebb8c453b4eec6741de599cf4f7e44774e.png?generation=1592497330366462\&alt=media)

Paste the copied URL and press “Clone.” IntelliJ should open a new project. Next, try running the program by clicking on the green arrowhead in the upper toolbar.

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F22bea9d61fc14e8a27c913208cba77a90ce7a7c3.png?generation=1592497328244975\&alt=media)

## Setting Up The Virtual Robot Environment

Now we will be setting up the Virtual Robot Environment for this course’s use. First, navigate to the Config class on the left menu bar by opening `virtual_robot`, then `Controller`, then `config`. Double click on the `Config` class to open it.

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2Ff63c53cbeee5f459e4db41b2eee0f7d56fd586c6.png?generation=1592497321517059\&alt=media)

In the `Config` class, change the boolean `USE_VIRTUAL_GAMEPAD` to true.

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2Ff40ac98d4420cd42b5531d39d1b66412fc092d51.png?generation=1592497322574390\&alt=media)

Finally, navigate to the `MecanumDrivingOpMode` class - open `TeamCode`, `src`, `org.firstinspires.ftc.teamcode`, `ftc16072`, and then double click on the `MecanumDrivingOpMode` class.

Delete the contents of the `loop()` method. We will be writing our own version of this in Lesson 6.

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F73cdb0052bd095ad564409dfdb96ba5a58dd98a9.png?generation=1592497324435406\&alt=media)

Add the following fields to the `MecanumDrivingOpMode` class:

```java
private DcMotor motorFL = null;
private DcMotor motorFR = null;
private DcMotor motorBL = null;
private DcMotor motorBR = null;
```

Remove the fields `mecanumDrive` and `distances`. Your class should look something like this:

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2Ff67e06f0385624528b266f09280bb8c41302cf09.png?generation=1592497329351200\&alt=media)

We are now going to init the DcMotors using a special class that helps you retrieve hardware devices from configuration in code. That’s right: it’s `hardwareMap`! (Revisit the [HardwareConfiguration](../hardware-interaction/configuration) page for a quick reminder).

We want to initialize the front left motor, the front right motor, the back left motor, and the back right motor. These are all `DcMotors`, and their names have been written as `front_left_motor`, `front_right_motor`, `back_left_motor`, and `back_right_motor` in the configuration.

Try writing the init statements yourself now.

Done?

They should look something like this:

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2Fa28d35dd3bfd18a11aab5532f2495160bc508f69.png?generation=1592497323477220\&alt=media)

Recall that the hardwareMap class uses `.get()` to retrieve instances. Since we are initializing the `DcMotors`, we use `hardwareMap.dcMotor.get()`, and then place our motor’s name from the config in the parenthesis.

We want to use encoders for our mecanum drive, so let’s add these lines to our init method as well:

```java
motorFL.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
motorFR.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
motorBL.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
motorBR.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
```

Lastly, add these two lines to your init class:

```java
motorFL.setDirection(DcMotor.Direction.REVERSE);
motorBL.setDirection(DcMotor.Direction.REVERSE);
```

All together, it should look something like this:

![](https://1155679192-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkLnHres6iGYD61JT86%2Fsync%2F20482059301e721759edf9e4d4096be1249f8262.png?generation=1592497318447995\&alt=media)

Congratulations! You have set up your very own Virtual Robot Environment. In future lessons, we will teach you how to use it to simulate different OpModes, and you’ll learn how to write some yourself!
