コード例 #1
0
def watchAngles_(angleCallback=None, maxTime=None):
    t0 = time.time()
    #device_list = ts_api.getComPorts(filter=ts_api.TSS_FIND_USB)
    device_list = ts_api.getComPorts()

    print "device_list:", device_list
    com_port = device_list[0]
    device = ts_api.TSBTSensor(com_port=com_port)

    ## If a connection to the COM port fails, None is returned.
    if not device:
        print "Cannot get device"
        return

    ## The class instances have all of the functionality that corresponds to the
    ## 3-Space Sensor device type it is representing.
    print("==================================================")
    print("Getting the filtered tared quaternion orientation.")
    quat = device.getTaredOrientationAsQuaternion()
    if quat is not None:
        print(quat)
    print("==================================================")
    print("Getting the raw sensor data.")
    data = device.getAllRawComponentSensorData()
    gyro = data[:3]
    print "gyro:", gyro
    if data is not None:
        print data
        print(
            "[%f, %f, %f] --Gyro\n"
            "[%f, %f, %f] --Accel\n"
            "[%f, %f, %f] --Comp" % data)

    i = 0
    while 1:
        i += 1
        t = time.time()
        dt = t - t0
        if maxTime and dt > maxTime:
            break
        angles = device.getTaredOrientationAsEulerAngles()
        #print i, angles
        angles = map(math.degrees, angles)
        pitch, roll, yaw = angles
        print "%4d %7.1f %7.1f %7.1f" % (i, yaw, pitch, roll)
        if angleCallback != None:
            angleCallback(angles)

    ## Now close the port.
    device.close()
コード例 #2
0
ファイル: YEIWatcher.py プロジェクト: WorldViews/PhysViz
def watchAngles_(angleCallback=None, maxTime=None):
    t0 = time.time()
    #device_list = ts_api.getComPorts(filter=ts_api.TSS_FIND_USB)
    device_list = ts_api.getComPorts()

    print "device_list:", device_list
    com_port = device_list[0]
    device = ts_api.TSBTSensor(com_port=com_port)

    ## If a connection to the COM port fails, None is returned.
    if not device:
        print "Cannot get device"
        return

    ## The class instances have all of the functionality that corresponds to the
    ## 3-Space Sensor device type it is representing.
    print("==================================================")
    print("Getting the filtered tared quaternion orientation.")
    quat = device.getTaredOrientationAsQuaternion()
    if quat is not None:
        print(quat)
    print("==================================================")
    print("Getting the raw sensor data.")
    data = device.getAllRawComponentSensorData()
    gyro = data[:3]
    print "gyro:", gyro
    if data is not None:
        print data
        print("[%f, %f, %f] --Gyro\n"
              "[%f, %f, %f] --Accel\n"
              "[%f, %f, %f] --Comp" % data)

    i = 0
    while 1:
        i += 1
        t = time.time()
        dt = t - t0
        if maxTime and dt > maxTime:
            break
        angles = device.getTaredOrientationAsEulerAngles()
        #print i, angles
        angles = map(math.degrees, angles)
        pitch, roll, yaw = angles
        print "%4d %7.1f %7.1f %7.1f" % (i, yaw, pitch, roll)
        if angleCallback != None:
            angleCallback(angles)

    ## Now close the port.
    device.close()
コード例 #3
0
def begin():
    """NEED TO PAIR DEVICES FIRST
	will read temp from paired devices for given time
	then write data to an array
	uses thread for each sensor"""
    device_list = ts_api.getComPorts(filter=ts_api.TSS_FIND_DNG)
    print device_list

    com_port = device_list[0]
    dng_device = ts_api.TSDongle(com_port=com_port)

    for i in xrange(numDevices):
        wl_devices.append(dng_device[i])

    for device in wl_devices:
        newThread = threadFunction(device)
        threads.append(newThread)
        newThread.start()

    for thread in threads:
        thread.join()

    return concatData
コード例 #4
0
ファイル: create_devices.py プロジェクト: WorldViews/Spirals
    print(device)

    ## Now close the port.
    if device is not None:
        device.close()

## If the COM port is not known or the device type is not known for the 3-Space
## Sensor device, we must do a search for the devices. We can do this by calling
## the getComPorts function which returns a lists of COM port information.
## (both known 3-Space Sensor devices and unknown devices)
## getComPorts also as a parameter called filter that takes a mask that denotes
## what type of 3-Space Sensor device can be found. If filter is not used or set
## to None all connected 3-Space Sensor devices and unknown devices are found.
## Each COM port information is a list containing
## (COM port name, friendly name, 3-Space Sensor device type)
device_list = ts_api.getComPorts()


## Now go through our list of devices and create the appropriate instance by
## using the devices' type and COM port. Unknown devices could be 3-Space Sensor
## devices that were connected via a serial connection. We can find out if there
## is any 3-Space Sensor devices by using the getSensorInfo function. However,
## we must send commands over the port which could make devices other than
## 3-Space Sensor devices act strangely. So, be sure to know what port your
## 3-Space Sensor device(s) are on when calling this function.
## getSensorInfo returns a list of information that it found from the COM port
## (Friendly name, 3-Space Type, 3-Space ID, 3-Space Firmware Version String,
##  3-Space Hardware Version String, is in bootloader mode)
for device_port in device_list:
    com_port, friendly_name, device_type = device_port
    if device_type == "USB":
コード例 #5
0
    print(device)

    ## Now close the port.
    if device is not None:
        device.close()

## If the COM port is not known or the device type is not known for the 3-Space
## Sensor device, we must do a search for the devices. We can do this by calling
## the getComPorts function which returns a lists of COM port information.
## (both known 3-Space Sensor devices and unknown devices)
## getComPorts also as a parameter called filter that takes a mask that denotes
## what type of 3-Space Sensor device can be found. If filter is not used or set
## to None all connected 3-Space Sensor devices and unknown devices are found.
## Each COM port information is a list containing
## (COM port name, friendly name, 3-Space Sensor device type)
device_list = ts_api.getComPorts()

## Now go through our list of devices and create the appropriate instance by
## using the devices' type and COM port. Unknown devices could be 3-Space Sensor
## devices that were connected via a serial connection. We can find out if there
## is any 3-Space Sensor devices by using the getSensorInfo function. However,
## we must send commands over the port which could make devices other than
## 3-Space Sensor devices act strangely. So, be sure to know what port your
## 3-Space Sensor device(s) are on when calling this function.
## getSensorInfo returns a list of information that it found from the COM port
## (Friendly name, 3-Space Type, 3-Space ID, 3-Space Firmware Version String,
##  3-Space Hardware Version String, is in bootloader mode)
for device_port in device_list:
    com_port, friendly_name, device_type = device_port
    if device_type == "USB":
        device = ts_api.TSUSBSensor(com_port=com_port)
コード例 #6
0
## YEI 3-Space Python API

import threespace_api as ts_api

## If the COM port is not known or the device type is not known for the 3-Space
## Sensor device, we must do a search for the devices. We can do this by calling
## the getComPorts function which returns a lists of COM port information.
## (both known 3-Space Sensor devices and unknown devices)
## getComPorts also as a parameter called filter that takes a mask that denotes
## what type of 3-Space Sensor device can be found. If filter is not used or set
## to None all connected 3-Space Sensor devices and unknown devices are found.
## Each COM port information is a list containing
## (COM port name, friendly name, 3-Space Sensor device type)
## This example makes use of the filter parameter of getComPorts and just
## searches for Wireless devices and Dongle devices.
device_list = ts_api.getComPorts(filter=ts_api.TSS_FIND_DNG)

## Only the 3-Space Sensor Dongle device is connected so we are just going to
## take the first one from the list.
com_port = device_list[0]
dng_device = ts_api.TSDongle(com_port=com_port)

## If a connection to the COM port fails, None is returned.
if dng_device is not None:
    ## Now we need to get our Wireless device from our Dongle device.
    ## Indexing into the TSDongle instance like it was a list will return a
    ## TSWLSensor instance.
    wl_device = dng_device[0]

    ## Now we can start getting information from the Wireless device.
    ## The class instances have all of the functionality that corresponds to the
コード例 #7
0
ファイル: set_data_ex.py プロジェクト: Knio/threespace
import threespace_api as ts_api
import time

