Compare commits
3
Commits
071236bc0e
...
87449e287e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87449e287e | ||
|
|
0d7a234a25 | ||
|
|
d0717ec157 |
Binary file not shown.
+111
-1
@@ -2,6 +2,11 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
import DobotDllType as dType
|
import DobotDllType as dType
|
||||||
|
|
||||||
|
import json
|
||||||
|
import socket, select
|
||||||
|
import re
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Six actuators:
|
Six actuators:
|
||||||
linear rail
|
linear rail
|
||||||
@@ -202,7 +207,7 @@ def adjustSpeed(motor, adjustment):
|
|||||||
global nowTime, stopTime, currentMotor, speed, motorcfg, movement_time, max_speed, max_movement_time
|
global nowTime, stopTime, currentMotor, speed, motorcfg, movement_time, max_speed, max_movement_time
|
||||||
|
|
||||||
if currentMotor==motor:
|
if currentMotor==motor:
|
||||||
if (adjustment>0 and speed>0) or (adjustment<0 and speed<0):=
|
if (adjustment>0 and speed>0) or (adjustment<0 and speed<0):
|
||||||
speed += adjustment * 1-(abs(speed)/max_speed)
|
speed += adjustment * 1-(abs(speed)/max_speed)
|
||||||
else:
|
else:
|
||||||
stopMotorFunctions()
|
stopMotorFunctions()
|
||||||
@@ -320,5 +325,110 @@ def stop():
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
############################### 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!")
|
||||||
|
|
||||||
|
print("Location 3")
|
||||||
|
print(queue)
|
||||||
|
|
||||||
|
# removing the first item from queue
|
||||||
|
queue = queue[1:]
|
||||||
|
|
||||||
|
print("Location 4")
|
||||||
|
print(queue)
|
||||||
|
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
import DobotDllType as dType
|
import DobotDllType as dType
|
||||||
|
|
||||||
|
import json
|
||||||
|
import socket, select
|
||||||
|
import re
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Six actuators:
|
Six actuators:
|
||||||
linear rail
|
linear rail
|
||||||
@@ -253,27 +258,36 @@ def updateLoop():
|
|||||||
|
|
||||||
def rt():
|
def rt():
|
||||||
adjustSpeed(1, 5)
|
adjustSpeed(1, 5)
|
||||||
|
print("TURNING RIGHT!")
|
||||||
|
|
||||||
def lt():
|
def lt():
|
||||||
adjustSpeed(1, -5)
|
adjustSpeed(1, -5)
|
||||||
|
print("TURNING LEFT!")
|
||||||
|
|
||||||
def fw():
|
def fw():
|
||||||
adjustSpeed(2, 5)
|
adjustSpeed(2, 5)
|
||||||
|
print("GOING FORWARD!")
|
||||||
|
|
||||||
def bc():
|
def bc():
|
||||||
adjustSpeed(2, -5)
|
adjustSpeed(2, -5)
|
||||||
|
print("GOING BACK!")
|
||||||
|
|
||||||
def up():
|
def up():
|
||||||
adjustSpeed(3, 5)
|
adjustSpeed(3, 5)
|
||||||
|
print("UP!")
|
||||||
|
|
||||||
def dn():
|
def dn():
|
||||||
adjustSpeed(3, -5)
|
adjustSpeed(3, -5)
|
||||||
|
print("DOWN!")
|
||||||
|
|
||||||
def lr():
|
def lr():
|
||||||
adjustSpeed(4, 10)
|
adjustSpeed(4, 10)
|
||||||
|
print("GOING RIGHT!")
|
||||||
|
|
||||||
def ll():
|
def ll():
|
||||||
adjustSpeed(4, -10)
|
adjustSpeed(4, -10)
|
||||||
|
print("GOING LEFT!")
|
||||||
|
|
||||||
updateLoop()
|
updateLoop()
|
||||||
|
|
||||||
|
|
||||||
@@ -282,13 +296,117 @@ def stopCmp():
|
|||||||
|
|
||||||
def grab():
|
def grab():
|
||||||
candy.gripp()
|
candy.gripp()
|
||||||
|
print("GRASP!")
|
||||||
|
|
||||||
def drop():
|
def drop():
|
||||||
candy.letgo()
|
candy.letgo()
|
||||||
|
print("DROPPING!")
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
candy.panic()
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user