You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Look Up Table for position solver
1 view (last 30 days)
Show older comments
Dear all,
I am trying to build a look up table to solve the position. It is basically a voltage-position conversion problem.
I will define the position in cartesian coordinates (x,y,z)
Each point of the position will have 3 volatge measured.
For example, at (0,0,0) the voltage is [5,1,2]
and at (1,0,0) the voltage is [3,2,4]
i will have 1000 points data.
How can i generate a look up table that when the input is [?,?,?] voltage, the output is [x,y,z] coordinate.
For example if the input voltage is [3,2,4] then the output will be (1,0,0)
It is also okay to use simulink or matlab
Could anyone help me? Please~
Thank you ver much
16 Comments
Torsten
on 26 Jan 2022
Is there a unique position vector that corresponds to each voltage vector ?
And for your table lookup, you only choose voltage vectors for which there already exists a position vector in the table or is it necessary to perform interpolation ?
Chun Wai KO
on 26 Jan 2022
Thanks for your reply
Yes, For different position, the voltage will be different
I will need the interpolation.
Or i may talk about my application more detailedly
i am trying to build an electromagnetic tracking system
My sensor can measure 3 voltage value in a point of position
And my tracking volume is 50cm x 50cm x 50cm
i will move the sensor in incremental step along x,y,z for 5 cm
So for example, i place my sensor at a point and define it as (0,0,0) and measure a voltage [v1,v2,v3]
then i move the sensor along x axis for 5 cm, the position will be (1,0,0) and measure the voltage again [v1', v2', v3']
So there are 1000 points in total. And what i want to do is after getting the 1000 points voltage-position data
Then i can solve the position by the real time measured voltage. Not only the position i measured, but also predicting the position like (1.5, 0 , 0)
Chun Wai KO
on 26 Jan 2022
Any thoughts?
Chun Wai KO
on 27 Jan 2022
i still cannot solve the problem.
Is it possible to map a vector to other vector?
Chun Wai KO
on 27 Jan 2022
Yes, the voltage vector is depends on the position
it is basically a constant for each point of position
Chun Wai KO
on 27 Jan 2022
while the voltage has a revese relationship to the distance from the sensor
i.e [10,10,10] will get the smallest voltage for each compoent of voltage [v1,v2,v3]
Chun Wai KO
on 27 Jan 2022
My project is based on one paper. They used 5 voltage compoent and 6 position/orientation compoent to generate the the look up table. I am trying to do simplier model, so my voltage will only have 3 compoents and only x,y,z will be found
Torsten
on 27 Jan 2022
So does it make sense to independently reverse interpolate in x-,y- and z- direction ?
Means : points with x-component 1 have all approximately voltage v1 in the first position, points with x-component 2 have all approximately voltage v2 in the first position and so on. And the same for y- and z- direction ?
Chun Wai KO
on 27 Jan 2022
You mean use the 3 voltage to solve the x independently
and solve the y independently and solve the z independently
like decompose the x y z coordinate ?
Chun Wai KO
on 27 Jan 2022
The author didnt explain..
But i think that decomposing the xyz may not work
For example for position [1 0 0] and position [1 0 1]
their x coordinate are both 1
but the voltage compoents for [1 0 0] and [1 0 1] are totally different
Chun Wai KO
on 27 Jan 2022
Or i may try to use inverse interpolation to solve 1 voltage first
using 1 voltage compoent, means f(x,y,z) = v
what is the function to solve 3d reverse interpolation?
i know a function called contour() but it can only solve x and y
Torsten
on 27 Jan 2022
Say you are to interpolate the position for the voltage vector that is half the voltage vector in position 1,0,0 plus half the voltage vector in position 1,0,1. Would it be acceptable to assume that the reverse interpolated position is 1,0,1/2 ?
Torsten
on 27 Jan 2022
Edited: Torsten
on 27 Jan 2022
Concerning your idea:
Maybe
f(x,y,z) = v1
g(x,y,z) = v2
h(x,y,z) = v3
Three equations for contour in three unknowns x,y,z where f,g and h are the equations for the surface of voltage components 1,2 and 3.
Accepted Answer
Torsten
on 28 Jan 2022
Edited: Torsten
on 28 Jan 2022
Use fmincon (or maybe better ga, since the objective function doesn't look differentiable) to solve the following problem:
min:( interp3(xdata,ydata,zdata,v1data,x,y,z) -v1q)^2 + (interp3(xdata,ydata,zdata,v2data,x,y,z)-v2q)^2 + ...
(interp3(xdata,ydata,zdata,v3data,x,y,z)-v3q)^2
for x,y,z under the constraints
0<=x,y,z<=10
Here, v1data,v2data and v3data are your voltages at (xdata,ydata,zdata) and (v1q,v2q,v3q) is the voltage combination for which you want to find the coordinates (x,y,z).
11 Comments
Chun Wai KO
on 28 Jan 2022
Thank you very much for your effort
Is it a function similar to lsqnonlin?
I dont have much knowledge about it
but in my understnading, lsqnonlin can also be used to find the minimize value
Torsten
on 28 Jan 2022
Edited: Torsten
on 28 Jan 2022
lsqnonlin and fmincon are optimizers that work if the objective function is differentiable. You can try both of them, but I think ga is better suited in your case because of the nonnecessary differentiability assumption.
Chun Wai KO
on 28 Jan 2022
Is it the basic idea? Sorry i don't have the voltage data yet
seems i need to adjust the lsqnonlin parameter (like upper bound lower bound? or tolerance?)
Sorry i don't have much experience on it.
Torsten
on 28 Jan 2022
Edited: Torsten
on 28 Jan 2022
xdata,ydata and zdata are vectors of length 11^3 since x,y and z coordinates run from 0 to 10.
v1,v2 and v3 are the associated voltage vectors, thus also of length 11^3.
If you take them randomly, you won't succeed with lsqnonlin because of differentiability considerations
Additionally, you must fix them since as you wrote above, they will be generated anew in every call to "position", and the solver will have a newly generated problem each time.
Upper and lower bounds for the solution are 0 and 10 for x,y and z.
Chun Wai KO
on 28 Jan 2022
i am trying to do a small dimenson model to verify the code first
let's say it is a 3x3x3 dimenson
i know that the voltage v1,v2,v3 will be also 3x3x3
but you mean xdata,ydata,zdata are also 3x3x3?
i thought for each, they are 3x1 only
Torsten
on 28 Jan 2022
Edited: Torsten
on 28 Jan 2022
Look at the documentation of interp3.
xdata,ydata and zdata used in interp3 must be generated by the meshgrid command from the corresponding 1x3 vectors.
In your case, calling interp3 as interp3(vidata,x,y,z) where vidata are the 11x11x11 matrices of voltage data might be the easiest way.
Chun Wai KO
on 21 Feb 2022
Dear Sir, i finally completed my measurement system and got a set of data.
i am trying to do a 1 degree of freedom system first.
However, when i use the lsqnonlin, it shows 'the relative norm of the current step
is less than options.StepTolerance'.
For example, my data is
[4.3827, 4.2624, 3.2585, 0.9934, 0.5985, 0.1775, 0.2299, 0.0952, 0.0935, 0.0954, 0.08]'
The lsqnonlin can solve the position when the v1q is large (>0.5).
When the v1q is small, the lsqnonlin cannot solve the position.
Even if i set the StepTolerance = 1e-100, the Optimization stopped and show relative norm(step) = 0e00
i may show you the code here.
Thank you very much
Torsten
on 24 Feb 2022
You didn't specify how to extrapolate values that are outside [1:10]. interp1 will return NaN in the case that the suggested "currentPandO" value is outside this interval.
I gave you the advice to
a) use ga
b) constrain the solution
You use lsqnonlin (wrong, since you have to specify out = interp1(y,x) - vq) and don't constrain the solution. So how can I help you ?
Chun Wai KO
on 24 Feb 2022
Dear Sir,
i tried to constrain the solutuon to [1:10] for the lsqnonlin
but it still cannot compute the correct solution
y = [4.3827, 4.2624, 3.2585, 0.9934, 0.5985, 0.1775, 0.2299, 0.0952, 0.0935, 0.0954, 0.08]'
when my vq= 3, it can compute a solution x = 3.1161
but when the vq is small, for example vq = 0.7, it shows that x = 7.00
i expected the value should be bewteen 4 to 5 from the interpoation.
It only happens when the vq is small. (it is okay when the vq is larger than 2)
I don't know why it happens.
I will try ga also
Thank You very much
Torsten
on 24 Feb 2022
Edited: Torsten
on 24 Feb 2022
vq = 0.7;
y = [4.3827, 4.2624, 3.2585, 0.9934, 0.5985, 0.1775, 0.2299, 0.0952, 0.0935, 0.0954, 0.08];
fun=@(x) interp1(1:numel(y),y,x,'pchip') - vq;
x0 = 1;
[solution,res] = lsqnonlin(fun,x0,1,numel(y))
But you should really try ga instead of lsqnonlin.
Chun Wai KO
on 2 Mar 2022
Dear sir,
I am trying to use the ga to build the 2D system
It can compute a solution but the output keeps varying. (not very accurate)
So i tried to set the options:
options = optimoptions(@ga,'FunctionTolerance',1e-16,'MaxGenerations',150,'MaxStallGenerations',150,'ConstraintTolerance',1e-16)
The output becomes more accurate
however, i found that the computation time for the ga is quite long for each output (1-2 seconds)
As my application is a real time tracking system, this situation is not ideal
is there any way to keep the accuracy while shortening the run time?
thank you very much
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)