# How to calibration the camera system

On the computer Coover 3050-07, open the Tracking Tools program. Make sure you have all the tools required which include a 
wand and ground plane component. These are usually kept on top of the cabinets in the corner of Coover 3050. In addition to 
these instructions see the [DANC wiki page](https://wikis.ece.iastate.edu/distributed-autonomous-and-networked-control-lab/index.php/Distributed_Autonomous_and_Networked_Control_Lab_Wiki)
which may have more information as well as the [OptiTrack Wiki](https://v20.wiki.optitrack.com/index.php?title=Calibration).

All steps take place on the OptiTrack - Tracking Tools software on the Coover 3050 computer co3050-07.

Below shows the OptiTrack - Tracking Tools Software on initial opening, many of the steps will refer to actions that can be seen
on this image.

![alt text](./images/OptiTrack_Tracking_Tools.PNG "OptiTrack - Tracking Tools")

1. Open up a new project with "New Project" button, directly under File drop down menu. Or navigate to "File->New".
2. If the "3-Marker Calibration" window is shown on the screen, usually on the right side, continue to next step. 
   If not go to "Tools->3-Marker Calibration".
3. Now that the 3-Marker Calibration tool is open make sure to remove as much of the IR disturbance as possible, 
   more disturbance leads to worse calibration. Usually you need to ensure all window blinds are down and that 
   all IR reflective components (like the Quad) are out of the camera system view.
4. After as much of the IR reflective components are removed from view click "Block Visible" in the "3-Marker Calibration" 
   window to remove the left over spots.
5. Before you start wanding check that the following configuration options are set.
    * Quality -> Very High
    * OptiWand -> Large (500mm)
	
6. Click "Start Wanding", directly next to the "Block Visible" button in the "3-Marker Calibration" window.
7. This step will take awhile (approx. 10 minutes) as you wand the entire area of the camera system. Make sure to get at least 5000 samples
   for each of the cameras. Try not to exceed 10,000 samples as this can lead to worse calibration results. Walk around the camera area moving
   the wand in a variety of different movements to try to cover the full camera volume.
8. After sufficient samples have been taken click "Calculate" within "Calibration Engine" and wait until all cameras have exceptional
   listed next to them before continuing. This process takes 5-6 minutes on average.
9. Click "Apply Results" then "Apply" when the next windows comes up. It will prompt you to save a timeline, just click "Save".
10. The next step is to set the ground plane. This window should be automatically switched to after you save, but if not you can switch at the 
    top of the window within the "3-Marker Calibration" window by clicking "Ground Plane".
11. Set up the ground plane component as shown in the window above. The Z direction should point towards the ceiling, X direction towards the 
    white boards, and the IR balls should be facing towards the door. If you lift up the carpet tiles you can use the lines on the floor to
	orient the piece in the correct X direction. Additionally, the levels in the lab may help with this process to get the best results.
	
	![alt text](./images/CameraGroundPlane.jpg "Camera Ground Plane")

12. Once everything is set, check that the "Vertical Offset (mm)" is set to 55, this value can be measured with a meter stick and it
    is the distance from the ground to the height of the lower IR ball. Next, click "Set Ground Plane". This will prompt you to save a 
	file, just click "Save".
13. Save the project, with the "Save Project" button or go to "File->Save Project".
14. The last step is to enable streaming to VRPN. If you test the backend within the ground station directory without the following steps
    to complete it will not connect to the VRPN system.
15. The OptiTrack Tracking Tool software support streaming to VRPN go to "View->Streaming Pane".
16. In the "Streaming Properties" windows enable "Broadcast Frame Data" within "VRPN Streaming Engine" and ensure that the 
    "VRPN Broadcast Port" is 3883.
17. Save the project, and you are now done!