Skip to content

Commit

Permalink
DepthAI local testing instructions for static IP (#10)
Browse files Browse the repository at this point in the history
Updated depthai camera local testing to include instructions for static IP
  • Loading branch information
vedarshshah authored May 3, 2024
1 parent b3e27c1 commit b55517e
Showing 1 changed file with 49 additions and 27 deletions.
76 changes: 49 additions & 27 deletions computer_vision/depthai_camera_local_testing.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,87 @@
# DepthAI Camera Local Testing

The following instructions provide a step-by-step guide to setting up the hardware and software required to test the DepthAI camera locally.
The following instructions provide a step-by-step guide to setting up the hardware and software required to test the DepthAI camera locally. A router is not required if the Linux computer's wired network profile is setup correctly (see step 2 under [Software](#software)).

## Hardware
* PoE ethernet switch, with following items plugged into it:
* DepthAI Camera (#5 would be preferable; see step 7)
* Tenda router (plug into port 1, 2, or 3; do NOT plug into WAN)
* Asus laptop
* Optional: your laptop
* Linux computer
* Optional: Tenda router (plug into port 1, 2, or 3; do NOT plug into WAN)
* Optional: Your computer

## Software

> [!ATTENTION]
> Perform all steps on Asus laptop (or via SSH on Asus laptop; see [Tips](#tips)).
> Perform all steps on Linux computer (or via SSH on Linux computer; see [Tips](#tips)).
1. Check that the camera is connected and has received an IP address from the router’s DHCP server.
1. Setup wired network profile on Linux computer for static IP. *If you are using a router, skip this step.*
1. Open Settings > Network.
2. Click the plus sign next to "Wired" to add a new wired connection.
3. Under Identity, name the connection "DepthAI Camera" or something similar.
4. Under IPv4, set the method to "Manual".
5. Under IPv4 > Addresses, add the following:
* Address: `169.254.1.10`
* Netmask: `255.255.0.0`
* Leave Gateway blank.
6. Click "Add".
7. Click on the new profile to select it. A checkmark should appear next to its name, meaning it is now being used.
8. **After this is setup once, for every future setup, you do NOT need to recreate the profile. You only need to ensure that the profile you created is selected in network settings.**
8. For the rest of the steps use the following IP addresses:
* Linux computer: `169.254.1.10`
* Camera: `169.254.1.222`
2. Ensure wired network profile on Linux computer is set to obtain IP from DHCP server. *If you are not using a router, skip this step.*
1. Open Settings > Network.
2. Click on the wired connection profile with a checkmark next to it.
3. Under IPv4, set the method to "Automatic (DHCP)".
4. Click "Apply".
5. Ensure that the profile with the checkmark next to it is the one you just edited.
3. Check that the camera and Linux computer are connected and have received an IP address from the router’s DHCP server. *If you are not using a router, skip this step.*
1. Open a web browser, and go to `192.168.1.1`. You should see the Tenda router’s administrative interface.
2. Open “Parental Controls” and check the “Attached Devices” list. You should see two (or three if your laptop is connected). The laptop(s) will be labeled with proper names (the Asus laptop is called “dukerobotics-laptop”). **Record the IP address of dukerobotics-laptop.**
2. Open “Parental Controls” and check the “Attached Devices” list. You should see two (or three if your laptop is connected). The computer(s) will be labeled with their hostnames (run `hostname` in the terminal or command prompt of a computer to find its hostname). **Record the IP address of the Linux computer.**
3. There should also be a device labeled “Unknown” – this is the camera. **Make sure you can see the camera here before proceeding. Record the camera’s IP address.**
4. If you don’t see the camera here:
1. Unplug and replug the camera.
2. Go back and forth between the “Parental Controls” tab and the “Bandwidth Control” tab until the camera appears in the list of devices.
2. Make sure you can ping the camera.
4. Make sure you can ping the camera.
1. Open a terminal. Run `ping <camera-ip-address>`.
2. Make sure you get a response. If you don’t, unplug and replug the camera and try again.
3. Optional, but highly recommended: Open `robosub-ros` in VSCode.
4. In a terminal, run the following command to start the docker container:
5. Optional, but highly recommended: Open `robosub-ros` in VSCode.
6. In a terminal, run the following command to start the docker container. If `robosub-ros` is not located in the user's home directory, replace `~/robosub-ros` in the command with the correct path.
```bash
docker run -td --privileged --net=host -e ROBOT_NAME=oogway -v /home/duke-robotics/robosub-ros:/root/dev/robosub-ros -v /dev:/dev dukerobotics/robosub-ros:onboard
docker run -td --privileged --net=host -e ROBOT_NAME=oogway -v ~/robosub-ros:/root/dev/robosub-ros -v /dev:/dev dukerobotics/robosub-ros:onboard
```
5. Update `ROS_IP`.
7. Update `ROS_IP`.
1. SSH into the container (you can do `ssh onboard`).
2. In the container, run the following command to edit the `setup_network.bash` file:`nano /opt/ros/noetic/setup_network.bash`
3. In the `nano` editor, change the value of `ROS_IP` to the IP address of dukerobotics-laptop.
3. In the `nano` editor, change the value of `ROS_IP` to the IP address of the Linux computer.
4. Save the changes (`Ctrl + X`, then `Y`, then `Enter`)
6. Confirm new `ROS_IP`.
8. Confirm `ROS_IP` was updated.
1. Open a new terminal and SSH into the container.
2. Run `echo $ROS_IP`.
3. Confirm that the value returned is the IP address of dukerobotics-laptop. If not, the changes to the `setup_network.bash` file weren’t saved. Perform step 5 again.
3. Confirm that the value returned is the IP address of dukerobotics-laptop. If not, the changes to the `setup_network.bash` file weren’t saved. Perform step 7 again.
4. Close the previous terminal (that you ran `nano` in). All new terminals will have the updated `ROS_IP`.
7. Update camera’s MAC address in our code.
1. For camera #5, this is `44:A9:2C:36:E0:11`
9. Update camera’s MAC address in our code. *If you are not using a router, skip this step.*
1. Known MAC addresses:
- Camera #4: `44:A9:2C:3C:3D:85`
- Camera #5: `44:A9:2C:36:E0:11`
2. If you are using a different camera, you will need to find its MAC address. In a new terminal, (outside the container) run `arp -n`. Find the line corresponding to the camera’s IP address, and copy the MAC address in that line. **It is strongly suggested to record this MAC address in a permanent location, along with the camera number, as it never changes throughout the lifetime of the camera.**
3. In the code currently on `master`, replace the MAC address on line 100 in `depthai_camera_connect.py` with the new MAC address.
4. In the updated CV refactoring code, change this in the appropriate YAML file.
8. You can now launch a DepthAI node, and it will connect to the camera.
10. You can now launch a DepthAI node, and it will connect to the camera.

## Explanation
- The Tenda router runs a DHCP server that assigns IP addresses to all devices on the local network (any device plugged into the switch). We first make sure it has recognized the camera and assigned it an IP address.
- We run the Docker container using host networking – this means that the Docker container’s network isn’t isolated from the host computer’s network, allowing the container to access the camera. Host networking is only available on Linux hosts, hence the Asus laptop is required.
- By default, the onboard Docker container’s IP address is set to 192.168.1.1. Since we are using host networking, the onboard container’s IP address is the same as the host computer’s IP address. This is usually fine, as the robot computer’s IP address is always 192.168.1.1. However, in this situation, that IP address belongs to the Tenda router; the router provides the Asus laptop with a different IP address. Thus, we change `ROS_IP` to the IP address of the Asus laptop.
- The router runs a DHCP server that assigns IP addresses to all devices on the local network (any device plugged into the switch). We first make sure it has recognized the camera and assigned it an IP address.
- If there is no DHCP server on the network (which is the case when there you are not using a router), the camera automatically assigns itself the IP address `169.254.1.222`. We ensure that the Linux computer has an IP address in the same subnet `169.254.1.10` and the netmask is set to `255.255.0.0` to allow communication between the two devices.
- We run the Docker container using host networking – this means that the Docker container’s network isn’t isolated from the host computer’s network. This is required to allow the container to access the camera, as indicated in the [DepthAI documentation](https://docs.luxonis.com/projects/api/en/latest/install/#docker). Host networking is only available on Linux hosts, hence a Linux computer is required.
- By default, the onboard Docker container’s IP address is set to `192.168.1.1`. Since we are using host networking, the onboard container’s IP address is the same as the host computer’s IP address. This is usually fine, as the robot computer’s IP address is always 192.168.1.1. However, in this situation, that IP address belongs to the router – the router provides the Linux computer with a different IP address – or the computer is using an IP address beginning with `169.254`. Thus, we change `ROS_IP` to the IP address of the Linux computer.
- The `setup_network.bash` file is sourced in `~/.ros_bashrc` inside the container; `~/.ros_bashrc` is a file we have created that is configured to be sourced every time you open a new terminal and SSH into the container. Thus, after the `ROS_IP` environment variable is changed in in `setup_network.bash`, the change is in effect for all new terminals (except the original terminal that we edited the file in and any terminals created before).
- Our code connects to the DepthAI camera by finding the IP address corresponding to its MAC address, hence we need to update the MAC address the code searches for. The MAC address is burned into the ROM of the camera’s ethernet adapter – hence, it never changes for the lifetime of the camera.
- Our code connects to the DepthAI camera by finding the IP address corresponding to its MAC address, hence we need to update the MAC address the code searches for. The MAC address is burned into the ROM of the camera’s ethernet adapter – hence, it never changes for the lifetime of the camera. This is only necessary if you are using a router; if you are not using a router, the code already attempts to connect to the static IP address.

## Tips
- To copy/paste in the terminal on Linux, use `Ctrl + Shift + C` and `Ctrl + Shift + V`. To copy/paste anywhere else, use `Ctrl + C` and `Ctrl + V`.
- If you prefer to work on your laptop, you can SSH into the Asus laptop to perform these steps.
- Connect your laptop to the ethernet switch.
- Perform step 1 to obtain the Asus laptop’s IP address, then run `ssh duke-robotics@<ip-address>`.
- You can also SSH via VSCode.
- On the Asus laptop, close any windows you don’t need to maximize performance.
- If you prefer to work on your laptop, you can SSH into the Linux computer to perform these steps. It may be useful to SSH via VSCode.
- If you are using the Asus laptop, close any windows you don’t need to maximize performance.
- If you are not using a router, comment out all parts of `depthai_camera_connect.py` that attempt custom autodiscovery and DepthAI autodiscovery; keep only the part that connects to the camera using the static IP address. This will speed up the connection process.

## Troubleshooting
- When performing a ROS launch, you get “RLException: Unable to contact my own server at…”
Expand Down

0 comments on commit b55517e

Please sign in to comment.