![]() |
Re: Equation for joystick input to Talons
y = x^2, and then if (x < 0) y= y * -1?
or y = x^3 Simplest approach. |
Re: Equation for joystick input to Talons
Quote:
Code:
Here is your XY data: |
Re: Equation for joystick input to Talons
If you like using lookup tables (I come from an automotive world where everything is pretty much a table or surface), you can write a routine to do it.
I do it as a two-step process. First, I 'prelookup' the fractional index of the input. Then, I interpolate the output. I have a 2d (1 input 1 output) and 3d (2 input 1 output) interpolation block, you simply use two prelookup blocks for the two inputs. Header (structs): Code:
/*Code:
/*Code:
/*Code:
/*You can then write an interp curve as a pair of arrays, x and z. X must be monotonic (strictly increasing), z does not have to be. It will first find the points of x that bound the given point X and the fraction between them (the prelookup step). Then it finds the corresponding z points and weights them with the fraction, returning Z (output). Surfaces are similar, but you instead have 2 arrays (x and y) and a 2-dimensional array z. The sizes of x and the first dimension of z must match, and the size of y and the second dimension of z must match. The function needs to know the x size to index the array. In this way, you can make some really easily change the response of the curve or surface based on how you want it to be, non-linearly (there is no dependence between x and y as there would be in a multi-variable equation). For more than 3 dimensions, an interpolation is impractical. If you need more dimensions, you can use multiplied factors (curve with a variable as the input which scales the output). |
Re: Equation for joystick input to Talons
If you pre-compute the slope between each pair of points in the XY table and store those in an array, it makes the lookup marginally faster (and the code a lot cleaner). You can do this pre-computation at runtime at power-up, or after loading a table into memory from a config file. Once you've got a table that you're pretty sure won't need to be tweaked or tuned, you can do the pre-computation offline and hard-code the coefficients into the lookup routine (as was done in my previous post - I have an app that does this, to avoid human error). |
Re: Equation for joystick input to Talons
If using LV, the interpolate function in the array palette accepts an array of XY pairs that are your control points. You can then pass in the fractional index and it will perform the search/interp approach.
Be sure the array is sorted, though. Greg McKaskle |
| All times are GMT -5. The time now is 22:01. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi