Marco Polo: Finding a friend with only distance and motion

原始链接: https://www.jackhogan.me/blog/marco-polo

Hacker Newsnew | past | comments | ask | show | jobs | submitloginMarco Polo: Finding a friend with only distance and motion (jackhogan.me)44 points by jackhogan11 4 hours ago | hide | past | favorite | 5 comments help stonlyb 2 hours ago | next [–] Pilling on to say well done on the interactivity and visuals / design overall. I'm working to make producing posts like this universally accessible (http://motate.app/) and posts like yours are an inspiration.replyrayhanadev 1 hour ago | prev | next [–] love seeing purdue hackers folks on hackernews :)replynoen 1 hour ago | prev | next [–] Really well written article, thank you!replyjmux 3 hours ago | prev | next [–] nice work! the interactive visuals are really coolreplytreycluff 2 hours ago | prev [–] I love a blog post with interactionreply Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact Search:
相关文章

原文

You walk into a cafe, looking for your friend. Seems like an easy task, until you see it’s so packed that you can’t see through the crowd at all, and everyone’s talking so loud that you can barely hear anything. The only things you know are your movements, and how far you are from your friend (through the special psychic bond you two share). How will you find each other?

I wanted to solve the exact same problem, but with devices instead of people (so no psychic connection for me), existing in a space of hundreds of other devices. Working the problem taught me a lot of really interesting science relating to robotics and state estimation, and I wrote this post so you can learn, too.

The Formal Problem: Range-Only Relative Localization

I have two microcontrollers (the large blue boards). Each has an inertial measurement unit (IMU, small board on top right), which gives me data including acceleration and compass heading. They also have an ultra-wideband unit (UWB, small board in slot on left), which gives the distance to the other unit in the pair.

The Beacons in question.

Each of these packages will be contained within a wearable device, and can therefore prompt its wearer to move around. This is an important freedom, because it means we can use the change in distance over time to determine location during the localization process, rather than purely statically.

Potential Solutions

To get us in the mindset of doing a technical implementation, let’s understand some options we have and see why they are or aren’t a good fit for what we’re trying to do.

Candidate 1: Multi-Antenna Ultra-Wideband

Ultra-wideband localization, found in location-aware products including AirTags, uses a simple call-and-response system known as time of flight. The UWB measures the time it takes for a roundtrip exchange of information, which is then turned into a distance d=c(TloopTreply)/2d = c \cdot (T_{loop} - T_{reply})/2

The initiator sends out a timestamped pulse to the responder, which then responds in TreplyT_{reply}

TloopT_{\text{loop}} 220.07 NS TreplyT_{\text{reply}} 120.00 NS Derived ToF\text{Derived ToF} 50.03 NS Recovered Distance 15.00 M
ToF=TloopTreply2=220.07120.002=50.03 ns\text{ToF} = \frac{T_{\text{loop}} - T_{\text{reply}}}{2} = \frac{220.07 - 120.00}{2} = 50.03 \text{ ns}
d=cToF=15.00 md = c \cdot \text{ToF} = 15.00 \text{ m}

Release to update

The time of flight system works fine for getting the distance to the other device, but alone is insufficient for getting the bearing to the other device. This limitation is where phase difference of arrival (PDoA) ultra-wideband comes in.

PDoA uses a property of radio waves called the phase. Light and radio waves oscillate up and down as they travel; where they are in that cycle is the phase. As the wave passes any fixed point in space, its phase at that point cycles:

We use this property to determine the heading relative to the other device. By positioning two antennas a known distance dad_a

Drag the point to move the wave source.

Δφ\Delta\varphi 0.00 rad θ\theta 0.00 rad (0.00°)
θ=arcsin ⁣(Δφλ2πda)=arcsin ⁣(0.0080.002π100)=0.00 rad\theta = \arcsin\!\left(\frac{\Delta\varphi \cdot \lambda}{2\pi \cdot d_a}\right) = \arcsin\!\left(\frac{0.00 \cdot 80.00}{2\pi \cdot 100}\right) = 0.00 \text{ rad}

Release to update

Failure mode: PDoA is a great system, but it has a caveat: it requires two antennas. This design restriction makes it very difficult to integrate into a wearable, where you have to deal with skin substantially attenuating signals. One antenna (what I chose for Beacons) can maybe get through with clever placement, but two is much more difficult.

