Skip to content

Yaw and Pitch

Liam Lawrence edited this page Mar 16, 2017 · 3 revisions

Yaw and pitch are the values that we find in some simple equations to figure out how far our robot should turn in both the X and the Y plane to align itself with the goal.


Yaw and Pitch Calculations

Yaw, pitch and roll are used to tell us how many degrees in a certain plane we should move, we will only be focusing on the first two as (hopefully) your robot will not be tipping over onto its side. These can be seen in the diagram below.

ypr

We want to have an easy way to line our robots shooter up with the goal, this can easily be achieved by knowing only a few simple things about your camera.

  • Width in Pixels
  • Height in Pixels
  • Field of View (in Degrees)

To find how many degrees in each plane we need to turn, we first need to calculate our Pixels Per Degree, or PPD. This will allow us to see how many pixels off our shooter is, and convert that into useful data our robot can interpret. The equations are easy and can be seen below.

Used for Yaw

Horizontal PPD = (Camera FOV) / (Camera Pixel Width)

Used for Pitch

Vertical PPD = (Camera FOV) / (Camera Pixel Height)

In my case, this is just 75/640 and 75/480.

Now we compare the center of the goal relative to the center of the entire image frame to see how off we are, this can be done visually be looking at the orange dot (center of goal) and the white dot (center of the entire frame) in the image below.

PrestonHatesC++

Comparing these against each other allow us to see how many degrees our robot should turn in each direction to perfectly align with the target. The equations for this are as follows.


Center.x is the X coordinate of the goal (orange dot) and imageWidth is how many pixels wide our frame is (in my case, 640)

yaw = ((center.x - ((imageWidth / 2) - 0.5)) * horizontalDPP);

Center.y is the Y coordinate of the goal (orange dot) and imageHeight is how many pixels tall our frame is (in my case, 480)

pitch = ((center.y - ((imageHeight / 2) - 0.5)) * verticalDPP);

With this information we can now have our robot turn to align itself with the goal!