add netowrking between pi and laptop, basically add all the components together
parent
47eb71057f
commit
6524ba6cfe
@ -1,10 +1,29 @@
|
||||
import math
|
||||
import serial
|
||||
import RPi.GPIO as gpio
|
||||
import time
|
||||
|
||||
ser = serial.Serial('/dev/ttyUSB0', 115200)
|
||||
gpio.setmode(gpio.BCM)
|
||||
gpio.setup(13, gpio.OUT)
|
||||
pwm = gpio.PWM(13, 100)
|
||||
pwm.start(5)
|
||||
|
||||
def goToBin(bin):
|
||||
if bin % 2 == 0:
|
||||
direction = "right"
|
||||
else:
|
||||
direction = "left"
|
||||
adjustedBin = math.floor(bin / 2)
|
||||
distance = adjustedBin * 18
|
||||
time = 0.5 + 0.93 * adjustedBin
|
||||
delay = 0.5 + 0.93 * adjustedBin
|
||||
command = 'G0 X'
|
||||
command += distance
|
||||
ser.write(command)
|
||||
time.sleep(delay)
|
||||
if bin % 2 == 0: # tilt to right
|
||||
pwm.ChangeDutyCycle(0)
|
||||
time.sleep(1)
|
||||
pwm.ChangeDutyCycle(20)
|
||||
else:
|
||||
pwm.ChangeDutyCycle(40)
|
||||
time.sleep(1)
|
||||
pwm.ChangeDutyCycle(20)
|
||||
ser.write(b'G0 X0')
|
||||
time.sleep(delay)
|
@ -0,0 +1,25 @@
|
||||
import socket
|
||||
import sort
|
||||
import control_motor
|
||||
import control_pixel
|
||||
|
||||
host = socket.gethostname()
|
||||
port = 9001 # The same port as used by the server
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((host, port))
|
||||
s.sendall(b'Connected to server!')
|
||||
control_pixel.ledOn()
|
||||
while True:
|
||||
try:
|
||||
data = s.recv(1024)
|
||||
if not data: break
|
||||
print("Found "+data)
|
||||
selectedBin = sort.sort(data)
|
||||
control_pixel.ledOff()
|
||||
control_motor.goToBin(selectedBin)
|
||||
control_pixel.ledOn()
|
||||
s.sendall(b'Continue')
|
||||
except socket.error:
|
||||
print("Error Occured.")
|
||||
break
|
||||
s.close()
|
@ -0,0 +1,10 @@
|
||||
import socket
|
||||
|
||||
host = socket.gethostname()
|
||||
port = 12345 # The same port as used by the server
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((host, port))
|
||||
s.sendall(b'Hello, world')
|
||||
data = s.recv(1024)
|
||||
s.close()
|
||||
print('Received', repr(data))
|
Loading…
Reference in New Issue