Skip to content

Instantly share code, notes, and snippets.

@Mango-kid
Created August 31, 2016 16:10
Show Gist options
  • Save Mango-kid/fc926d3d6befe7e6789c2d72fce12681 to your computer and use it in GitHub Desktop.
Save Mango-kid/fc926d3d6befe7e6789c2d72fce12681 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
#configure the slush library
import Slush
import time
b = Slush.sBoard()
#setup a motor, more than one motor can be setup here
m0 = Slush.Motor(0)
#set the power levels of the motor during run, accel, deccel, and hold
m0.setCurrent(10, 10, 20, 20)
#set the microstepping level to 2
m0.setMicroStepping(2)
m0.goTo(10000)
m0.setMicroStepping(4)
m0.goTo(0)
#set the maximum speed in steps per second
m0.setMaxSpeed(1500)
#set the acceleration of the motor
m0.setAccel(850)
#set the decceleration of the motor
m0.setDeccel(200)
#run the motor a little
m0.run(1, 400)
print("Current Speed: " + str(m0.getSpeed()))
time.sleep(3)
m0.softStop()
'''
The next command covers use of the limit switchs
Param 1: limit switch open or closed
Param 2: direction to travel towards the limit switch
Param 3: speed at which to travel
'''
m0.goUntilPress(1, 1, 200)
#set the new position as home, or zero in the position data
m0.setAsHome()
#spin the motor again and preform a hard stop
m0.run(1, 200)
time.sleep(2)
m0.hardStop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment