]> defiant.homedns.org Git - ros_wild_thumper.git/blob - scripts/engine_man_test.py
pid tuning with fixes
[ros_wild_thumper.git] / scripts / engine_man_test.py
1 #!/usr/bin/env python
2 # -*- coding: iso-8859-15 -*-
3
4 import sys
5 import struct
6 from time import sleep
7 from i2c import i2c_write_reg, i2c_read_reg
8
9
10 def set_pwm(left, right):
11         i2c_write_reg(0x50, 0x1, struct.pack(">h", left))
12         i2c_write_reg(0x50, 0x3, struct.pack(">h", left))
13         i2c_write_reg(0x50, 0x5, struct.pack(">h", right))
14         i2c_write_reg(0x50, 0x7, struct.pack(">h", right))
15
16 if __name__ == "__main__":
17         set_pwm(int(sys.argv[1]), int(sys.argv[2]))
18
19         while True:
20                 motor1, = struct.unpack(">B", i2c_read_reg(0x50, 0x2, 1))
21                 motor2, = struct.unpack(">B", i2c_read_reg(0x50, 0x4, 1))
22                 motor3, = struct.unpack(">B", i2c_read_reg(0x50, 0x6, 1))
23                 motor4, = struct.unpack(">B", i2c_read_reg(0x50, 0x8, 1))
24                 speed1, speed2, speed3, speed4 = struct.unpack(">hhhh", i2c_read_reg(0x50, 0x30, 8))
25                 error,  = struct.unpack(">B", i2c_read_reg(0x50, 0xA1, 1))
26                 print "PWM:", motor1, motor2, motor3, motor4, "Speed:", speed1, speed2, speed3, speed4, "Error:", error
27                 sleep(0.1)