Candidate 2: External Trilateration System

Another potential way to do things is to involve external devices with known fixed positions, usually known as anchors. With at least three of them, a Beacon can measure its distance to each and solve for its location. This strategy is the same as how GPS works, using multiple circles (or spheres in 3D) of distance to derive an exact location for the device:

Drag the beacon.

r1r_1
r12=(xx1)2+(yy1)2r22=(xx2)2+(yy2)2r32=(xx3)2+(yy3)2\begin{aligned} r_1^2 &= (x - x_1)^2 + (y - y_1)^2 \\ r_2^2 &= (x - x_2)^2 + (y - y_2)^2 \\ r_3^2 &= (x - x_3)^2 + (y - y_3)^2 \end{aligned}
[x2x1y2y1x3x1y3y1][xy]=12[k2k1k3k1],ki=xi2+yi2ri2\begin{bmatrix} x_2 - x_1 & y_2 - y_1 \\ x_3 - x_1 & y_3 - y_1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \tfrac{1}{2}\begin{bmatrix} k_2 - k_1 \\ k_3 - k_1 \end{bmatrix},\quad k_i = x_i^2 + y_i^2 - r_i^2
(x,y)=(240.00, 190.00)(x, y) = (240.00,\ 190.00)

Release to update

Failure mode: Trilateration is easy, once you have those three anchors. In practice, this means permanently installing devices to always broadcast their locations within a space. The localization needs to work without specially-installed equipment, so I don’t see trilateration as a valid solution. However, if I were to deploy these in a known location that has a lot of traffic (like a conference venue), this strategy could act as a refining system to keep the main system grounded.

Candidate 3: Kalman Filters

Kalman filters are the gold standard for state-space estimation in physical spaces, and are exactly what we need to solve our problem. They operate on the principle of having an internal estimation of the unobservable true state — in this case, the relative position — which is updated with new information we get from measurements in a looping process. This loop eventually converges on a reasonable estimate that we can use to guide the user. Our true state is unobservable because we can’t directly measure bearing from the sensors alone; the bearing comes from the combined information from all of our sensors.

I specifically chose an extended Kalman filter (EKF), which gives support for the nonlinear functions needed to calculate the expected bearing. The reason an EKF is our best solution is that it only requires one UWB antenna (unlike PDoA) and only two devices (unlike trilateration).

Implementing an EKF

An EKF is a loop composed of two parts: a prediction and a measurement step. You have a state vector x^\hat{\textbf{x}}

  • “What do I think my next state will be?”: Answered by the state transition function f(x,u)f(\textbf{x}, \textbf{u})
  • “What measurements do I expect to receive?”: Answered by the measurement function h(x)h(\textbf{x}), this also takes the current state, but it instead asks what the probable sensor readings are. For Beacons: “Given how I’m moving, what do I expect the UWB reading to be at the next timestep?”

The state x\textbf{x} represents what the system is keeping track of, but it’s also very important to know the relations of each of the state values to each other. This is where the covariance matrix PRx×xP \in \mathbb{R}^{|\textbf{x}|\times|\textbf{x}|}

Sidenote: Linearization

Linearization is the process of taking a nonlinear function (like a parabola) and “zooming in” really close, so close that the curved line actually looks straight, or in other words, linear. It’s an approximation so it’s not guaranteed to be optimal, but it’s good enough for our use case (and others, including GPS).

EKFs have an additional layer of complexity in return for supporting nonlinear functions like square root, which you will see are necessary for our task: they require differentiability of f(x,u)f(\textbf{x}, \textbf{u})

The Flow of Data

We now have all of the pieces to describe how data flows through the EKF loop. We start with the current state x^kk\hat{\textbf{x}}_{k|k}

Our first step is to predict what the next state and covariance will be.

x^k+1k=fk(x^kk,uk)Pk+1k=FkPkkFkT+Qk\begin{align*}\hat{\textbf{x}}_{k+1|k} &= f_k(\hat{\textbf{x}}_{k|k}, \textbf{u}_k)\\P_{k+1|k}&=F_k P_{k|k} F_k^T + Q_k\end{align*}
联系我们 contact @ memedata.com