wiimoteTests.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 #
4 # WIIMote Run Tests
5 #
6 #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 
8 # TODO: Don't duplicate cwiid constants in armConrolConstants.py
9 # TODO: Offer exception if stdev is too high in IMU readings
10 # TODO: Zeroing
11 # TODO: Catch wiimote being turned off.
12 
13 
14 import WIIMote
15 from wiimoteExceptions import *
16 from wiiutils import *
17 from wiistate import *
18 import numpy as np
19 
20 mySampleRate = 1
21 try:
22  ac = WIIMote.WIIMote(theSampleRate = mySampleRate)
23  ac.zeroDevice()
24 
25  #********************
26 # numSamples = 50
27 #
28 # accMeans = []
29 # accStdevs = []
30 # gyroMeans = []
31 # gyroStdevs = []
32 #
33 # for i in range(numSamples):
34 # ac.zero()
35 # accMeans.append(ac.meanAcc)
36 # accStdevs.append(ac.stdevAcc)
37 # gyroMeans.append(ac.meanGyro)
38 # gyroStdevs.append(ac.stdevGyro)
39 #
40 # accMean = np.vstack(accMeans).mean(axis=0)
41 # accStdev = np.vstack(accMeans).std(axis=0)
42 # gyroMean = np.vstack(gyroMeans).mean(axis=0)
43 # gyroStdev = np.vstack(gyroMeans).std(axis=0)
44 #
45 # report("Acc mean: " + `accMean` + " Min mean: " + `np.vstack(accMeans).min(axis=0)` + " Max mean: " + `np.vstack(accMeans).max(axis=0)`)
46 # report("Acc stdev: " + `np.vstack(accMeans).std(axis=0)`)
47 #
48 # report("Gyro mean: " + `gyroMean` + " Min gyro: " + `np.vstack(gyroMeans).min(axis=0)` + " Max gyro: " + `np.vstack(gyroMeans).max(axis=0)`)
49 # report("Gyro stdev: " + `gyroStdev`)
50 #
51 #
52 #
53 #
54 # exit(0)
55 #
56 # report ("Acc list: " + `map(lambda wiiReading: wiiReading.tuple(), ac._accList)`)
57 # report ("Acc mean: " + `ac.meanAcc` + " Acc stdev: " + `ac.stdevAcc`)
58 # report ("Gyro list: " + `map(lambda wiiReading: wiiReading.tuple(), ac._gyroList[1:])`)
59 # report ("Gyro mean: " + `ac.meanGyro` + " Gyro stdev: " + `ac.stdevGyro`)
60  #********************
61 
62  #ac.integrate()
63 except WiimoteError, e:
64  report(e)
65  exit()
66 
67 ledCycle = 0
68 try:
69  while True:
70  #time.sleep(.2)
71  time.sleep(mySampleRate)
72 
73  ac.printState()
74 
75  if ledCycle == 0:
76  ac.setLEDs([True, False, False, False])
77  elif ledCycle == 1:
78  ac.setLEDs([False, True, False, False])
79  elif ledCycle == 2:
80  ac.setLEDs([False, False, True, False])
81  elif ledCycle == 3:
82  ac.setLEDs([False, False, False, True])
83  elif ledCycle == 4:
84  ac.setLEDs([True, False, False, None])
85  elif ledCycle == 5:
86  ac.setLEDs([None, True, True, None])
87  elif ledCycle == 6:
88  ac.setLEDs([False, False, False, False])
89  ledCycle += 1
90  if ledCycle >= 7:
91  ledCycle = 0
92  #******ac.setRumble(not ac.getRumble())
93 
94 
95 finally:
96  ac.shutdown()
def report(str, debuglevel=acConst._DEBUGLEVEL)
Definition: wiiutils.py:30


wiimote
Author(s): Andreas Paepcke, Melonee Wise, Mark Horn
autogenerated on Fri Jun 7 2019 22:01:33