當前位置: 首頁>>代碼示例>>Python>>正文


Python InterfaceKit.getSensorRawValue方法代碼示例

本文整理匯總了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.getSensorRawValue方法的典型用法代碼示例。如果您正苦於以下問題:Python InterfaceKit.getSensorRawValue方法的具體用法?Python InterfaceKit.getSensorRawValue怎麽用?Python InterfaceKit.getSensorRawValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phidgets.Devices.InterfaceKit.InterfaceKit的用法示例。


在下文中一共展示了InterfaceKit.getSensorRawValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Interface

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorRawValue [as 別名]
class Interface(Model):
    def __init__(self, serial_number):
        self._phidget = InterfaceKit()
        self._serial_number = serial_number
        self._is_initialized = False
    
    def initialize(self):
        if not self._is_initialized:
            self._phidget.openPhidget(serial = self._serial_number)
            self._phidget.waitForAttach(ATTACH_TIMEOUT)
            self._phidget.setRatiometric(False) #note the default is True!
            self._is_initialized = True
            
    def identify(self):
        if not self._is_initialized:
            self.initialize()
        name = self._phidget.getDeviceName()
        serial_number = self._phidget.getSerialNum()
        return "%s, Serial Number: %d" % (name, serial_number)
    
    def read_sensor(self, index):
        """ reads the raw value from the sensor at 'index' 
            returns integer in range [0,4095]
        """
        if not self._is_initialized:
            self.initialize()
        return self._phidget.getSensorRawValue(index)
    
    def read_all_sensors(self):
        """ reads all the sensors raw values, indices 0-7
            returns list of 8 integers in range [0,4095]
        """
        if not self._is_initialized:
            self.initialize()
        values = []
        for i in range(8):
            values.append(self.read_sensor(i))
        return values    
    
    def read_digital_input(self,index):
        """ reads the digital input at 'index' 
            returns True if grounded, False if open (pulled-up to 5V)
        """
        if not self._is_initialized:
            self.initialize()
        return self._phidget.getInputState(index)
    
    def write_digital_output(self,index,state):
        if not self._is_initialized:
            self.initialize()
        return self._phidget.setOutputState(index,state)
    
    def shutdown(self):
        if not self._is_initialized:
            self.initialize()
        self._phidget.closePhidget()
        self._is_initialized = False
    
    def __del__(self):
        self.shutdown()
開發者ID:cversek,項目名稱:yes-o2ab,代碼行數:62,代碼來源:kit1018.py

示例2: range

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorRawValue [as 別名]
    for i in range(interfaceKitHUB.getSensorCount()):
        try:
            #intval = interfaceKitHUB.getSensorValue(i)
            #if 0 reading, don't try and convert
            #if not intval:
            #    continue

            if i >= 6:
                #Sonar sensor range 0cm - 645cm
                #Plugged into analog input 6 & 7 for N (forward) and S (reverse)

                #turn on the sonar sensor via digital output 'i'
                interfaceKitHUB.setOutputState(i,True)
                #intval = interfaceKitHUB.getSensorValue(i)
                #sleep(0.1) # Wait for sonar to activate
                intval = interfaceKitHUB.getSensorRawValue(i) #Read sonar
                print intval, i
                distance_mm = (intval / 4.095 ) * 12.96 #convert raw value to mm
                #Check that value is within permissable range
                if distance_mm > 6450.0:
                    distance_mm = -1

                #turn off the sonar sensor via digital output 'i'
                interfaceKitHUB.setOutputState(i,False)
                sleep(0.4)
                #save value into array
                #message.append(distance_mm)
            else:
                #IR range 20cm - 150cm (2.5V - 0.4V)
                #Read seonsor value
                intval = interfaceKitHUB.getSensorRawValue(i)
開發者ID:AustralianSynchrotron,項目名稱:Australian-Synchrotron-Surveyor-Tunnel-Exploration-And-Fault-Detection-Robot,代碼行數:33,代碼來源:srv_irdist.py

示例3: range

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorRawValue [as 別名]
    for i in range(interfaceKitHUB.getSensorCount()):
        try:
            #intval = interfaceKitHUB.getSensorValue(i)
            #if 0 reading, don't try and convert
            #if not intval:
            #    continue

            if i >= 6:
                #Sonar sensor range 0cm - 645cm
                #Plugged into analog input 6 & 7 for N (forward) and S (reverse)
                #for j in range(6,7):
                interfaceKitHUB.setOutputState(i,True)
                #intval = interfaceKitHUB.getSensorValue(i)
                sleep(0.1)
                intval = interfaceKitHUB.getSensorRawValue(i)
                print intval, i
                distance_mm = (intval / 4.095 ) * 12.96
                if distance_mm > 6450.0:
                    distance_mm = -1
                interfaceKitHUB.setOutputState(i,False)
                sleep(0.4)
                message.append(distance_mm)
            else:
                #IR range 20cm - 150cm (2.5V - 0.4V)
                intval = interfaceKitHUB.getSensorRawValue(i)
                print intval
                distance_mm = (9462/((intval / 4.095) - 16.92)) * 10
                #Not a reliable mesaurement below 200mm (20cm) or above 1500 (150cm)
                if (distance_mm < 200.0) or (distance_mm > 1500.0):
                    distance_mm = -1
開發者ID:nomad-cam,項目名稱:ass-bot,代碼行數:32,代碼來源:srv_irdist.py

示例4: dict

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorRawValue [as 別名]
s = dict()    
s['sens'] = np.zeros((1,2))
s['start_time'] = time.time()
sec_of_dat = 600
f_s = 60
err_ind = []
for i in range(sec_of_dat*f_s):
    s['tic'] = time.time()

    sensdat = np.zeros((1,2))
    try:
        sensdat[0,0] = kit.getSensorValue(0)/1000.
        sensdat[0,1] = kit.getSensorValue(1)/1000.
    except:
        print time.time() - s['start_time'], i
        print kit.isAttached()
        err_ind.extend([i])

    try:
        print kit.getSensorRawValue(2), kit.getSensorValue(2)
    except:
        print 'novalue'

    s['sens'] = np.vstack((s['sens'], sensdat))
    left_over_time = np.max([0, 1000/60. - (time.time() - s['tic'])])
    time.sleep(left_over_time/1000.)
kit.closePhidget()
plt.plot(np.array(err_ind)/float(f_s))


開發者ID:carmenalab,項目名稱:brain-python-interface,代碼行數:30,代碼來源:test_phidgets_joystick_acqu.py


注:本文中的Phidgets.Devices.InterfaceKit.InterfaceKit.getSensorRawValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。