# Connecting to the physical robot

<!-- TODO move this to tools -->
## Establishing network connection to the robot

1. Take an Ethernet cable and connect it to your computer and to the network port through which you can access the robot you want to control. You will probably need a USB-Ethernet dongle. If there is a connection, you should see blinking lights on the Ethernet port.

1. After connection your internet access may be lost, if the robot network is not connected to the internet and if your computer tries to route internet packets through the robot network. 

   To fix this, you can delete the corresponding route using:

   ::::{tab-set}

   :::{tab-item} MacOS
   - `System Settings → Network`
   - Click `three-dot menu` at the bottom. It shows up if you have multiple interfaces
   - Click `Set service order...`
   - Drag `Wi-Fi` to the top, so that `Wi-Fi` is used to access the internet instead of the dongle.
   - Confirm settings and exit settings
   :::

   :::{tab-item} Windows
   start `Command Prompt` with administrator rights and use:
   ```sh
   route delete 0.0.0.0 mask 0.0.0.0 172.20.254.254
   ```
   :::

   :::{tab-item} Linux
   ```sh
   sudo ip route delete default via 172.20.254.254
   ```

   - `enp0s13f0u3` is the interface name which you used to connect to the robot network.
   - `172.20.254.254` is the gateway address
   - `default` or `0.0.0.0` is the network destination for the packets. `default` stands for all packets which do not fit to the other entries in the routing table, which are typically internet packets.

   *alternatively*: `sudo ip route delete default` will delete the last added default route, which should be the robot network route.
   :::

   ::::

## Testing connection to the physical robot

1. Switch the robot on using the pendant and wait for PolyScope to boot
1. Test whether you can reach the robot. Open a terminal in MacOS and:

  ```sh
  ping IP-ADDRESS
  ```
  If you get messages as follows, then the robot is accessible:
  
  ```text
  64 bytes from IP-ADDRESS: icmp_seq=1 ttl=56 time=2.92 ms
  64 bytes from IP-ADDRESS: icmp_seq=2 ttl=56 time=2.79 ms
  ...
  ```
:::{card} Troubleshooting
Methods:

Symptom:
- Robot is not accessible

Solution:
- Check your network dongle. Its LEDs should blink. The cables wear off easily and the contacts may not be reliable. Hold it still to test the cable's reliability.
:::

Now we will test network connection from Rider
1. Open a terminal in Rider use the same `ping` command
1. You should get the same output as above.


(macos-blocked-network-access)=
:::{card} Troubleshooting
Symptom:
- you use MacOS
- you use Rider
- you can ping the robot using MacOS terminal
- you **cannot** ping the robot using Rider terminal

Solution:

MacOS blocked the network access. Go to `System settings → Privacy & Security → Network`. Activate local network access for `Rider`.
:::

## Finding a pose that the robot can reach

1. On the pendant use the button on its back to move the gripper to the desired pose.
1. In PolyScope click `Move`.
1. Click `Feature` drop-down menu and select `Base`.

   `Base` frame is located on the working area.

1. Copy the [test code](sending-a-program-to-the-robot) in your editor.
1. Read the pose like we have done [previously using the simulator](pose) and enter the pose/s in the program.


## Running the test program

1. On the pendant, look to the upper right of the screen and search for the icon:

   :::{image} ../img/polyscope-local-connection-symbol.png
   :::

   Switch the robot to `Remote` control mode, if `Local` mode is selected.
   
1. Set up the IP address. We used `localhost` (address of your computer) to connect to the simulator. Replace this with the IP address of the robot. You find the address on the robot arm on a sticker.


:::{card} Troubleshooting
Symptom:
- MacOS
- the test program worked for one or two times but then the program errors out with a message like `cannot reach address [ffff::172...]`

Solution:
- MacOS blocked network access. Activate it according to the instructions in the [above troubleshooting box about MacOS blocking the network](macos-blocked-network-access).

Symptom:
- The pendant errors out with `kinematics solution cannot be found`

Solution:
- pay attention that you read a pose while `Feature` was `Base`. If `Feature` was view, then the pose may be incorrect.
:::