跟踪对象的速度不一致地报告其位置

发布于 2025-01-31 10:53:01 字数 1645 浏览 4 评论 0原文

我的代码跟踪虚拟3D空间中存在的对象。

我无法直接访问该对象的位置,但是它每隔一段时间都报告其坐标。更新的确切频率并不完全是可靠的或可靠的,但是我知道通常会发生每个x毫秒。

此外,我不知道何时发生更新。取而代之的是,该代码仅限于单个功能,该功能运行了很多次(每秒考虑约60倍,但是它也应该在或多或少的执行中可以很好地工作,并且在运行时的速率可能会更改)。每次函数运行时,它都可以访问对象的最后一个报告的坐标以及确切的当前时间(但不是报告坐标的时间)。

该功能必须返回对物体当前速度和加速度的最佳估计。

估计并非微不足道。例如,连续两次读取完全相同的位置可能意味着对象停止移动,也可能意味着移动对象尚未更新其位置。

这是一个可能的“解决方案”的python/pseudocode示例,但不是一个很好的示例:

USUAL_UPDATE_RATE = X
STOPPING_THRESHOLD = USUAL_UPDATE_RATE * 1.2

lastTimePosition = None
lastVelocity = None
lastAcceleration = None

def update(time, position):
    # First time running, can't estimate yet
    if lastTimePosition is None:
        lastTimePosition = (time, position)
        return (0, 0)

    lastTime, lastPosition = lastTimePosition
    deltaTime = time - lastTime

    # Ignore duplicate positions if not enough time has passed
    if lastPosition == position and deltaTime < STOPPING_THRESHOLD:
        return (lastVelocity, lastAcceleration)

    # Calculate velocity
    velocity = distance(position, lastPosition) / deltaTime

    # If there's a previous velocity known, calculate acceleration
    if lastVelocity is not None:
        acceleration = (velocity - lastVelocity) / deltaTime
    else:
        acceleration = 0

    # Save new values
    lastTimePosition = (time, position)
    lastVelocity = velocity
    lastAcceleration = acceleration

    return (velocity, acceleration)

结果不够好,因为即使在实际速度或加速度避免的呼叫中,计算出的速度和加速度值也会差异很大T改变了。我还尝试将多个速度和加速度的平均值平均,但是即使那样的变化太多,当平均值太多的值时,结果花费太长以反映真实值。

鉴于有限的情况,哪种算法会给我最准确的估计,尽可能接近实时?

提前致谢。

My code tracks an object that exists in virtual 3D space.

I have no direct access to the object's position, but it reports its coordinates, every so often. The exact frequency with which the updates occur is not exactly known or reliable, but I know it usually happens every X milliseconds.

Additionally, I cannot know when updates occur. Instead, the code is limited to a single function that runs many times a second (think ~60 times a second, but it should work reasonably well with more or less executions, too, and the rate can change during runtime). Every time the function runs, it has access to the object's last reported coordinates, as well as the exact current time (but not the time when the coordinates were reported).

The function must return its best estimate of what the object's current velocity and acceleration are.

The estimation is not trivial. For example, reading the exact same position twice in a row may mean the object stopped moving, or it may simply mean the moving object hasn't updated its position yet.

Here's a python/pseudocode example of a possible "solution," but not a very good one:

USUAL_UPDATE_RATE = X
STOPPING_THRESHOLD = USUAL_UPDATE_RATE * 1.2

lastTimePosition = None
lastVelocity = None
lastAcceleration = None

def update(time, position):
    # First time running, can't estimate yet
    if lastTimePosition is None:
        lastTimePosition = (time, position)
        return (0, 0)

    lastTime, lastPosition = lastTimePosition
    deltaTime = time - lastTime

    # Ignore duplicate positions if not enough time has passed
    if lastPosition == position and deltaTime < STOPPING_THRESHOLD:
        return (lastVelocity, lastAcceleration)

    # Calculate velocity
    velocity = distance(position, lastPosition) / deltaTime

    # If there's a previous velocity known, calculate acceleration
    if lastVelocity is not None:
        acceleration = (velocity - lastVelocity) / deltaTime
    else:
        acceleration = 0

    # Save new values
    lastTimePosition = (time, position)
    lastVelocity = velocity
    lastAcceleration = acceleration

    return (velocity, acceleration)

