本文整理汇总了Python中sensor.Sensor.gen_from_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Sensor.gen_from_bytes方法的具体用法?Python Sensor.gen_from_bytes怎么用?Python Sensor.gen_from_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor.Sensor
的用法示例。
在下文中一共展示了Sensor.gen_from_bytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import gen_from_bytes [as 别名]
def run(self):
while(self.running):
self._request_sensor()
self.data = self.sci.read(80)
self.sensor = Sensor.gen_from_bytes(self.data)
if self.prevSensor :
eventList = self.sensor.diff(self.prevSensor)
if (eventList and len(eventList)>0):
self._raise_event(eventList)
# 現状Create2からは正しいDistance値が取得できないため,encoderから計算する
leftDiff = self.sensor.encoderCountsLeft - self.prevSensor.encoderCountsLeft
rightDiff = self.sensor.encoderCountsRight - self.prevSensor.encoderCountsRight
# overflow check
if(leftDiff<-10000):
leftDiff += 65536
elif(leftDiff>10000):
leftDiff -= 65536
if(rightDiff<-10000):
rightDiff += 65536
elif(rightDiff>10000):
rightDiff -= 65536
self.leftEncoder += leftDiff
self.rightEncoder += rightDiff
self.totalDistance += (leftDiff + rightDiff)/2 * ENC_TO_DISTANCE
l = leftDiff * ENC_TO_DISTANCE
r = rightDiff * ENC_TO_DISTANCE
angleDiff = -(l-r) * 180/(WHEEL_BASE*2)/math.pi
self.totalAngle += angleDiff
# check reachDistance Event
if(self.nextDistance):
if(self.nextDistanceCompare):
if(self.totalDistance>self.nextDistance):
self.nextDistance=None
self.nextDistanceCompare=None
self._raise_event([Event.reachDistance])
#print "raise reachDistance1"
else:
if(self.totalDistance<self.nextDistance):
self.nextDistance=None
self.nextDistanceCompare=None
self._raise_event([Event.reachDistance])
#print "raise reachDistance2"
# check reachAngle Event
if(self.nextAngle):
if(self.nextAngleCompare):
if(self.totalAngle>self.nextAngle):
self.nextAngle=None
self.nextAngleCompare=None
self._raise_event([Event.reachAngle])
else:
if(self.totalAngle<self.nextAngle):
self.nextAngle=None
self.nextAngleCompare=None
self._raise_event([Event.reachAngle])
self.prevSensor = self.sensor
time.sleep(self.interval/1000)
示例2: request_all_sensor
# 需要导入模块: from sensor import Sensor [as 别名]
# 或者: from sensor.Sensor import gen_from_bytes [as 别名]
def request_all_sensor(self):
self.sci.flash_input()
requestBytes = [142, 100]
self.sci.send(requestBytes)
data = self.sci.read(80)
return Sensor.gen_from_bytes(data)