View Single Post
Old 01-20-2007, 06:59 PM   #61
inh
Maximum Bitrate
 
Join Date: Jan 2007
Location: Fort Riley KS
Vehicle: 91 CRX Si
Posts: 514
My Photos: ()
heres a snippet to determine which axis is being acted upon. what was happeneing is that i had it set to play/pause the song when i pressed down on the hat (z axis) and to turn the volume up or down when i twisted it, but when i would twist it would change the z value a bit so the song would pause.. This is a snippet that will determine which axis is being acted upon the most.. Its really sloppy and nasty, but as of now im not aware of any functions or other features of the glovepie scripting language that would speed this up..

Code:
//Routine to determine which axis is being acted upong the most due to it being //inevitable that more than one axis will change at a time //this checks all values after a specified time and determines which one changed the most //get a position reading from all axises var.roll.1 = MapRange(Joystick1.roll, -1,1, 0,1) var.yaw.1 = MapRange(Joystick1.yaw, -1,1, 0,1) var.pitch.1 = MapRange(Joystick1.pitch, -1,1, 0,1) var.x.1 = MapRange(Joystick1.x, -1,1, 0,1) var.y.1 = MapRange(Joystick1.y, -1,1, 0,1) var.z.1 = MapRange(Joystick1.z, -1,1, 0,1) //wait a bit, then get positions again wait 200ms var.roll.2 = MapRange(Joystick1.roll, -1,1, 0,1) var.yaw.2 = MapRange(Joystick1.yaw, -1,1, 0,1) var.pitch.2 = MapRange(Joystick1.pitch, -1,1, 0,1) var.x.2 = MapRange(Joystick1.x, -1,1, 0,1) var.y.2 = MapRange(Joystick1.y, -1,1, 0,1) var.z.2 = MapRange(Joystick1.z, -1,1, 0,1) //compare second reading to first usign subtraction, then use th absolute function so that even negative values //return whole numbers. the greated var.whatever.diff value will be the axis that has changed the most var.roll.diff = abs(var.roll.2 - var.roll.1) var.yaw.diff = abs(var.yaw.2 - var.yaw.1) var.pitch.diff = abs(var.pitch.2 - var.pitch.1) var.x.diff = abs(var.x.2 - var.x.1) var.y.diff = abs(var.y.2 - var.y.1) var.z.diff = abs(var.z.2 - var.z.1) //super-sloppy if tree to figure out which var.*.diff is the greatest, and then act accordingly.. //as of now it just spits out which axis is being acted upon up in the debug bar at the top //of the scripting window.. if ((var.roll.diff > var.yaw.diff) and (var.roll.diff > var.pitch.diff) and (var.roll.diff > var.x.diff) and (var.roll.diff > var.y.diff) and (var.roll.diff > var.z.diff)) var.roll.dir = sign(var.roll.2 - var.roll.1) if (var.roll.dir = -1) debug = "Roll (Twist Left)" elseif (var.roll.dir = 1) debug = "Roll (Twist Right)" endif else if ((var.yaw.diff > var.roll.diff) and (var.yaw.diff > var.pitch.diff) and (var.yaw.diff > var.x.diff) and (var.yaw.diff > var.y.diff) and (var.yaw.diff > var.z.diff)) var.yaw.dir = sign(var.yaw.2 - var.yaw.1) if (var.yaw.dir = -1) debug = "Yaw (Tilt Right)" elseif (var.yaw.dir = 1) debug = "Yaw (Tilt Left)" endif else if ((var.pitch.diff > var.roll.diff) and (var.pitch.diff > var.yaw.diff) and (var.pitch.diff > var.x.diff) and (var.pitch.diff > var.y.diff) and (var.pitch.diff > var.z.diff)) var.pitch.dir = sign(var.pitch.2 - var.pitch.1) if (var.pitch.dir = -1) debug = "Pitch (Tilt Forewards)" elseif (var.pitch.dir = 1) debug = "Pitch (Tilt Backwards)" endif elseif ((var.x.diff > var.yaw.diff) and (var.x.diff > var.pitch.diff) and (var.x.diff > var.roll.diff) and (var.x.diff > var.y.diff) and (var.x.diff > var.z.diff)) var.x.dir = sign(var.x.2 - var.x.1) if (var.x.dir = -1) debug = "X (Slide Left)" elseif (var.x.dir = 1) debug = "X (Slide Right)" endif else if ((var.y.diff > var.roll.diff) and (var.y.diff > var.pitch.diff) and (var.y.diff > var.x.diff) and (var.y.diff > var.yaw.diff) and (var.y.diff > var.z.diff)) var.y.dir = sign(var.y.2 - var.y.1) if (var.y.dir = -1) debug = "Y (Slide Forewards)" elseif (var.y.dir = 1) debug = "Y (Slide Backwards)" endif else if ((var.z.diff > var.roll.diff) and (var.z.diff > var.yaw.diff) and (var.z.diff > var.x.diff) and (var.z.diff > var.y.diff) and (var.z.diff > var.pitch.diff)) var.z.dir = sign(var.z.2 - var.z.1) if (var.z.dir = -1) debug = "Z (Pull Up)" elseif (var.z.dir = 1) debug = "Z (Push Down)" endif else debug = " " endif

Edit: tweaked the code a bit to give you a better idea of what axis is being affected... I'm sure i'll have a useable script up in a bit

Last edited by inh : 01-20-2007 at 07:21 PM.
inh is offline   Reply With Quote
Sponsored Links