Created
February 1, 2020 08:56
-
-
Save mjkaufer/1b702380e81c5e44a0469c1d7b414868 to your computer and use it in GitHub Desktop.
boba bot baby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import serial | |
# configure the serial connections (the parameters differs on the device you are connecting to) | |
ser = serial.Serial( | |
port='/dev/tty.usbserial-AD0JM61U', | |
baudrate=115200, | |
parity=serial.PARITY_NONE, | |
stopbits=serial.STOPBITS_ONE, | |
bytesize=serial.EIGHTBITS, | |
timeout=2 | |
) | |
ser.isOpen() | |
while ser.read(): | |
pass | |
# configure the serial connections (the parameters differs on the device you are connecting to) | |
ser.close() | |
ser = serial.Serial( | |
port='/dev/tty.usbserial-AD0JM61U', | |
baudrate=115200, | |
parity=serial.PARITY_NONE, | |
stopbits=serial.STOPBITS_ONE, | |
bytesize=serial.EIGHTBITS, | |
timeout=30 | |
) | |
# G06 O=P0.1 # solenoid on, initialize w/ this, turn off at end | |
# G06 O=P1.0 # opens closes | |
ser.isOpen() | |
import atexit | |
def exitHandler(): | |
print('calling exitHandler') | |
ser.write(b'\x30\x10\x30\x10') | |
print('exitHandler: sent those commands; waiting 1s') | |
time.sleep(1) | |
print('exitHandler: waited 1s; now closing ser port') | |
ser.close() | |
print('exitHandler: successfully closed ser port') | |
atexit.register(exitHandler) | |
# G07 VP=5 # (1-100) | |
commands = [ | |
'\x30',# pause | |
'\x10',# exit | |
'\x14',# debug | |
'G00 J1=0 J2=0 J3=0 J4=0 J5=0 J6=0\r\n', # always send these 0 positions else weird shit happens | |
'G07 VP=5\r\n', # sets speed of robot to 15% | |
'G06 O=P0.1\r\n', # turns on solenoid | |
'G06 O=P1.1\r\n', # opens hook | |
'G00 J1=0 J2=-90 J3=0 J4=0 J5=0 J6=0\r\n', | |
'G06 O=P1.0\r\n', # 0 is closed | |
'G00 J1=0 J2=0 J3=0 J4=0 J5=-90 J6=0\r\n', | |
'G06 O=P1.1\r\n', # 1 is open | |
'G00 J1=0 J2=0 J3=0 J4=0 J5=0 J6=0\r\n', # try to always do this at the end | |
'G06 O=P0.0\r\n' # try to always do this at the end | |
] | |
for command in commands: | |
start_time = time.time() | |
print('running', str.encode(command)) | |
ser.write(str.encode(command)) | |
if command[0] == 'G': | |
while '%' != ser.read(1).decode('utf8'): | |
pass | |
print('assumed', command, 'succeeded') | |
time.sleep(1) | |
if 'G06 O=P0.1' in command: | |
time.sleep(9) | |
elif len(command) == 1: | |
# ser.read(1) | |
time.sleep(1) | |
print('ran', command, 'in', time.time() - start_time, 'seconds') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment