Have been working with @jeremydouglass on using a joystick that was returning unusual values, and I couldn’t get them to work like a ‘normal’ joystick.
As it turns out - the pot on this stick has a logarithmic curve! I’ve verified this by converting each x & y value from the pot to log(x) and log(y) and use that to draw a line. And I get a nice straight line at some angle on the screen!
So I’ve been searching for ways to turn log values to linear - and getting some HEAVY math I don’t quite ‘get’ :-). I’ve also done some ‘shoot-from-the-hip’ coding (as in the code below) in Processing and am getting SOMETHING… close but no cigar!
In the ballpark - but not there yet. The line drawn runs all over the screen - so there must be a way to ‘math’ these values into linear values. I need them to be 0 to height and 0 to width where w&h/2 = screen center. Then they have to be converted to Cartesian coordinates.
// X is the value from the stick which currently runs from 170 to around 900;
float fX = pow(10,log(X/20));
float fY = pow(10,log(Y/30));
line(10,fX,fY,70);
Since you are getting a straight line then have you not solved the problem?
You have the code
This will not solve the problem since the log function is “logarithm to the base e” but your power function is trying to reverse a value calculated as “logarithm to the base 10”.
for(float x = 170; x < 900; x += 20){
println(x , log(x), exp(log(x)));
}
If you try this code you will see that to reverse the log you need to take the exponential,
Based on your description the curve is not logarithmic rather it is exponential
HINT: Map the pot values to the range 0-1 rather than 0-width and 0-height this means the code can be used with any screen size by multiplying by the screen size.
This is a joystick data-stream - can’t really make a copy! Enclosed is a picture of this beast, up on wood blocks so I can get to things. It using an Arduino Micro to send to a CP-2104 USB-Serial chip which Processing can open as a port.
I’ve been trying so many ways to get this #@)$@ thing to work… getting
kinda punchy. I don’t recall now how I got the idea, but I tried converting the data with the log() function - which I forgot was logN. So…
All I need to do is get the movement of the joystick to create x-y points on any place on the screen. As I may have said - it was working FINE with the Logitech 3D stick. I don’t know if I’ve mentioned this - but I sub’d in a little Parallax ‘thumb-stick’ and I could get the kind of motion I’m looking for. This confirmed the Navy pots are NOT linear -
not sure what they are now… @Quark thought it might be exponential.
I am seriously thinking of finding a 10k pot with 360 rotation and replacing those big pots. It has been hard to find anything at a decent
price so far.
Yes - I can move the joystick to the major cardinal positions. I have an Arduino script displaying the values. The web-site looks very cool - will try it with at least 6 values. THANKS!
Ok - did the CurveFit and here is the link to the results: By specifying log10 I got a line i produced (somehow) in my many trial and errors. So now - how do i use those formulas to get the joystick vales to be in the processing coordinate system: x=0 - height y=0 - width.
If this doesn’t work out I have found a cheap continuous trimmer pot that should do the job. But handling it with the math is much cooler!
Found an Arduino scaling solution here: http://bit.ly/2HFZPrS
It looks like it is working GREAT - converting on Arduino side and sending (hopefully) ready-to-use data to Processing. But it seems slightly off.
If/when you have time, could you look at this function - I’m not sure what the ‘curve parameter’ is or should be. I’m currently using his value of -1.5.