avr: increase clk to 8MHz
[ros_wild_thumper.git] / scripts / test_speed.py
1 #!/usr/bin/env python
2 # -*- coding: iso-8859-15 -*-
3
4 import struct
5 from i2c import *
6 from datetime import datetime
7 from time import sleep
8
9 def get_pos():
10         s = i2c_read_reg(0x50, 0x10, 8)
11         hall1, hall2, hall3, hall4 = struct.unpack(">hhhh", s)
12         return hall1, hall2, hall3, hall4
13
14 if __name__ == "__main__":
15         i2c_write_reg(0x50, 0x90, struct.pack("BB", 1, 1)) # switch direction
16         speed = 255
17         i2c_write_reg(0x50, 0x1, struct.pack(">hhhh", speed, speed, speed, speed))
18         start = datetime.now()
19         for i in range(100):
20                 diff = datetime.now() - start
21                 status = get_pos()
22                 print "%d.%03d: %d %d %d %d" % ((diff.seconds, diff.microseconds/1000) + status)
23                 sleep(0.01)
24         speed = 0
25         i2c_write_reg(0x50, 0x1, struct.pack(">hhhh", speed, speed, speed, speed))