Calibrating Camera Angle Offset - northern-bites/nbites GitHub Wiki

Intro

Calibrating a robot provides the roll and pitch offsets (IN RADIANS) of the top and bottom cameras, so a total of four values for each robot. Calibration values are stored in src/man/config/calibrationParams.txt.

How to Calibrate

There are two parts to calibrating robots, the robot and the tool.

Robot

  1. Install the pCalibrate player with logging on to the uncalibrated robot.
  2. Set up the robot about 500cm away perpendicular to a black line on BlackStar. This number does not have to be exact and you might have to move the robot later to get a calibration success.
  3. Now the robot is ready to be calibrated! Proceed to tool.

Tool

Step 1: Setup

  1. Open nbtool (version 8) and nbcross. {always make sure nbtool is completely open before starting nbcross.}
  2. Hit L to open the view utility. Under the tripoint folder, make sure CalibrateView is checked. Now close that window.
  3. Change the robot's name to the uncalibrated robot and change don't stream to stream: all tripoint
  4. Hit connect.
  5. Switch tripoint from false to true and switch 'state_playing_override' from false to true

Once you have completed all for steps, the CalibrateView should be open and indicating if the logs was a success or a failure, and the robot should be panning slowly. If so, proceed to calibration.

Step 2: Calibration

  1. Hit 'o' to receive the offset calibration utility. (or 'c' depending on the version of the tool')
  2. Hit 'go!' to determine if at least 15 logs have been used to calibrate and the status is good. You need to hit 'go' again to refresh the utility pane.
i. if the status is bad, change the robots position, so that it is either closer or farther from the star. Knowing which to do comes with practice and there is no right answer!

ii. if the status is good, then change state_penalty_override from false to true to get bottom logs. 3. Once you have good parameters, hit 'save to config file' to save the parameters to the config file.
4. Congrats! You have calibrated the camera angle offsets for this robot! 5. Once you are done calibrating all the robots needing calibration, please 'git diff' the file to make sure all the robots have been calibrated. Then you can commit and push! Well done on your hard work!

#Logistics(not updated)

BlackStar

"BlackStar" is the 1.3 meters squared poster of 4 black lines at 45 degree angles. BlackStar should be as flat as physically possible. Position the robot about 1.2 meters from the center of the star, aligned with one of the black lines.

pCalibrate

pCalibrate is a player state written specifically for calibrating from BlackStar. In Game Playing, the robot will tilt its head so the top camera can see the whole mat (if setup correctly). The robot pans very slightly and slowly, moving two degrees and then stopping for one second. After seven of these, it starts again. In Penalized, the robot tilts way back and does the same for the bottom camera.

Every second, the robot logs one image (one top per second if in playing, one bottom if in penalized). Take at least 7 logs of each top and bottom.

Valid Logs

A valid log is one were there are exactly three valid field lines. A valid field line is a field line (comprising of two hough lines) that are not horizontal (or very close to horizontal) in the image and are sufficiently long. These three lines are intended to be the BlackStar line pointing directly at the robot, and the two next to it.

The Camera Calibration Utility 3

The utility used to generate and save calibration params is located in the tool in the misc tab, under utilities. Select the folder of the calibration logs and click the button in this pane or just type "c" or "cc" in the tool. It will display a table containing the robot name, which camera, the status of the calibration, roll, tilt, how many logs were given and used. Hit "go!" to search through all of the logs taken in this session to get the accurate parameters. I would suggest going way over 7 logs to improve accuracy.

The code needs to be reinstalled for the scrimmage or game or whomever wants a calibrated robot. In short, when the Vision Module is constructed the robot looks up its params in that text file, and uses them until man stop. Getting calibration values, and even saving them to the text file, DOES NOT mean the robot is actually calibrated. Have the installer cherry-pick the commit and reinstall. This might get changed in the future, so stay tuned.

Potential Errors

Sounds pretty simple. But..

Vertical Hough Lines

The hough line finder has a bug that causes it to miss lines that are nearly vertical in the image. This means that in calibration only two lines will be detected sometimes. A short term solution is to calibrate from just off of center so there are no truly vertical lines. A better solution would be to work with Bill Silver to find that damn bug!

False Valid Line

When you are calibrating for the first time or in a new place, look through all the logs with LineView open and nbcross running. (It is recommended that as you stream them you look at this view as well to ensure good logs.) Make sure there are no field lines not on BlackStarr. They will wreck calibration. Make sure all three lines that we want are detected.

Other Bugs

Sometimes the VisionModule, probably because of errors in the way the tool or nbcross is written, will act strangely, not pairing field lines or not finding hough lines. There is a lot of work to be done. Because calibration needs to happen, work hard to squash those bugs.

Future Work

  • Find bugs mentioned above
  • SEND calibrationParams.txt over network to robot. Work with @PhilKoch
  • Change players on the fly (send the python file require to switch to pCalibrate over the network) If you can get the two things above working, calibrating will be super fast and super easy.
  • Send a variable amount of images to nbcross, and have it keep checking them until it finds seven valid images.

How it Works

The c++ code found in man/vision/Homography.cpp takes tries to find three valid field lines according to the standards discussed above. For each field line, it finds the intersection point of the hough lines that compose it. Because these lines should be parallel, the intersection point in image coordinates should be on the camera horizon. With three lines, it finds three points on the camera horizon. It then fits a line to the three points to calculate roll offset (angle of the line) and tilt offset (height of the line).

The tool passes logs internally between nbcross and nbtool. Logs that have three valid lines are sent back with calibration params in the description (S-Expression form).

The internal flag to take a log for a single frame (so that it doesn't stream tripoints like in other states) are set in the pCalibrate player code in behaviors. It is a sole environment variable which is inspected in the logImage() method in the Vision Module. Logs with with this flag have a "Black Star" tuple, which is used within the Vision Module during calibration to know to look for lines of reversed polarity (because these "field lines" go from light to dark to light, instead of dark light dark like a soccer field.

[email protected] with any questions!