Skip to content

Instantly share code, notes, and snippets.

@paulaksm
Created March 20, 2018 01:19
Show Gist options
  • Save paulaksm/9b511eb3f226c0b3daef764cfa894a88 to your computer and use it in GitHub Desktop.
Save paulaksm/9b511eb3f226c0b3daef764cfa894a88 to your computer and use it in GitHub Desktop.
use with NXTtr.java
'''
Uses USB connection (requires pyusb and udev rules for lego USB)
Tries to increase velocity using synchronized motors for forward and backward motion.
Is possible to increase power up to 60 in weak_turn() calls, but it best behaves with 40
'''
import nxt
import time
import keyboard as key
import USBInterface
brick = next(USBInterface.find_bricks(debug=True))
print(type(brick), brick)
# initialize and reset position
while True:
try:
if key.is_pressed('q'):
brick.send('\x64')
print('Exiting...')
break
elif key.is_pressed('up'):
#rightMotor.weak_turn(20, 100)
#leftMotor.weak_turn(20, 100)
#both.run(40)
brick.send('\x01')
time.sleep(3)
brick.send('\x10')
elif key.is_pressed('down'):
brick.send('\x02')
time.sleep(3)
brick.send('\x20')
# #rightMotor.weak_turn(-20,30)
# #leftMotor.weak_turn(-20,30)
# both.run(-40)
# time.sleep(0.05)
#elif key.is_pressed('left'):
# rightMotor.weak_turn(60,30)
# leftMotor.weak_turn(-60,30)
#elif key.is_pressed('right'):
# rightMotor.weak_turn(-60,30)
# leftMotor.weak_turn(60,30)
# # leftMotor.run(-40)
# # rightMotor.run(40)
#elif key.is_pressed('space'):
# leftMotor.idle()
# rightMotor.idle()
# leftMotor.brake()
# rightMotor.brake()
# # both.idle()
# # both.brake()
# print('stopping...')
else:
pass
except:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment