Merged the Chat parser with the robot arm control.

master
pk23 5 years ago
parent 9ee108ee57
commit d0717ec157

@ -2,6 +2,11 @@ import time
import threading
import DobotDllType as dType
import json
import socket, select
import re
from time import sleep
"""
Six actuators:
linear rail
@ -253,27 +258,36 @@ def updateLoop():
def rt():
adjustSpeed(1, 5)
print("TURNING RIGHT!")
def lt():
adjustSpeed(1, -5)
print("TURNING LEFT!")
def fw():
adjustSpeed(2, 5)
print("GOING FORWARD!")
def bc():
adjustSpeed(2, -5)
print("GOING BACK!")
def up():
adjustSpeed(3, 5)
print("UP!")
def dn():
adjustSpeed(3, -5)
print("DOWN!")
def lr():
adjustSpeed(4, 10)
print("GOING RIGHT!")
def ll():
adjustSpeed(4, -10)
print("GOING LEFT!")
updateLoop()
@ -282,13 +296,117 @@ def stopCmp():
def grab():
candy.gripp()
print("GRASP!")
def drop():
candy.letgo()
print("DROPPING!")
def stop():
candy.panic()
############################### Chat Parser Section ###############################
with open('/Users/pawel/Documents/Junction2018/twitch_key.json', 'rb') as json_data:
data = json.load(json_data)
primary_stream_key = data["primary_stream_key"]
oauth_key = data["oauth_key"]# bytes('oauth:gcpsl3csq85rf3lk8c1ijzer8deuat', "utf8")
print(primary_stream_key)
print(oauth_key)
HOST = "irc.chat.twitch.tv"
PORT = 6667
PASS = oauth_key
NICK = "TwitchGrabsCandy"
CHAN = "#twitchgrabscandy"
s = socket.socket()
s.connect((HOST, PORT))
s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
s.setblocking(0)
queue = []
while True:
response = ""
ready = select.select([s], [], [], 0.1)
if ready[0]:
print("Trying")
response = s.recv(1024).decode("utf-8") # blocking
# print(response)
if re.search("up", response) != None:
queue = queue + ["up"]
if re.search("down", response) != None:
queue = queue + ["down"]
if re.search("go left", response) != None:
queue = queue + ["gleft"]
if re.search("go right", response) != None:
queue = queue + ["gright"]
if re.search("turn left", response) != None:
queue = queue + ["tleft"]
if re.search("turn right", response) != None:
queue = queue + ["tright"]
if re.search("forward", response) != None:
queue = queue + ["forward"]
if re.search("back", response) != None:
queue = queue + ["back"]
if re.search("grasp", response) != None:
queue = queue + ["grasp"]
if re.search("drop", response) != None:
queue = queue + ["drop"]
# checking the motion that is first in the FIFO queue
if len(queue):
if queue[0] == "up":
up()
elif queue[0] == "down":
dn()
elif queue[0] == "gleft":
ll()
elif queue[0] == "gright":
lr()
elif queue[0] == "tleft":
lt()
elif queue[0] == "tright":
rt()
elif queue[0] == "forward":
fw()
elif queue[0] == "back":
bc()
elif queue[0] == "grasp":
grab()
elif queue[0] == "drop":
drop()
else:
print("Something is TERRIBLY wrong!")
# removing the first item from queue
queue = queue[1:]
sleep(1)

Loading…
Cancel
Save