The result is not good enough becuase the calculated velocity and acceleration values will vary wildly from call to call, even when the real velocity or acceleration haven't changed. I also tried averaging multiple velocities and accelerations together, but even then there is too much variation, and when averaging too many values, the results take too long to reflect the true values.

Given the limiting circumstances, what algorithm would give me the most accurate estimations, as close to real-time as possible?

Thanks in advance.

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

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

发布评论

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

评论(1

栀子花开つ 2025-02-07 10:53:01

我是a

算法

是,幸运的是,使用某些给定的邻居点可以在任何程度上在特定点上区分任何功能,甚至不必平均分布。最重要的是,您甚至可以定义近似值的准确性(当然,这是通过给出更多点)。

>提出算法(在此直接指向PDF的链接)。它具有一些密集的数学和一些棘手的符号,但它做得非常出色。

您说报告的时间

可能不是报告的坐标时间。鉴于时间间隔如此之低,我认为这不是一个大问题(这取决于您想要的准确性)。另外,如果您使用此算法来减少噪声,我认为将轨迹进行曲线样本是一个好主意。而不是取点p,p-1,p-2,...(其中p是当前点),您可以服用p,pk,pk, P-2K,...作为算法的输入。

关于图书馆,

我们没有涵盖库中的生活更新轨迹,但是您每次都可以创建一个新的轨迹(也许只使用最后几个点),但这可能不是最佳的。尽管如此,我鼓励您使用我们的图书馆,尽管它们的性质以一种简单的方式,但仍旨在与各种轨迹一起使用,我鼓励您使用我们的图书馆。在这里,您可以在几行中指定速度估计方法。这是一个现在正在工作的项目,当今我们将添加新功能。

我们也有一个 explample存储库,其中包含a 笔记本专门用于分析不同的速度估计方法及其工作方式。您可以将其与 iftial文档

重要说明:此项目仍处于alpha阶段,而在因果关系中,下一个版本将在此速度方法选择中特别更改序列(我们正在将其进行一般性,以便它也可以用于估计)) 。如果您使用它,请继续关注。

I'm one of the developers of a general trajectory analysis python library and we had a similar issue recently when estimating the velocity of a trajectory by several methods.

Algorithm

There is luckly an algorithm that can differentiate any function in a specific point at any degree using some given neighbours points and they don't even have to be equally spaced. The best of all is that you can even define the accuracy of the approximation (this of course is by giving more points).

This is the article where the algorithm is presented (here the link to the pdf directly). It has some dense math and some tricky notations, but it does an excelent job.

Limitations

You said the reported time might not be the extact time for the reported coordinates. Given that the time spasing is so low I think this is not a big problem (it depends on the accuracy you might want). Also, if you use this algorithm, to reduce noise I think it would be a good idea to subsample the trajectories. Instead of taking the points p, p-1, p-2, ... (where p is the current point) you could take p, p-k, p-2k, ... as inputs to the algorithm.

About the library

We don´t have covered life updating trajectories yet in the library, but you can create a new trajectory each time (maybe only using the last few points) but this might be not optimal. Althow this limitation (that surelly will be tackle in the future), I encourage you to use our library which is intended to be use with all kind of trajectories despite their nature in an easy way. There you can specify the velocity estimation method in a few lines. This is a project in work right now and we will be adding new features in these days.

We also have an expample repository which contains a notebook dedicated only to analyse the diferent velocity estimation methods and how they work. You can use this along with the offitial documentation.

IMPORTANT NOTE: this project is in an alpha stage still, and causally the next release will have somename changes specifically in this velocity method selection (we are making it general so it can be used too for aceleration estimation). Stay tuned if you use it.

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