## If the COM port is not known or the device type is not known for the 3-Space
## Sensor device, we must do a search for the devices. We can do this by calling
## the getComPorts function which returns a lists of COM port information.
## (both known 3-Space Sensor devices and unknown devices)
## getComPorts also as a parameter called filter that takes a mask that denotes
## what type of 3-Space Sensor device can be found. If filter is not used or set
## to None all connected 3-Space Sensor devices and unknown devices are found.
## Each COM port information is a list containing
## (COM port name, friendly name, 3-Space Sensor device type)
## This example makes use of the filter parameter of getComPorts and just
## searches for 3-Space Sensor USB devices.
device_list = ts_api.getComPorts(filter=ts_api.TSS_FIND_USB)


## Only one 3-Space Sensor device is needed so we are just going to take the
## first one from the list.
com_port = device_list[0]
device = ts_api.TSUSBSensor(com_port=com_port)
## If a connection to the COM port fails, None is returned.
if device is not None:
    ## Now we can start getting information from the device.
    ## The class instances have all of the functionality that corresponds to the
    ## 3-Space Sensor device type it is representing.
    print("==================================================")
    print("Setting the tared data of the device to an arbitrary quaternion.")
    if device.tareWithQuaternion([0, 0, 0, 1]):
        quat = device.getTareAsQuaternion()
コード例 #8
0
## YEI 3-Space Python API

import threespace_api as ts_api

## If the COM port is not known or the device type is not known for the 3-Space
## Sensor device, we must do a search for the devices. We can do this by calling
## the getComPorts function which returns a lists of COM port information.
## (both known 3-Space Sensor devices and unknown devices)
## getComPorts also as a parameter called filter that takes a mask that denotes
## what type of 3-Space Sensor device can be found. If filter is not used or set
## to None all connected 3-Space Sensor devices and unknown devices are found.
## Each COM port information is a list containing
## (COM port name, friendly name, 3-Space Sensor device type)
## This example makes use of the filter parameter of getComPorts and just
## searches for Wireless devices and Dongle devices.
device_list = ts_api.getComPorts(filter=ts_api.TSS_FIND_DNG|ts_api.TSS_FIND_WL)


## Now go through our known list of 3-Space Sensor devices and create the
## appropriate instance by using the devices' type and COM port
dng_device = None
wl_device = None
for device_port in device_list:
    com_port, friendly_name, device_type = device_port
    if device_type == "DNG":
        dng_device = ts_api.TSDongle(com_port=com_port)
    elif device_type == "WL":
        wl_device = ts_api.TSWLSensor(com_port=com_port)

## If a connection to the COM port fails, None is returned.
if dng_device is not None and wl_device is not None:
コード例 #9
0
ファイル: get_batch_data.py プロジェクト: WorldViews/Spirals
################## First getting data over a wired connection ##################
################################################################################

## If the COM port is not known or the device type is not known for the 3-Space
## Sensor device, we must do a search for the devices. We can do this by calling
## the getComPorts function which returns a lists of COM port information.
## (both known 3-Space Sensor devices and unknown devices)
## getComPorts also as a parameter called filter that takes a mask that denotes
## what type of 3-Space Sensor device can be found. If filter is not used or set
## to None all connected 3-Space Sensor devices and unknown devices are found.
## Each COM port information is a list containing
## (COM port name, friendly name, 3-Space Sensor device type)
## This example makes use of the filter parameter of getComPorts and just
## searches for wired 3-Space Sensor devices excluding Dongle devices.
filter_flag = ts_api.TSS_FIND_ALL_KNOWN^ts_api.TSS_FIND_DNG
device_list = ts_api.getComPorts(filter=filter_flag)


## Only one 3-Space Sensor device is needed so we are just going to take the
## first one from the list.
com_port, friendly_name, device_type = device_list[0]
device = None
if device_type == "USB":
    device = ts_api.TSUSBSensor(com_port=com_port)
elif device_type == "WL":
    device = ts_api.TSWLSensor(com_port=com_port)
elif device_type == "EM":
    device = ts_api.TSEMSensor(com_port=com_port)
elif device_type == "DL":
    device = ts_api.TSDLSensor(com_port=com_port)
elif device_type == "BT":