Created
January 3, 2014 03:43
-
-
Save adammck/8232311 to your computer and use it in GitHub Desktop.
Move Dynamixel servos randomly (to make sure they're working)
This file contains hidden or 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
| #!/usr/bin/env python | |
| import time | |
| import random | |
| import optparse | |
| import dynamixel | |
| if __name__ == "__main__": | |
| parser = optparse.OptionParser() | |
| parser.add_option("-p", "--port", help="Serial port", default="/dev/tty.usbserial-A9ITPZVR") | |
| parser.add_option("-b", "--baud", help="Baud rate", default="1000000") | |
| parser.add_option("-m", "--max-id", dest="max_id", help="Max servo ID", default="5") | |
| parser.add_option("-i", "--interval", help="Movement interval", default="0.5") | |
| parser.add_option("-t", "--torque", help="Torque limit", default="1023") | |
| parser.add_option("-s", "--speed", help="Moving speed", default="1023") | |
| (options, args) = parser.parse_args() | |
| max_id = int(options.max_id) | |
| serial = dynamixel.SerialStream(port=options.port, baudrate=options.baud, timeout=1) | |
| network = dynamixel.DynamixelNetwork(serial) | |
| network.scan(1, max_id) | |
| for s in network.get_dynamixels(): | |
| s.synchronized = True | |
| s.torque_enable = True | |
| s.torque_limit = int(options.torque) | |
| s.moving_speed = int(options.speed) | |
| try: | |
| while True: | |
| pos = random.randrange(0, 1023) | |
| for s in network.get_dynamixels(): | |
| s.goal_position = pos | |
| network.synchronize() | |
| time.sleep(float(options.interval)) | |
| except KeyboardInterrupt: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment