I have two systems, each of which has a direction sensor (0-360 degrees), but the sensors can provide wildly different values depending on the orientation of each system and the linearity of each sensor. I have a mechanical reference that I can use to generate a table of where each system is actually pointing. This yields a table with three columns:
Physical SystemA SystemB
-------- ------- -------
000.0 005.7 182.3
005.0 009.8 178.4
... ... ...
From just the data shown, we can see that SystemA isn't far from the physical reference, but SystemB is about 180 degrees off, and goes in the opposite direction (imagine it is mounted upside-down).
I need to be able to map back and forth between all three values: If SystemA reports something is at 105.7, I need to tell the user what physical direction that is, then tell SystemB to point to the same location. The same if SystemB makes the initial report. And the user can request both systems to point to a desired physical direction, so SystemA and SystemB would need to be told where to point.
Linear interpolation isn't hard, but I'm having trouble when data is going in opposite directions, and is modular/cyclical.
Is there a Pythonic way to do all these mappings?
EDIT: Let's focus on the most difficult case, where we have two paired lists of values:
A B
----- -----
0.0 182.5
10.0 172.3
20.0 161.4
... ...
170.0 9.7
180.0 359.1
190.0 348.2
... ...
340.0 163.6
350.0 171.8
Let's say the lists come from two different radars with pointers that aren't aligned to North or anything else, but we did manually take the above data by moving a target around and seeing where each radar had to point to see it.
When Radar A says "I have a target at 123.4!", where do I need to aim Radar B to see it? If Radar B finds a target, where do I tell Radar A to point?
List A wraps between the last and first elements, but list B wraps nearer to the middle of the list. List A increases monotonically, while list B decreases monotonically. Notice that the size of a degree on A is generally not the same size as a degree on B.
Is there a simple interpolator that will wrap correctly when:
Interpolating from List A to list B.
Interpolating from List B to list A.
It is OK to use two separate interpolator instantiations, one for going in each direction. I'll assume a linear (first-order) interpolator is OK, but I may want to use higher-order or spline interpolation in the future.
Some test cases:
A = 356.7, B = ?
A = 179.2, B = ?