根据传感器数据计算长度

发布于 2024-08-09 04:51:09 字数 384 浏览 3 评论 0原文

我有一个 IR 传感器,它将其当前信息写入一个令牌,然后我在 C# 应用程序中对其进行解释。一切都很好——没有问题,这是我的代码:

SetLabelText(tokens [1],label_sensorValue);
sensorreading = Int32.Parse(tokens[0]);
sensordistance = (mathfunctionhere);

太好了。因此,红外传感器距离物体越远,传感器读数就越低(因为反射回来并被传感器接收的光越少)。

我的问题是解释这个长度。当物体距离 5 英寸时,我可以继续计算“110”,然后当物体距离 6 英寸时,计算“70”。现在我希望能够使用这些常量计算任意长度的物体的距离。

有什么想法吗?

I've got an IR sensor which writes its current information to a token which I then interpret in a C# application. That's all good -- no problems there, heres my code:

SetLabelText(tokens [1],label_sensorValue);
sensorreading = Int32.Parse(tokens[0]);
sensordistance = (mathfunctionhere);

Great. So the further away the IR sensor is from an object, the lower the sensor reading (as less light is reflected back and received by the sensor).

My problem is in interpreting that length. I can go ahead and get lets say "110" as a value when an object is 5 inches away, and then "70" as a value when an object is 6 inches away. Now I want to be able to calculate the distance of an object using these constants for any length.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

滴情不沾 2024-08-16 04:51:10

嗯,我要做的第一件事是在固定距离处获取数据,即 1 英寸、1 英尺、2 英尺、5 英尺等。然后我会在 Excel 等程序中绘制这些数据,并从中找到最佳拟合曲线您可以导出一个函数。在代码中使用该函数并开始在不同的距离进行测试。

现在看来,事情可能没那么简单了。您尝试测量的物体的反射特性会改变您的读数,其他因素也可能会改变。由于我不知道你的要求是什么,所以我很难给出更具体的建议。

Well, the first thing that I would do is take data at fixed distances, i.e., 1 inch, 1 foot, 2 feet, 5 feet, etc. I would then plot that data in a program like Excel and find a best fit curve from which you can derive a function. Use that function in your code and start testing at varying distances.

Now, it may not be that simple. The reflective properties of the object you are trying to measure will change your readings, as could other factors. Since I don't know what your requirements are it is hard for me to give more specific advice.

平生欢 2024-08-16 04:51:10

这与其说是数学问题,不如说是物理问题!

Ed Swangren 建议使用各种实验的记录创建表格是可行的方法,除非您还可以依赖传感器制造商的信息。

除了设备固有的精度保真度之外,许多因素可能会干扰有效能量(或返回和测量的任何内容);阅读该特定设备或什至类似物品和/或游戏中物理效果/尺寸的基本原理可能会为您提供校准的更多想法。

