Created
March 26, 2018 16:59
-
-
Save Cleric-K/49dbba043a57fb0c0162d068c4ef7027 to your computer and use it in GitHub Desktop.
Automate motors
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 serial, time | |
s = serial.Serial('COM19', baudrate=115200) | |
def cmd(c): | |
s.flushInput() # we are not reading the input so do not let the buffer grow indefinitely | |
s.write( (c + '\n').encode('ascii') ) | |
cmd('#') # activate CLI | |
time.sleep(1) # give it some time to enter CLI mode | |
# motors are numbered 0 through 3 | |
# PWM is 1000 (off) to 2000 (full) | |
# turn on all motor in order | |
for i in range(4): | |
cmd('motor {} 1100'.format(i)) | |
time.sleep(1) | |
# turn off all motor in order | |
for i in range(4): | |
cmd('motor {} 1000'.format(i)) | |
time.sleep(1) | |
# 255 is a special value meaning ALL motors | |
cmd('motor 255 1100'.format(i)) | |
time.sleep(1) | |
cmd('motor 255 1000'.format(i)) | |
cmd('exit') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment