Welcome to Inverse Polarity's tutorial on how to set up FRC vision on a Raspberry Pi. The instructions below can help anyone with limited programming experience set up a robot vision system for detecting AprilTags. Also included in the doc folder are two presentations. AprilTag Vision Presentation gives a general overview of AprilTags and briefly describes our solution. Vision Distance Calculation is an overview of how to calculate the distance to a target given several constants.
- Follow these instructions to set up the Raspberry PI
- Stop at the end of the Installing the image to your MicroSD card section.
- Connect the pi to ethernet and power
- Make sure your computer is on the same network as the pi. The easiest way to ensure this is by connecting both the pi and the computer to the same router.
- Type http://wpilibpi.local/ into your browser to interface with the web dashboard.
- If the dashboard doesn't show up, you may need to connect a monitor and keyboard into the raspberry pi, and log in. However, if it did show up, skip to step 4.
- Username:
pi
- Password:
raspberry
- Username:
- type
ifconfig
(prints out the IP address).- The ip address should be after the word "inet"
- Ex: inet 192.168.0.196
- Type the ip address directly into your browser search bar.
- If the dashboard doesn't show up, you may need to connect a monitor and keyboard into the raspberry pi, and log in. However, if it did show up, skip to step 4.
- Configure your Raspberry PI
- Read more about the web dashboard here.
- Click Writable at the top: MAKE SURE TO KEEP AS WRITABLE THE WHOLE PROCESS
- Go to the Vision Settings tab of the web dashboard, type in your team number, and save.
- Add the python application
- In the Application tab, select the Uploaded Python file option and upload the pythonVisionApp.py
- In the upload file section of the Application tab, upload the runCamera file.
- Interface with the PI
- There are two ways you can interface with the pi. The easiest to set up is to follow the instructions listed in step 3. section i.
- The alternative is to download Git Bash, which will allow for remote connection to the pi from your computer.
- Once downloaded, type in
ssh [email protected]
into the terminal to remotely connect to the pi. - Log in with the same credentials listed in step 3) i.
- Once downloaded, type in
- Learn how to navigate a linux terminal
- Follow this tutorial to learn how to use Linux
- Make sure the system clock is up to date
- Type
date
into the pi or Git Bash to read out what the system thinks is the current date and time. If it's correct, you can skip to step 10. If it is incorrect, continue to step 9.
- Type
- Update the system clock
- Type these instructions (insert the correct date for step C. "Year-Month-Day Hour:Minute:Second").
sudo bash
timedatectl set-timezone America/New_York
timedatectl set-time "2023-01-03 16:27:00"
apt install ntpdate
service ntp start
- Type these instructions (insert the correct date for step C. "Year-Month-Day Hour:Minute:Second").
- Organize the file structure (REMEMBER: make sure the pi is set to Writable)
- Type these instructions.
mkdir python-app
mv pythonVisionApp.py python-app/
chmod 755 runCamera
- Type these instructions.
- Download the AprilTag library
- Type these instructions.
apt update
apt upgrade
shutdown -r now
- At this point, the pi will have shut down, so remove and re-insert the power cable to reboot.
- Log back in and set the system to Writable via the web app.
- Type these instructions.
sudo apt install git
sudo apt install cmake
sudo apt-get install python3-opencv
mkdir apriltagCode
cd apriltagCode
git clone https://github.com/AprilRobotics/apriltag
cd apriltag
cmake .
make
sudo make install
make apriltag_demo
- Type these instructions.
- Configure the python application
- Read up on the VI editor
- ONLY IF you want to simulate the robot on a driver station, then you need to enter your computer ip address into the python program. However, if you plan on setting the pi up directly on the robot, skip to step 12) iii.
- Navigate into the python-app folder.
- Start editing the pythonVisionApp.py by typing
vi pythonVisionApp.py
- On line 51, set
usingComputerIP
toTrue
- On line 112, set
ip
to your computer's ip address.- On Windows, find your ip by opening Command Prompt and typing
ipconfig
- On Mac, find your ip by opening Terminal and typing
ifconfig
- On Windows, find your ip by opening Command Prompt and typing
- On line 51, set
- To specify which variables you want published to NetworkTables, add additional lines to the code:
- Search
Data published for Apriltags
to find the start of data published for Apriltags - Search
Data published for Color
to find the start of data published for Color
- Search
- If you wish to calculate the distance to a target, move onto step 13.
- Otherwise search
Distance Calculation Constants
, set all following ten numbers to 1, and skip to step 14.
- Otherwise search
- Calculate the distance to a target
- Read up on calculating distance to a target.
- search
Distance Calculation Constants
and fill in the five empty lists.- vertFOV is the vertical field of view of the camera.
- Calulate vertFOV by facing the camera toward a wall (making sure it's flat).
- Measure the distance from the camera to the wall (We will call this
adjacentDistance
). - Mark on the wall where the top and bottom of the camera feed ends (make sure they are along the same vertical line).
- Measure the distance between the two marks and devide that in half (We will call this
oppositeDistance
). - Take the inverse tangent of the adjacentDistance divided by the oppositeDistance.
- That's your vertFOV! Plug that into the pythonVisionApp.
- horizFOV is the horizontal field of view of the camera.
- Calulate horizFOV by facing the camera toward a wall (making sure it's flat).
- Measure the distance from the camera to the wall (We will call this
adjacentDistance
). - Mark on the wall where the left and right of the camera feed ends (make sure they are along the same horizontal line).
- Measure the distance between the two marks and devide that in half (We will call this
oppositeDistance
). - Take the inverse tangent of the
adjacentDistance
divided by theoppositeDistance
- That's your horizFOV! Plug that into the pythonVisionApp.
- elevationOfTarget is the height of the target from the ground.
- elevationOfCamera is the height of the camera from the ground. NOTE: This will need to be updated if it ever changes.
- angleFromHoriz is the angle the camera makes from an imaginary horizontal line. If it is facing straight forwards, angleFromHoriz would be 0. NOTE: This will need to be updated if it ever changes.
- vertFOV is the vertical field of view of the camera.
- View the video stream!
- Set up the pi on the robot.
- It requires a power input from the robot and an ethernet input from the radio.
- The camera needs to be plugged into one of the usb ports.
- Open Shuffleboard.
- In the top left corner, click on the two greater-than signs to expand the drawer.
- Click on the CameraServer menu.
- If visionCam shows up, right click and select Show as: Camera Stream. Wave an apriltag in front and see the program do its magic!!
- If it doesn't show up, restart the python program.
- Go to the Vision Status tab of the web dashboard (make sure you are connected to the robot's wifi).
- Toggle the switch on the far right of the Console Output to enble output.
- Press Kill to restart the program.
- If it still doesn't work, review the previous steps to make sure you followed directions exactly.
- Set up the pi on the robot.