How to combine equations that are describing related physical phenomena?

320 Views Asked by At

A quick word about what is going on to put this question in perspective. I am trying to dock a robot onto a charger.

enter image description here

Sometimes the robot center is not in line with the charger center. Let's call this offset "centering error". A centering error that is larger than 2cm will not allow the robot to dock properly. For this reason knowing the "centering error" is very important for me.

enter image description here

The charger has a QR Barcode, that the robot takes a picture of and processes. This yields a lot of data, such as area of barcode, barcode edge lengths, center point coordinate of barcode in image, etc... I hope you know a bit about how computers store images, and that pixels have x and y coordinates. enter image description here

I am trying to merge mathematical relationships that represent existing physical relationships. I plotted key data, and matched it with suitable equations. Here are relationships I have “found”:

Relationship #1 The amount of area occupied by the barcode in the image is correlated to the distance between the robot and the charger. This relationship is shown in the graph below. The X axis shows the distance, and the Y axis shows the area of the barcode. For graph and equation see: https://www.desmos.com/calculator/oebhjbtp4q and shown below: enter image description here

Relationship #2 If the robot is exactly 30 cm away from the charger (Let's assume this to be a fixed, unchanging truth of Relationship #2). I have established a line equation between the "centering error" and the center pixel of the barcode relative to the image the camera is getting. In the graph below, the Y axis is the "centering error" in centimeters, and the X axis is the X value (of an x and y pair) of the center pixel of the barcode (center pixel has an x and y coordinate in the image.. just like all pixels in the image have an x and y coordinate). So, if robot is EXACTLY 30cm away from panel (and robot is square to charger AND Camera stays fixed relative to robot... just some assumptions that must be true), then the center pixel address of the barcode in the image the robot takes, tells me EXACTLY what my "centering error" equals. Not a bad relationship for a rube to find. No?

enter image description here

Relationship #3 If the robot is exactly 60cm away, I get a line with a slightly different slope and Y intercept compared to the 30cm relationshop. The pink line is the 30cm line, and the green line is the 60cm line. So, if I'm exactly 60cm away, I'll know exactly how much "centering error" I exists. Both lines and equations can be found here: https://www.desmos.com/calculator/mulkeviown enter image description here

My problem: I could get the line equation for all the possible distances (1cm, 2cm, 3cm all the way to 60cm away), then use the area of the barcode to figure out how far I am away and choose the correct line equation to find the "centering error". That would be a very manual, hard, and ugly coding solution to the problem.

I am hoping to use the two line equations and the distance equation to generate one equation where I feed the following variables:

  • area of barcode (same as distance)
  • x coordinate of the center point of the barcode in the image

and get the correlated "centering error" value as a distance.

Any advice on how to do this? I am hoping to not have to get all 3D geometric on this challenge (plan B) as I think I have enough data and equations to solve this challenge.

1

There are 1 best solutions below

2
On

It's evident from your relationships $2$ and $3$, that the equation for the centering error, $\ ce\ $, in terms of $\ x\ $ and the distance $\ D\ $, has the form $$ ce=m(D)(345-x)\ . $$ without more details of the camera optics, it's impossible to know for sure what form the function $\ m\ $ takes, but it's possible that it might be given by the simple geometry illustrated in the figure below. This would give $$ \frac{ce}{D+d}=\frac{345-x}{e}\ , $$ or $$ m(D)=\frac{D+d}{e}\ . $$ Your relationships $2$ and $3$ then give $$ m(30)=\frac{30+d}{e}=0.086\\ m(60)=\frac{60+d}{e}=0.125\ , $$ which you can solve for $\ e\ $ and $\ d\ $: $$ e=\frac{10}{0.013}\\ d=\frac{0.125\times10}{0.013}-60\approx36.15\ , $$ thus giving $$ ce=0.0013(D+36.15)(345-x) $$ as the equation for $\ ce\ $ in terms of $\ x\ $ and $\ D\ $. The fact that $\ e\ $ turns out to be much larger than $\ D+d\ $ for the values of $\ D\ $ you're interested in, makes me doubt that the equation's likely to be helpful. Are you able to check whether it actually works?

I don't see how you could possibly do what you want unless you can get a formula for $\ m(D)\ $, or at least one which gives a sufficiently close approximation to it. If you assume $\ m(D)\ $ to be an affine function of $\ D\ $ (that is, it has the form $\ m(D)=$$\,aD+b\ $), then your relationships $2$ and $3$ imply that it must be given by the formula above—that is, $\ M(D)=$$\,0.0013(D+36.15)\ $. If you were to assume that $\ m(D)\ $ is a polynomial of higher degree in $\ D\ $, you would need more relationships of the same form as $2$ and $3$ to pin down the the polynomial's coefficients. For a polynomial of degree $\ n\ $ you would have to obtain such relationships for at least $\ n+1\ $ different values of $\ D\ $.

enter image description here