Skip to content

Instantly share code, notes, and snippets.

@pingswept
Created December 15, 2012 00:10
Show Gist options
  • Save pingswept/4289810 to your computer and use it in GitHub Desktop.
Save pingswept/4289810 to your computer and use it in GitHub Desktop.
Servo test code in Python for Pololu Micro Maestro servo controller
@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