 |
WiiLi.org a new revolution
|
| View previous topic :: View next topic |
| Author |
Message |
Endrick

Joined: 30 Mar 2007 Posts: 7
Digg It |
Posted: Mon Apr 02, 2007 2:58 am Post subject: Uber Joystick script, up to 6 axis. Mote, Chuck, and Stick |
|
|
Here's my first script that I'll take credit for. I set it up for "easy" customization. The biggest thing I like is the LED lights telling you when the wiimote and nunchuk are centered for easy calibration.
I'm happy with it for now but it can use improvement. I can set up the nunchuk sideways as and twist it like a throttle and the use the wiimote as a stick. This makes me VERY happy with flight sims.
I don't have the geometry background to get the axis perfect so right now its based on dividing the massaged raw values. It works well up to about 70 degrees of tilt in 2 directions before the angles get too complex for it.
| Code: |
// 3 Joysticks of freedom created by Endrick
// This started as the Generic Joystick Driver by vkapadia
// This utility works with the nunchuk, the chuck joystick, and the wiimote to
// provide up to 6 analog axes at a time and 13 useable buttons. The
// only things missing are IR and Accel functions. This is set up as a
// decent starting point for all sorts of uses. Please feel free to use,
// correct, update, change, obliterate, or abuse this script for any
// purpose you wish to put it to.
// The axis are set up to output to PPJoy as such:
// Analog 0 and 1 are for the wiimote tilt regardless of mode
// Analog 2 and 3 are for the nunchuk tilt
// Analog 4 and 5 are for the nunchuk joystick
// Any changes manual changes to this can be found near the bottom of
// the script.
// If the wiimote and chuck are outputting center (including dead zone) then
// All 4 LEDs will be lit. The first 2 LEDs represent the x, and y or z axis
// depending on which mode you're using. The second 2 LEDs represent x and z
// axis on the nunchuk
// The buttons are set up to output to PPJoy as such:
PPJoy.Digital1 = wiimote.Up
PPJoy.Digital2 = wiimote.Down
PPJoy.Digital3 = wiimote.Left
PPJoy.Digital4 = wiimote.Right
PPJoy.Digital5 = Wiimote.A
PPJoy.Digital6 = Wiimote.B
PPJoy.Digital7 = Wiimote.Minus
PPJoy.Digital8 = Wiimote.Plus
PPJoy.Digital9 = Wiimote.Home
PPJoy.Digital10 = wiimote.One
PPJoy.Digital11 = wiimote.Two
PPJoy.Digital12 = Wiimote.Nunchuk.CButton
PPJoy.Digital13 = Wiimote.Nunchuk.ZButton
// *************************************************************
// *** Wiimote Mode Select ***
// These are the 4 modes I have set up:
// 0 = off, does not use forces from the wiimote
// 1 = normal mode, hold the wiimote with the D pad facing the screen
// 2 = steering mode, hold the wiimote with the D pad by your left
// hand and steer like excite truck
// 3 = joystick mode, hold the wiimote upright like a joystick
var.wiimote.mode = 3 //set to 0, 1, 2 or 3
// ************************************************************
// *** Trim values ***
// This is the wiimote and chuck trimming area. Probably not needed. When
// the wiimote and chuck are leveled these will be near 0 anyway. Any variance
// will be kicked out by the deadzone. Y is set at -8 for stick mode so that
// the stick will be held at a slightly forward angle at 0 making it easy.
// to use the D pad as a hat switch.
// trim for wiimote
var.xtrim = 0 // set from -10 to 10
var.ytrim = -8 // set from -10 to 10
var.ztrim = 0 // set from -10 to 10
// trim for nunchuck
var.chuck.xtrim = 0 // set from -10 to 10
var.chuck.ztrim = 0 // set from -10 to 10
//***********************************************************
// *** Dead zone settings ***
// These can be adjusted from 0 to 25, 4 seemed to work well for me.
// Note: output starts at the deadzone value, so the deadzone value
// is the lowest value that will be seen by PPjoy. If it is set too high
// you lose any fine control. The joystick on the chuck doesn't really
// need a dead zone so none was set.
var.deadzone = 4 // set from 2 to 10
var.chuck.deadzone = 4 // set from 2 to 10
//***********************************************************
// *** Max/Min zone settings for wiimote ***
// The value of the raw wiimote setting will be capped at these levels.
// 25 / -25 is the max / min value of laying the wiimote on its side,
// front, or bottom.
var.xMax = 17 // Maximum X value, set from -25 to 25
var.xMin = -17 // Minimum X value, set from -25 to 25
var.yMax = 17 // Maximum Y value, set from -25 to 25
var.yMin = -17 // Minimum Y value, set from -25 to 25
var.zMax = 25 // Maximum Z value, set from -25 to 25
var.zMin = -25 // Minimum Z value, set from -25 to 25
// Max/Min zone setting for nunchuk
var.chuck.xMax = 23 // Maximum X value for chuck, set from -25 to 25
var.chuck.xMin = 0 // Minimum X value for chuck, set from -25 to 25
var.chuck.zMax = 25 // Maximum Z for chuck, set from -25 to 25
var.chuck.zMin = -25 // Minimum Z for chuck, set from -25 to 25
//***********************************************************
//Main code below
// sets the trim values
var.xRot = Wiimote.RawForceX + var.xtrim
var.yRot = Wiimote.Rawforcey + var.ytrim
var.zRot = Wiimote.RawForceZ + var.ztrim
var.chuck.xRot = Wiimote.Nunchuk.RawForceX + var.chuck.xtrim * 2
var.chuck.zRot = Wiimote.Nunchuk.RawForceZ + var.chuck.ztrim * 2
// sets the dead zone for the wiimote
// if the current reading, including trim is less than the deadzone
// then it will return a 0 value to ppjoy
if abs(var.xRot)< var.deadzone
var.xRotDead = 0.00
else
var.xRotDead = var.xRot
endif
if abs(var.yRot)< var.deadzone
var.yRotDead = 0.00
else
var.yRotDead = var.yRot
endif
if abs(var.zRot)< var.deadzone
var.zRotDead = 0.00
else
var.zRotDead = var.zRot
endif
if abs(var.zRot)< var.deadzone
var.zRotDead = 0.00
else
var.zRotDead = var.zRot
endif
// sets the dead zone for the nunchuck
if abs(var.chuck.xRot)< var.chuck.deadzone * 2
var.chuck.xRotDead = 0.00
wiimote.led3 = 1
else
var.chuck.xRotDead = var.chuck.xRot
wiimote.led3 = 0
endif
if abs(var.chuck.zRot)< var.chuck.deadzone * 2
var.chuck.zRotDead = 0.00
wiimote.led4 = 1
else
var.chuck.zRotDead = var.chuck.zRot
wiimote.led4 = 0
endif
if var.xRotdead > var.xMax
var.xRotDead = var.xMax
endif
if var.xRotdead < var.xMin
var.xRotDead = var.xMin
endif
if var.yRotdead > var.yMax
var.yRotDead = var.yMax
endif
if var.yRotdead < var.yMin
var.yRotDead = var.yMin
endif
if var.zRotdead > var.zMax
var.zRotDead = var.zMax
endif
if var.zRotdead < var.zMin
var.zRotDead = var.zMin
endif
if var.chuck.xRotdead > var.chuck.xMax * 2
var.chuck.xRotDead = var.chuck.xMax * 2
endif
if var.chuck.xRotdead < var.chuck.xMin * 2
var.chuck.xRotDead = var.chuck.xMin * 2
endif
if var.chuck.zRotdead > var.chuck.zMax * 2
var.chuck.zRotDead = var.chuck.zMax * 2
endif
if var.chuck.zRotdead < var.chuck.zMin * 2
var.chuck.zRotDead = var.chuck.zMin * 2
endif
// Wiimote value is divided by 25 to create -1/1 variance
// each set is a different mode setting
if var.wiimote.mode = 1
PPJoy.Analog0 = -var.xRotDead / 25
PPJoy.Analog1 = var.zRotDead / 25
If var.xRotDead = 0.00
wiimote.led1 = 1
else
wiimote.led1 = 0
endif
If var.zRotDead = 0.00
wiimote.led2 = 1
else
wiimote.led2 = 0
endif
endif
if var.wiimote.mode = 2
PPJoy.Analog1 = var.xRotDead / 25
PPJoy.Analog0 = var.zRotDead / 25
If var.xRotDead = 0.00
wiimote.led1 = 1
else
wiimote.led1 = 0
endif
If var.zRotDead = 0.00
wiimote.led2 = 1
else
wiimote.led2 = 0
endif
endif
if var.wiimote.mode = 3
PPJoy.Analog0 = -var.xRotDead / 25
PPJoy.Analog1 = -var.yRotDead / 25
If var.xRotDead = 0.00
wiimote.led1 = 1
else
wiimote.led1 = 0
endif
If var.yRotDead = 0.00
wiimote.led2 = 1
else
wiimote.led2 = 0
endif
endif
// Nunchuk value is divided by 50 to create -1/1 variance
PPJoy.Analog2 = -var.chuck.xRotDead / 50
PPJoy.Analog3 = var.chuck.zRotDead / 50
// Nunchuk's Joystick
PPJoy.Analog4 = MapRange(Wiimote.Nunchuk.JoyX, -1,1, -1,1)
PPJoy.Analog5 = - MapRange(Wiimote.Nunchuk.JoyY, -1,1, -1,1)
// Debug window output
debug = "wiimote X= " + var.xRotDead + " y= " + var.yRotDead + " z= " + var.zRotDead + " | chuck X= " + var.chuck.xRotDead / 2 + " Z= " + var.chuck.zRotDead / 2
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|