def __init__(self, tracker = None, probeYaw = False, probePitch = False):
        # ------------ Connecting to wii remote.
        self.mote = None
        self.tracker = tracker
        self.monitor = xwiimote.monitor(True, True)
        while self.mote == None:
            self.mote = self.monitor.poll()
            rospy.sleep(1)


        # ------------ Setting up wii remote.
        self.mote = xwiimote.iface(self.mote)
        self.mote.open(self.mote.available() | xwiimote.IFACE_WRITABLE)
        self.mote.open(self.mote.available() | xwiimote.IFACE_ACCEL)
        self.mote.open(self.mote.available() | xwiimote.IFACE_MOTION_PLUS)
        self.poller = poll()
        self.poller.register(self.mote.get_fd(), POLLIN)
        self.event = xwiimote.event()

        # ------------ Parameters, data, etc.
        self.current = [0,0,0]
        self.resting = [0,0,0]
        self.last_reading = rospy.Time.now()
        self.last_button_press = rospy.Time.now()
        self.target = [30, 0, -20] # just for testing purposes
        self.index = 0 # ditto
        self.rumble_proportion = 0

        self.probeYaw = probeYaw
        self.probePitch = probePitch

        # ----------- ROS Publishers/subscribers.
        self.button_pub = rospy.Publisher("/wii_buttons", Int32, queue_size=10)
        self.orientation_pub = rospy.Publisher("/wii_orientation", Int32MultiArray, queue_size=10)
        rospy.Subscriber("/wii_rumble", Float32, self.set_rumble)
Пример #2
0
def get_first_wiimote(logger):
    ent = None

    try:
        ent = xwiimote.monitor(True, True).poll()
    except SystemError as e:
        logger.error("Unable to init monitor: ", e)

    return ent
Пример #3
0
    def setup_monitor(self):
        # setup monitor
        try:
            mon = xwiimote.monitor(True, True)
            print("mon fd", mon.get_fd(False))
            return mon

        except SystemError as e:
            print("ooops, cannot create monitor (", e, ")")
Пример #4
0
    def __init__(self):
        self.mote = None
        self.monitor = xwiimote.monitor(True, True)
        while self.mote == None:
            self.mote = self.monitor.poll()
            rospy.sleep(1)

        self.mote = xwiimote.iface(self.mote)
        self.mote.open(self.mote.available() | xwiimote.IFACE_WRITABLE)
        self.poller = poll()
        self.poller.register(self.mote.get_fd(), POLLIN)
        self.event = xwiimote.event()
Пример #5
0
 def _wait_for_balanceboard(self):
     print "Waiting for balanceboard to connect.."
     monitor = xwiimote.monitor(True, False)
     t = time.time()
     print "Start searching for WiiBalanceBoard device..."
     while time.time() - t < 30:
         monitor.get_fd(False)
         device = monitor.poll()
         if device != None and self._device_is_balanceboard(device):
             return device
         else:
             print "Found non-WiiBalanceBoard device"
             print "Waiting.."
     return device
Пример #6
0
def get_balance_board_iface():
    mon = xwiimote.monitor(True, True)
    wiimote_path = mon.poll()
    while wiimote_path is not None:
        dev = xwiimote.iface(wiimote_path)
        if dev.get_extension() == 'balanceboard':
            mask = dev.available() | xwiimote.IFACE_BALANCE_BOARD
            dev.open(mask)
            yield dev
            dev.close()
            break
        wiimote_path = mon.poll()
    else:
        raise BalanceBoardConnectionError
Пример #7
0
 def _wait_for_balanceboard(self):
     print "Waiting for balanceboard to connect.."
     monitor = xwiimote.monitor(True, False)
     t = time.time()
     print "Start searching for WiiBalanceBoard device..."
     while time.time()-t < 30:
         monitor.get_fd(False)
         device = monitor.poll()
         if device != None and self._device_is_balanceboard(device):
             return device
         else:
             print "Found non-WiiBalanceBoard device"
             print "Waiting.."
     return device
