GlovePIE:Capture Motion Data

From WiiLi

Jump to: navigation, search

Captures wiimote & nunchuk motion data to output.txt file in GlovePIE's directory.

/*                Capture Motion Data v1.1
***********************************************************
*                 Created by Rhys Legault                 *
*                 rhyslegault@hotmail.com                 *
*            Last Modified: February 25th, 2007           *
***********************************************************
*  Feel free to use, modify and redistribute this script  *
***********************************************************
*
*  About:
*  ------
*  This script outputs the following Wiimote and Nunchuk motion data to the output.txt file:
*  Wiimote data: gx, gy, gz, RelAccX, RelAccY, RelAccZ, Pitch, Roll, dot1x, dot2x, dot1y, dot2y,
*  Nunchuk data: gx, gy, gz, RelAccX, RelAccY, RelAccZ, Pitch, Roll
*
*  Controls:
*  ---------
*  To begin recording data click the Wiimote's A button
*  Click the Wiimote's A button to pause/resume recording data to file
*  Use the Wiimote's D-pad to change values displayed in the debug window
*  Hold down the Wiimote's Home button for 1 second to exit the script
*
*  Optional Settings: (Script must be adjusted below)
*  --------------------------------------------------
*  AddLabels  - A row of data labels are added when script is started  - Default = true
*  EnableLeds - Wiimote's LEDs display recording status                - Default = true
*  AddZeroes  - Rows of zeroes added to the file when recording pauses - Default = true (Easier to identify pauses in data recording)
*
*  Using the Data:
*  ---------------
*  This script outputs a comma-separated values(.csv) file to output.txt under the GlovePIE directory
*  After acquiring your data close GlovePIE
*  Rename the output.txt file to whatever.csv
*  Open the file with your favourite spreadsheet program (Microsoft Excel/OpenOffice.org Calc etc.)
*  Create graphs & analyze your data
*  Make new scripts, containing motion controls, for your favourite games or applications
*
*  Notes:
*  ------
*  - GlovePIE will append data to the output.txt file unless the program is closed and reopened (after which it will overwrite the file)
*  - Labels are added every time the script is started. If you start the script multiple times, multiple labels will be created.
*    You should close GlovePIE and rename the ouput.txt file between running this script multiple times or disable writing labels
*  - If you have problems renaming or deleting the output.txt file make sure all instances of GlovePIE are closed properly
*  - You can import the output.txt file into a spreadsheet program without renaming the file to .csv however you will have to manually
*    select that the file's data format is data separated by commas
*  - GlovePIE's default framerate is 40Hz.  When recording, each frame is recorded, therefore there should be 40 data entries every second.
*    This info should help you determine waiting times etc. for your new scripts
***********************************************************
*/

//Change this to false if you do not want labels added to the file
var.AddLabels = true

//Change this to false if you do not want LEDs to display the recording status
var.EnableLeds = true

//Change the values to display different LEDs for recording/not recording (valid values are 0-15)
var.LedsRecording    = 15  //15 = All 4 LEDs on
var.LedsNotRecording = 0   //0  = All 4 LEDs are off

//Change this value to false if you do not want rows of 0s to be written to file when recording motion data is paused
var.AddZeroes = true

//This value limits the rows of zeroes written to file for each pause in recording
var.ZeroesLimit = 100

//Initializes values
if var.Initialize = false
   var.DebugData = 1  //Debug window displays all motion data by default
   //Adds column labels to file each time the script is run
   if var.AddLabels then OutputToFile("gx" + ", " + "gy" + ", " + "gz" + ", " + "RelAccX" + ", " + "RelAccY" + ", " + "RelAccZ" + ", " + "Pitch" + ", " + "Roll" + ", " + "dot1x" + ", " + "dot2x" + ", " + "dot1y" + ", " + "dot2y" + ", " + "Ngx" + ", " + " Ngy" + ", " + "Ngz" + ", " + "NRelAccX" + ", " + "NRelAccY" + ", " + "NRelAccZ" + ", " + "NPitch" + ", " + "NRoll")
   var.Initialize = true
endif

//Use the Change this value to display only some motion data (Displaying all data may not fit in the debug window)
if Wiimote.Up    then var.DebugData = 0  //Debug window does not display any data
if Wiimote.Down  then var.DebugData = 1  //Debug window displays all motion data
if Wiimote.Left  then var.DebugData = 2  //Debug window displays Wiimote motion data
if Wiimote.Right then var.DebugData = 3  //Debug window displays Nunchuk motion data

//Click Wiimote A button to begin/pause recording data
if Clicked(Wiimote.A) && var.GetData = false
   var.GetData = true
elseif Clicked(Wiimote.A) && var.GetData = true
   var.GetData = false
endif

//Writes Wiimote's motion data to output.txt file
if var.GetData
   if var.EnableLeds then Wiimote.Leds = var.LedsRecording     //LEDs display recording status
   //Writes motion data to file
   OutputToFile(RemoveUnits(Wiimote.gx) + ", " + RemoveUnits(Wiimote.gy) + ", " + RemoveUnits(Wiimote.gz) + ", " +  RemoveUnits(Wiimote.RelAccX) + ", " + RemoveUnits(Wiimote.RelAccY) + ", " + RemoveUnits(Wiimote.RelAccZ) + ", " + RemoveUnits(Wiimote.Pitch) + ", " + RemoveUnits(Wiimote.Roll) + ", " + Wiimote.dot1x + ",  " + Wiimote.dot2x + ", " + Wiimote.dot1y + ", " + Wiimote.dot2y + ", " + Wiimote.Nunchuk.gx + ", " + Wiimote.Nunchuk.gy + ", " + Wiimote.Nunchuk.gz + ", " + RemoveUnits(Wiimote.Nunchuk.RelAccX) + ", " + RemoveUnits(Wiimote.Nunchuk.RelAccY) + ", " + RemoveUnits(Wiimote.Nunchuk.RelAccZ) + ", " + RemoveUnits(Wiimote.Nunchuk.Pitch) + ", " + RemoveUnits(Wiimote.Nunchuk.Roll))
   var.FirstRecord = true  //Ensures the first set of data written to file is Wiimote motion data and not zeroes
   var.Zeroes = 0
else
   if var.EnableLeds then Wiimote.Leds = var.LedsNotRecording  //LEDs display recording status
   //Writes rows of zeroes to file between recording motion data
   if var.AddZeroes && var.FirstRecord && var.Zeroes < var.ZeroesLimit
      OutputToFile(0 + ", " + 0 + ", " + 0 + ", " +  0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0 + ", " + 0)
      var.Zeroes++
   endif
endif

//Hold down the Wiimote's home button to exit the script
if HeldDown(Wiimote.Home, 1s) then ExitScript

//Displays motion data in debug window
if var.DebugData = 1
   debug = "gx: " + RemoveUnits(Wiimote.gx) + " gy: " + RemoveUnits(Wiimote.gy) + " gz: " + RemoveUnits(Wiimote.gz) + " AcX: " +  RemoveUnits(Wiimote.RelAccX) + " AcY: " + RemoveUnits(Wiimote.RelAccY) + " AcZ: " + RemoveUnits(Wiimote.RelAccZ) + " Pch: " + RemoveUnits(Wiimote.Pitch) + " Rol: " + RemoveUnits(Wiimote.Roll) + " Dt1X: " + Wiimote.dot1x + " Dt2X: " + Wiimote.dot2x + " Dt1Y: " + Wiimote.dot1y + " Dt2Y: " + Wiimote.dot2y + " Ngx: " + Wiimote.Nunchuk.gx + " Ngy: " + Wiimote.Nunchuk.gy + " Ngz:" + Wiimote.Nunchuk.gz + " NAcX: " + RemoveUnits(Wiimote.Nunchuk.RelAccX) + " NAcY: " + RemoveUnits(Wiimote.Nunchuk.RelAccY) + " NAcZ: " + RemoveUnits(Wiimote.Nunchuk.RelAccZ) + " NPch: " + RemoveUnits(Wiimote.Nunchuk.Pitch) + " NRol: " + RemoveUnits(Wiimote.Nunchuk.Roll)
   wait 100ms
elseif var.DebugData = 2
   debug = "gx: " + RemoveUnits(Wiimote.gx) + "   gy: " + RemoveUnits(Wiimote.gy) + "   gz: " + RemoveUnits(Wiimote.gz) + "   AcX: " +  RemoveUnits(Wiimote.RelAccX) + "   AcY: " + RemoveUnits(Wiimote.RelAccY) + "   AcZ: " + RemoveUnits(Wiimote.RelAccZ) + "   Pch: " + RemoveUnits(Wiimote.Pitch) + "   Rol: " + RemoveUnits(Wiimote.Roll) + "   Dt1X: " + Wiimote.dot1x + "   Dt2X: " + Wiimote.dot2x + "   Dt1Y: " + Wiimote.dot1y + "   Dt2Y: " + Wiimote.dot2y
   wait 100ms
elseif var.DebugData = 3
   debug = "Ngx: " + Wiimote.Nunchuk.gx + "   Ngy: " + Wiimote.Nunchuk.gy + "   Ngz: " + Wiimote.Nunchuk.gz + "   NAcX: " + RemoveUnits(Wiimote.Nunchuk.RelAccX) + "   NAcY: " + RemoveUnits(Wiimote.Nunchuk.RelAccY) + "   NAcZ: " + RemoveUnits(Wiimote.Nunchuk.RelAccZ) + "   NPch: " + RemoveUnits(Wiimote.Nunchuk.Pitch) + "   NRol: " + RemoveUnits(Wiimote.Nunchuk.Roll)
   wait 100ms
else
    debug = ""
endif
Personal tools
Online Casino - best online casino reviews.
Facebook Developers - facebook applications, facebook developers, facebook development, social network application development and viral widget social media strategy