psx contoller problem/limitation
Owen
Posts: 100
I'm using a psx2 controller connected to my propellar chip amd have a problem with the output of the device. the psx outputs one byte for each axis of the joystick so joystick foward is 255 joystick down is 0 joystick centered is 127. the problem is that the joystick physically has a circle shaped opening at the joystick instead of a square preventing the joystick from a full diagonal position. it is not possible for both x and y to be 255 , does anyone know what the purpose of this is? or is there a way around it with software? whouldn't the playstation want the full byte of information? thanks in advance
Owen
Owen
Comments
It seems not all controllers are the same I have two sony controllers and they are as you describe but I have a cheapo Logic 3 controller and I can get both ends of the scale at the same time, I've also found that most don't always centre on 127 either.
Why don't you change your thresholds in your code and reduce the range from say 5 - 250 that way you can achieve your goal.
Best regards,
Coley
The reason they can't both get 255 is because it's a circular gap for the stick to go through to the outside of the joypad, thus max X and Y is 0 and 255, yet on diagonals it changes due to it having circular motion.
Also, like Coley states, don't use 127 as center, have a dead area ( from about 96 to 159 ) and force that to 127, I used that on the Playstation games I've done, as some sticks are way out.
Hope this helps clarift things for you a little.
Have fun,
Jim.
speed = sqrt(x^2 + y^2)
Graham
thanks
Surely you could just decrease the maximum value from 255 to say 240, or whatever you max out to in the corners, then scale your values from 16 to 240, then subtract 16 to limit to 0-224, then * (65536/224) and then >>8 and voila.
x := ( ( ( ( x-16 ) #>0 ) #<224 ) * 292 ) >>8
y := ( ( ( ( y-16 ) #>0 ) #<224 ) * 292 ) >>8
Baggers.
can you explain how this works in more detail.
x := ( ( ( ( x-16 ) #>0 ) #<224 ) * 292 ) >>8
y := ( ( ( ( y-16 ) #>0 ) #<224 ) * 292 ) >>8
I appreciate the help
Owen.
The reason I multiply by 65535 / 224, then >>8 is to put it back in the range from 0 to 255
Because 65535 ( 65535 being the max number for >>8 to =255) / Max ( of small range ) gives us 292.5etc but we're usint integers, so 292 is the number to scale our small 0-224 value by to make from 0 - 65535.
EG. Take your new MAX value, 224, then run it through the conversion.
224*292 = 65408 then >> 8 = 255.5 but since registers are integer based not float, it becomes 255
hope this clears it up a bit more for you.
Baggers
Graham
Example 1:
x = 255
y= 0
Move the sprite zero x for every y pixel moved
Example 2:
x = 180
y = 180
Move the sprite one in y for every one in y moved, this would move the sprite at 45 degrees
Example 3:
x = 100
y = 50
Move the sprite 1 in y every two pixels in x.
Graham
Post Edited (Graham Stabler) : 9/28/2007 10:03:03 AM GMT
Owen
Thanks
Owen
Graham
p.s. Looks nice!
Oh, and don't forget to add the dead zone in the middle
Work out the radius to provide the speed, this will vary from 0 - 255 or whatever.
The motor that needs to go the greatest speed will be asigned this speed and the other motor will be asigned a fraction of this speed taken from the values for x and y.
e.g. 1:
say x = 180 and y = 180 from controller, calculate R as 255 apply this to both motors as they have equal components.
e.g. 2:
say x = 100 and y = 50 calculate radius as 111 apply this to the x motor and apply (50/100)*111 to the y motor (half the speed).
e.g. 3:
x = 10 y = 50 calculate r = 51 apply this to y (as larger) and apply (10/50)*51 to z motor.
Not sure of the easiest way to work out the radius perhaps Baggers can remember something about that fast method.
Graham
p.s. I'm still not completely sure all this is necessary, I think you will find that the angular speed of the camera going to a diagonal with both motors at 180 will be the same as the angular speed going to one side with a single motor going at 255 simply because when going to the diagonal the motors don't need to move as far for a given angle. In fact it comes from the fact that the two axes are orthogonal, the hypotenuse will always be longer than either of the other two sides and so will the speed in that direction.