Пример #8
0
def WaitForBoard():
    print("Waiting for board to connect...")
    mon = xwiimote.monitor(True, False)
    dev = None
    while True:
        print('waiting for board')
        mon.get_fd(True)  # blocks
        connected = mon.poll()
        if connected == None:
            continue
        elif IsBoard(connected):
            print("Found board.")
            dev = connected
            break
        else:
            print("Waiting...")
    return dev
Пример #9
0
def wait4bb():
    """Wait for balance board."""
    print("Waiting for balance board to connect.")
    mon = xwiimote.monitor(True, False)
    devpath = None
    while True:
        mon.get_fd(True)  # blocks
        connected = mon.poll()
        if connected == None:
            continue
        elif dev_is_balanceboard(connected):
            print("Found balanceboard:", connected)
            devpath = connected
            break
        else:
            print("Found non-balanceboard device:", connected)
            print("Still waiting...")
    return devpath
Пример #10
0
def wait_for_balanceboard():
    print("Waiting for balanceboard to connect..")
    mon = xwiimote.monitor(True, False)
    dev = None

    while True:
        mon.get_fd(True) # blocks
        connected = mon.poll()

        if connected == None:
            continue
        elif dev_is_balanceboard(connected):
            print("Found balanceboard:", connected)
            dev = connected
            break
        else:
            print("Found non-balanceboard device:", connected)
            print("Waiting..")

    return dev
Пример #11
0
# test with
# sudo LD_LIBRARY_PATH=<prefix>/lib PYTHONPATH=<prefix>/lib/python2.7/site-packages python ./swig/python/xwiimote_test.py

import errno
from time import sleep
from select import poll, POLLIN
from inspect import getmembers
from pprint import pprint
import xwiimote

# display a constant
print "=== " + xwiimote.NAME_CORE + " ==="

# list wiimotes and remember the first one
try:
    mon = xwiimote.monitor(True, True)
    print "mon fd", mon.get_fd(False)
    ent = mon.poll()
    firstwiimote = ent
    while ent is not None:
        print "Found device: " + ent
        ent = mon.poll()
except SystemError as e:
    print "ooops, cannot create monitor (", e, ")"

# continue only if there is a wiimote
if firstwiimote is None:
    print "No wiimote to read"
    exit(0)

# create a new iface
Пример #12
0
    return False


#
p = select.poll()

# watched wiimotes
wiimotes = {
    'all': [],
    xwiimote.IFACE_CLASSIC_CONTROLLER: [],
    xwiimote.IFACE_DRUMS: [],
    xwiimote.IFACE_GUITAR: []
}

try:
    mon = xwiimote.monitor(True, False)
    newmotes = read_monitor(mon, wiimotes)
    for dev in newmotes:
        p.register(dev.get_fd(), select.POLLIN)
    print_wiimotes(wiimotes)
except SystemError as e:
    print "ooops, cannot create monitor (", e, ")"
    exit(1)

# register devices
mon_fd = mon.get_fd(False)
p.register(mon_fd, select.POLLIN)

revt = xwiimote.event()
try:
    while True:
Пример #13
0
        dev.open(ext)
        currents.append(dev)
        return True
    except IOError:
        print "Ooops, unable to open the device"

    return False

#
p = select.poll()

# watched wiimotes
wiimotes = {'all':[], xwiimote.IFACE_CLASSIC_CONTROLLER:[], xwiimote.IFACE_DRUMS:[], xwiimote.IFACE_GUITAR:[]}

try:
    mon = xwiimote.monitor(True, False)
    newmotes = read_monitor(mon, wiimotes)
    for dev in newmotes:
        p.register(dev.get_fd(), select.POLLIN)
    print_wiimotes(wiimotes)
except SystemError as e:
    print "ooops, cannot create monitor (", e, ")"
    exit(1)

# register devices
mon_fd = mon.get_fd(False)
p.register(mon_fd, select.POLLIN)

revt = xwiimote.event()
try:
    while True: