本文整理汇总了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()
示例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
示例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))