本文整理汇总了Python中packet.Packet.write_ubyte方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.write_ubyte方法的具体用法?Python Packet.write_ubyte怎么用?Python Packet.write_ubyte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.write_ubyte方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: controlLoop
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import write_ubyte [as 别名]
def controlLoop(ip):
global LIN_V, ANG_V
word = None
while('end' != word and 'exit' != word):
if len(cmd_buffer)> 0 :
word = cmd_buffer.pop(0)
print word
lv = 0
av = 0
if('forward' == word or 'charge' == word):
lv = LIN_V * 1
elif('backward' == word or 'reverse' == word):
lv = LIN_V * -1
elif('right' == word):
av = ANG_V * -1
elif('left' == word):
av = ANG_V * 1
elif('faster' == word):
LIN_V += 0.2
ANG_V += 0.2
print LIN_V, ANG_V
elif('slower' == word):
LIN_V = LIN_V - 0.2
ANG_V = ANG_V - 0.2
print LIN_V, ANG_V
elif('stop' == word):
lv = 0
av = 0
elif('sing' == word):
pkt = Packet()
pkt.write_ubyte(CMD.SOUND)
val = randint(0, 6)
pkt.write_ubyte(val)
sock.sendto(str(pkt), ip)
else:
pass
pkt = Packet()
pkt.write_ubyte(CMD.MOTION)
pkt.write_double(lv)
pkt.write_double(av)
sock.sendto(str(pkt), ip)
print('leaving control loop')
示例2: list
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import write_ubyte [as 别名]
import threading
import struct
from random import randint
from packet import Packet, CMD
botIp = {} #used as a dictionary for botIps
botIp['donatello'] = ("137.143.52.234", 13676)
botIp['raphael'] = ("137.143.63.255", 13698)
cmd_buffer = list()
LIN_V = 0.2
ANG_V = 1
KA_PKT = Packet()
KA_PKT.write_ubyte(CMD.KEEPALIVE)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# obtain audio from the microphone
r = sr.Recognizer()
m = sr.Microphone()
def keepAlive():
for key in botIp:
sock.sendto(str(KA_PKT), botIp[key])
threading.Timer(3, keepAlive).start()
def controlLoop(ip):
global LIN_V, ANG_V
word = None
示例3: print
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import write_ubyte [as 别名]
print(sys.argv)
addr = (sys.argv[1],int(float(sys.argv[2])))
print(addr)
else:
print('useage is leapNode address port')
print('using default')
try:
keepAlive()
while True:
lv = 0
av =0
frame = controller.frame()
hand = frame.hands[0]
if hand.palm_position.z < -30:
lv = -1
elif hand.palm_position.z > 30:
lv = 1
elif hand.palm_position.x < -30:
av = -1
elif hand.palm_position.x > 30:
av = 1
LIN_V,ANG_V = speed(hand.palm_position.y)
pkt = Packet()
pkt.write_ubyte(CMD.MOTION)
pkt.write_double(-LIN_V * lv)
pkt.write_double(-ANG_V * av)
sock.sendto(str(pkt), addr)
time.sleep(1)
except KeyboardInterrupt:
print("ending")