Skip to content

Instantly share code, notes, and snippets.

@graykevinb
Created February 22, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graykevinb/75b7a01561069e9e9e70356818ceedbf to your computer and use it in GitHub Desktop.
Save graykevinb/75b7a01561069e9e9e70356818ceedbf to your computer and use it in GitHub Desktop.
Log BrickPi3 motors
#Licensed under Createive Commons Share Alike 4.0
#https://creativecommons.org/licenses/by-sa/4.0/
#Created by Kevin Gray
#For use with the brickpi3 by Dexter Industries. https://www.dexterindustries.com/BrickPi/
import brickpi3
import datetime
import time
BP = brickpi3.BrickPi3()
now = datetime.datetime.now()
filename = 'log_' + str(now.year) + '-' + str(now.month) + '-' + str(now.day) + '.txt'
if os.path.exists(filename) == True:
print ('hello')
n = 1
while True:
filename = 'log' + str(n) + '_' + str(now.year) + '-' + str(now.month) + '-' + str(now.day) + '.txt'
n += 1
if os.path.exists(filename) == False:
break
else:
pass
else:
print('hi')
f = open(filename, 'w+')
i = 0
read_check = []
try:
BP.set_motor_limits(BP.PORT_A, 200)
BP.offset_motor_encoder(BP.PORT_A, BP.get_motor_encoder(BP.PORT_A)[0])
BP.set_motor_position(BP.PORT_A, 360)
while True:
time.sleep(1)
reading = BP.get_motor_status(BP.PORT_A)
read_check.append(reading)
print(read_check[i])
f.write(str(read_check[i]) + '\n')
i += 1
except KeyboardInterrupt:
pass
f.close()
BP.reset_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment