wiimoteTests.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00003 #
00004 #    WIIMote Run Tests
00005 #
00006 #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00007 
00008 # TODO: Don't duplicate cwiid constants in armConrolConstants.py
00009 # TODO: Offer exception if stdev is too high in IMU readings
00010 # TODO: Zeroing
00011 # TODO: Catch wiimote being turned off.
00012 
00013 
00014 import WIIMote
00015 from wiimoteExceptions import *
00016 from wiiutils import *
00017 from wiistate import *
00018 import numpy as np 
00019 
00020 mySampleRate = 1
00021 try:
00022   ac = WIIMote.WIIMote(theSampleRate = mySampleRate)
00023   ac.zeroDevice()
00024 
00025   #********************
00026 #  numSamples = 50
00027 #
00028 #  accMeans  = []
00029 #  accStdevs = []
00030 #  gyroMeans = []
00031 #  gyroStdevs = []
00032 #  
00033 #  for i in range(numSamples):
00034 #      ac.zero()
00035 #      accMeans.append(ac.meanAcc)
00036 #      accStdevs.append(ac.stdevAcc)
00037 #      gyroMeans.append(ac.meanGyro)
00038 #      gyroStdevs.append(ac.stdevGyro)
00039 #      
00040 #  accMean =   np.vstack(accMeans).mean(axis=0)
00041 #  accStdev =  np.vstack(accMeans).std(axis=0)
00042 #  gyroMean =   np.vstack(gyroMeans).mean(axis=0)
00043 #  gyroStdev =  np.vstack(gyroMeans).std(axis=0)
00044 #  
00045 #  report("Acc mean: " + `accMean` + " Min mean: " + `np.vstack(accMeans).min(axis=0)` + " Max mean: " + `np.vstack(accMeans).max(axis=0)`)
00046 #  report("Acc stdev: " + `np.vstack(accMeans).std(axis=0)`)
00047 #  
00048 #  report("Gyro mean: " + `gyroMean` + " Min gyro: " + `np.vstack(gyroMeans).min(axis=0)` + " Max gyro: " + `np.vstack(gyroMeans).max(axis=0)`)
00049 #  report("Gyro stdev: " + `gyroStdev`)
00050 #
00051 #  
00052 #  
00053 #  
00054 #  exit(0)      
00055 #  
00056 #  report ("Acc list: " + `map(lambda wiiReading: wiiReading.tuple(), ac._accList)`)
00057 #  report ("Acc mean: " + `ac.meanAcc` + " Acc stdev: " + `ac.stdevAcc`)
00058 #  report ("Gyro list: " + `map(lambda wiiReading: wiiReading.tuple(), ac._gyroList[1:])`)
00059 #  report ("Gyro mean: " + `ac.meanGyro` + " Gyro stdev: " + `ac.stdevGyro`)
00060   #********************
00061   
00062   #ac.integrate()
00063 except WiimoteError, e:
00064   report(e)
00065   exit()
00066 
00067 ledCycle = 0
00068 try:
00069   while True:
00070     #time.sleep(.2)
00071     time.sleep(mySampleRate)
00072     
00073     ac.printState()
00074 
00075     if ledCycle == 0:
00076       ac.setLEDs([True, False, False, False])  
00077     elif ledCycle == 1:
00078       ac.setLEDs([False, True, False, False])
00079     elif ledCycle == 2:
00080       ac.setLEDs([False, False, True, False])
00081     elif ledCycle == 3:
00082       ac.setLEDs([False, False, False, True])
00083     elif ledCycle == 4:
00084       ac.setLEDs([True, False, False, None])
00085     elif ledCycle == 5:
00086       ac.setLEDs([None, True, True, None])
00087     elif ledCycle == 6:
00088       ac.setLEDs([False, False, False, False])
00089     ledCycle += 1
00090     if ledCycle >= 7:
00091       ledCycle = 0
00092       #******ac.setRumble(not ac.getRumble())
00093 
00094 
00095 finally:
00096   ac.shutdown()


wiimote
Author(s): Andreas Paepcke, Melonee Wise, Mark Horn
autogenerated on Sat Jun 8 2019 20:54:42