一旦您有了一个将测量值与距离(可能还有附加标准温度、反射系数……)相关联的表格,它就变成了一个真正的数学问题,例如:

  • 确认目标精确度的统计相关性
  • ,用离散表推断实际读数(似乎是OP的原始问题)
  • 找到回归函数,并取消表格方法(我怀疑这会很容易,正如评论中所暗示的那样,这将远远不是线性的......

It more of a physics question than a math question!

Ed Swangren suggestion to create tables with the recording from various experiments is the way to go, unless you can also rely on information from the manufacturer of the sensor.

Aside from the intrinsic precision and fidelity of the device, so many factors may interfere with the effective amount of energy (or whatever is returned and measured); reading up on this particular device or even on similar items and/or the fundamental of the physical effects/dimensions in play may provide you additional idea for the calibration.

Once you have a table associating measurements with distance (and maybe additional criteria temperature, reflective factor...), it becomes a true math issue, for example to:

  • confirm the statistical relevance of the precision targeted
  • extrapolate real reading with the discrete table (seems to be the original question by the OP)
  • find the regression function, and do away with the table approach (I doubt this would be easy, as hinted in comments and such this will be far from linear...
韬韬不绝 2024-08-16 04:51:10

反射红外通常用于物体检测。但是,如果目标的形状、角度、反射特性并不总是相同,那么测量反射红外线的强度并不是估计距离的可靠方法。

有什么想法吗?

不同的传感方法。怎么样,像这样的视差传感器: http://www. acroname.com/robotics/info/articles/sharp/sharp.html

Reflected IR is often used for object detection. But, if the shape, angle, reflective properties of your target(s) aren't always the same, then measuring the intensity of reflected IR is not a reliable method for estimating distance.

Any ideas?

Different sensing methodology. How about, parallax sensor such as this one: http://www.acroname.com/robotics/info/articles/sharp/sharp.html .

勿忘初心 2024-08-16 04:51:10

进一步阐述 tom10 提出的平方函数...

我们假设您的设备函数是平方曲线,即

distance = A + B * reading + C * reading^2

现在我们需要找出 A、B 和 C 将您的读数转换为距离,所以我们需要的是回归分析的一种。方形曲线恰好由 3 个点定义,因此您可以在 3 个点 (r1..r3) 进行测量并记下距离 (d1..d3)

现在您有 3 个带有三个未知数的方程,您可以通过任何方式求解它们,即

A + r1 * B + r1^2 * C = d1
A + r2 * B + r2^2 * C = d2
A + r3 * B + r3^2 * C = d3

您求解A、B 和 C 一次,这将是您的“校准曲线”,并且能够使用上面的第一个公式计算任何未知距离。当然,如果您更改硬件,您将需要在任何设备变化的限制内重新校准您的装备。

您可以通过进行第四次测量并通过变量 D 等扩展上述所有方程,将这种机制扩展到三次甚至更高阶曲线,

A + rx*B + rx^2*C + rx^3*D + ....

但它不会增加太多精度。您会发现 rx^3 及以后的因子 D 将非常小。

希望这有帮助

祝你好运
迈克·D

elaborating a bit further on the square function proposed by tom10 ...

we asume your devices function is a square curve , i.e.

distance = A + B * reading + C * reading^2

Now we need to find out A, B and C to convert your reading into a distance, so what we need is a kind of regression analysis. A square curve is defined by exactly 3 points, so you measure at 3 points (r1..r3) and note distances (d1..d3)

Now you have 3 equations with three unknowns which you can solve by any means, i.e.

A + r1 * B + r1^2 * C = d1
A + r2 * B + r2^2 * C = d2
A + r3 * B + r3^2 * C = d3

You solve once for A, B, and C which will be your "calibration curve" and will be able to calculate any unknown distance using the first formula above. Of course if you change hardware you will need to recalibrate your gear within the limits of any device variations.

You can extend this mechanism to a cubical and even higher order curve by making a fourth measurement and expanding all above equations by a variable D, i.e.

A + rx*B + rx^2*C + rx^3*D + ....

etc. but it will not add much of accuracy. You will find that factor D for a rx^3 and onwards will be very small.

Hope this helps

Good luck
MikeD

鸠魁 2024-08-16 04:51:10

来自光源的能量将以 1/r2 的形式衰减(对于相对较小的光源)。除此之外,如果其他一切保持不变,唯一的问题可能是传感器的非线性。

要使用您的数据检查这一点,您会期望 E x r2=const,这大致适用于您的数据:

110 x 52 = 2750,以及

70 x 62 = 2520,

所以这些都在 10% 之内,看起来相当接近,所以看起来基本规则是成立的。

非线性传感器很常见,因此您应该确保在您将使用它的整个范围内进行检查。但如果它是线性传感器,人们提到的其他问题(例如反射表面)将不会成为问题,因为对于光传输和反射,一切(几乎)都是线性的,因此将是通过单个校准常数进行本质补偿。光源的角度、吸光材料等只要不改变就没有关系。

如果您测试了一些点,包括您感兴趣的范围的极值,并且它遵循 1/r2 规则,那么您就可以开始了。然后,当然,计算 const 是什么,r = sqrt(const/E)。

The energy from the light source will fall off as 1/r2 (for a source that's relatively small). Beyond this, if everything else is held constant, the only problem could be non-linearity in the sensor.

To check this with your data, you would expect E x r2=const, and this roughly holds for your data:

110 x 52 = 2750, and

70 x 62 = 2520,

so these are within 10% which seems fairly close, so it looks like the basic rule will hold.

Non-linear sensors are common, so you should be sure to check this over the full range that you'll be using it. But if it's a linear sensor, the other issues that people are mentioning (e.g. reflective surfaces) won't be a problem because, for light transmission and reflection, everything (almost) is linear and will therefore be intrinsically compensated for by a single calibration constant. The angle of the light source, absorbing materials, etc, all won't matter as long as they don't change.

If you test a few points, including the extremes of the range you're interested in, and it follows the 1/r2 rule, you're good to go. Then, of course, calculate what the const is, and r = sqrt(const/E).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文