# Franka

We assume that you have a NUC running with a [real-time kernel](https://frankarobotics.github.io/docs/libfranka/docs/real_time_kernel.html) as the Franka controller, and a separate workstation for policy inference, on the same network.

## Gripper hardware setup

Follow this guide to assemble the gripper: [Assembly Guide](https://nyu-gripper.pages.dev/robot-gripper)

Have the following materials ready:

* Download and print the [gripper mount](https://nyu-gripper.pages.dev/cad/Robot%20_Gripper/Franka_with_controller.stl)
* 4 M6 x 10mm Screws
* 4 M2.5 x 10mm Screws
* The [Dynamixel Starter Set](https://www.robotis.us/dynamixel-starter-set-us/), which includes parts 2-6 in the photo below:

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-c34d519c14f92acd5d398653eef4b24c95fde4d8%2FLabeledParts.jpg?alt=media" alt=""><figcaption></figcaption></figure>

1. Connect the Dynamixel Motor to the U2D2 Power Hub. You will hear a clicking sound when connected:

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-00ffe53b60d38905ed5b5a787112c4d19df330c3%2FMotor2PowerHubOutline.jpg?alt=media" alt="" width="563"><figcaption></figcaption></figure>

2. Connect the Power Hub to the U2D2 Board

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-0edaecb1855515c0cde52a41ccb2f9d0dbcc8223%2FU2D2ConnectionsOutline.jpg?alt=media" alt="" width="563"><figcaption></figcaption></figure>

3. Connect the U2D2 and your computer with the USB cable. A red light will turn on.

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-afd407d51d20bc587543ea522381408b18985e16%2FU2D2On.jpg?alt=media" alt="" width="563"><figcaption></figcaption></figure>

4. Plug the 12V 5A power supply into the U2D2 Power Hub board and switch on the power. A red LED should turn on.

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-7f3181b7da23f675a788199dff4ceec74c9ad90e%2FU2D2PowerHubOn.jpg?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Go to the `robot-server` directory and run this script to initialize the gripper:

```bash
cd robot-server
python gripper_init.py
```

5. **Attach gripper to the mount** with M2.5 x 10mm screws

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-b801662b5171ebdc9d90d22d46613b6d71ab8dc2%2FFrankaMountLabel.jpg?alt=media" alt="" width="375"><figcaption></figcaption></figure>

6. **Mount your 3D printed franka mount** with M6 x 10mm screws

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-b2f3ea8eb4a387cb561f6127a16f72494dfb084f%2FFrankaMounted.jpg?alt=media" alt="" width="375"><figcaption></figcaption></figure>

## NUC Set-Up

1. **SSH into the NUC** hosting your Franka.

```bash
ssh -o LogLevel=ERROR -D 1337 user@nuc_IP
```

```
Host nuc
    HostName (nuc_IP)
    User ???
    LogLevel ERROR
    DynamicForward 1337
```

2. Setup Deoxys, select **0.13.3 for libfranka when prompted**

```bash
git clone git@github.com:NYU-robot-learning/deoxys_control.git
cd deoxys_control/deoxys

# Instructions from deoxys repo (this takes a while to build everything)
./InstallPackage
make -j build_deoxys=1
```

3. Input necessary IPs into the following config

```
./deoxys_control/deoxys/config/franka_config.yml
```

```yml
PC:
  NAME: "lambda"
  IP: ??? ## <<<<<<

NUC:
  NAME: "nuc"
  IP: ??? ## <<<<<<
  PUB_PORT: 5566
  SUB_PORT: 5565
  GRIPPER_PUB_PORT: 5568
  GRIPPER_SUB_PORT: 5567

ROBOT:
  IP: ??? ## <<<<<<
...
```

4. Run the following from the **deoxys** directory to start deoxys server.

* Errors will repeat until the next section is complete

```bash
./auto_scripts/auto_arm.sh config/franka_config.yml
```

## Franka Setup

1. **Setup and activate a proxy** in your browser (e.g., FoxyProxy on Firefox).
   * Example FoxyProxy config:

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-e7e85141fa5b2861504a16fbfc85ef7a53ebd839%2FFrankaProxy.png?alt=media" alt=""><figcaption></figcaption></figure>

2. **Connect to Franka Desk** using the Franka IP inputted into the config.

* Where the URL is, you'll see the input is an IP:

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-f0f324896cd9570fc423efd4034eea5018e86306%2FFrankaDeskLabel.png?alt=media" alt=""><figcaption></figcaption></figure>

3. **Unlock the joints** in Franka Desk (open lock icon under the Joints tab).

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-f4977b99d9741efc74fca16dccaa681b0117a78a%2FFrankaDeskUnlock.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

4. Set **Execution mode** (bottom-right in the UI).

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-8327a13208d6e9121bbbbc86e9781a0385b59765%2FFrankaDeskExecution.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

5. **Activate FCI mode**:

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-d2ff6a6ec84a500edd9336c5e0c40c4dfa3514c0%2FFrankaFCIOptions.png?alt=media" alt=""><figcaption></figcaption></figure>

* Click the **IP** (top-right) → **Activate FCI Mode**. The arm indicator should turn **green (Not guaranteed for all versions of Franka)**:

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-bdb4a6d0bc74175e14084d66c421415ba40e4379%2FFCIActive.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

6. Review NUC SSH terminal that errors have stopped.
7. Download the Franka gripper profile below

{% file src="<https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-fb712c620b79fbc1b015b6af6ec0c5431d07d873%2FNrum.endeffector-profile.zip?alt=media>" %}

8. Head to Settings in Franka Desk

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-c9ef5b2d5fcf9b9c6fdf3362a58bcdb1c38c3787%2FFrankaDeskSettingsLabel.png?alt=media" alt="" width="900"><figcaption></figcaption></figure>

9. Click on End Effector

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-1ec58cbcdcea94fb6e4fb67d43b7bf4a5dfa3750%2FFrankaSettings.png?alt=media" alt="" width="900"><figcaption></figcaption></figure>

10. Import the JSON from the downloaded zip

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-2a83697941e7bbb5292ebb794db55c7246e780ba%2FFrankaGripperImport.png?alt=media" alt="" width="900"><figcaption></figcaption></figure>

11. Activate the Gripper Profile

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-c50f644c2661623364d1a7b94dc2900042bb273c%2FFrankaGripperProfile.png?alt=media" alt="" width="900"><figcaption></figcaption></figure>

## Deploying a Trained Policy

1. **Set up the iPhone** on the robot:
   * Slide the iPhone into the gripper mount until the camera block hits the mount, then tighten the knob (snug, not over-tight).

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-184645ce56c7cfecbc277e671ba47c4a07e33c2e%2FFrankaPhone.jpg?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* Connect the iPhone to the robot via USB.

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-cb995a61ef840cbda4c1c1f7ff5e5f6d71e727c6%2FFrankaUSB.jpg?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* In **Record3D** app settings: set **RGBD Streaming** mode to **USB** and **FPS** to **30**.

<figure><img src="https://1062622575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhk470ucohNkzUZJCG1We%2Fuploads%2Fgit-blob-b3abb1c5dfbb0046a12112a24feeabe39eaee598%2Frecord3D_optionsOutline.PNG?alt=media" alt="" width="375"><figcaption></figcaption></figure>

* Press **Record** to enter “stream-ready” mode.

Unless otherwise specified, the following steps assume that we are in the `min-stretch` repo root directory. 2. Set up Deoxys

```bash
git clone git@github.com:NYU-robot-learning/deoxys_control.git
conda activate home_robot
cd deoxys_control/deoxys

# Instructions from deoxys repo (this takes a while to build everything)
./InstallPackage
make -j build_deoxys=1
pip install -U -r requirements.txt
pip install -e .
```

3. Edit the following config and input necessary IPs

```
./min-stretch/robot-server/robot/franka/deoxys_utils/configs/franka_config.yml
```

```yml
PC:
  NAME: "lambda"
  IP: ??? ## <<<<<<

NUC:
  NAME: "nuc"
  IP: ??? ## <<<<<<
  PUB_PORT: 5566
  SUB_PORT: 5565
  GRIPPER_PUB_PORT: 5568
  GRIPPER_SUB_PORT: 5567

ROBOT:
  IP: ??? ## <<<<<<
...
```

4. **Calibrate Gripper**:

   ```bash
   cd robot-server
   conda activate home_robot
   python auto_calibrate_gripper.py
   ```
5. **Start the robot server**:

   ```bash
   python3 start_server.py controller=franka
   ```

   This starts streaming images from the iPhone and the robot begins listening for action commands. If you have missing imports, try `pip3 install hydra-core record3d` (and any other missing packages).
6. **Run the policy** in another terminal (requires display):

   ```bash
   cd imitation-in-homes
   conda activate home_robot
   python run.py
   ```
7. Head to the [Playbook](https://docs.google.com/document/d/1nq0DX-a31FvFr1TDDIrt1seIKJJO8ftYRcByZvWp9IE/edit?tab=t.0)

### Available Policy Checkpoints

When running `python run.py`, you can select from these preconfigured checkpoints:

* **`run_vqbet_pick`**: default checkpoint for picking task.
* **`run_vqbet_open`**: default checkpoint for opening task.
* **`run_vqbet_close`**: default checkpoint for closing task.
* **`run_vqbet_pick_exp`**: experimental pick checkpoint.

Choose the config that matches your task and substitute it in:

```bash
python run.py --config-name=<one_of_the_above>
```

***
