Created
December 15, 2012 00:10
-
-
Save pingswept/4289810 to your computer and use it in GitHub Desktop.
Servo test code in Python for Pololu Micro Maestro servo controller
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
@public.route('/speed/<channel>/<pulse_in_ms>') | |
def set_motor_speed(channel, pulse_in_ms): | |
pytronics.serialWrite(chr(0xAA), speed=9600) | |
if (channel == 'right'): | |
side = chr(0x01) | |
else: | |
side = chr(0x02) | |
rough_speed = (int(pulse_in_ms) >> 7) & 0x7F # grab bits 7-13 | |
fine_speed = int(pulse_in_ms) & 0x7F # wipe out all but bits 0-6 | |
pytronics.serialWrite(chr(0x84) + side + chr(fine_speed) + chr(rough_speed), speed=9600) | |
print "Set speed to {0}".format(int(rough_speed)) | |
return "speed set" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment