asr_vosk: Allow to handle keyword and command in one sentence
[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         i2c_write_reg(0x50, 0x90, struct.pack("BBBB", 1, 1, 0, 0)) # switch direction
18         set_pwm(int(sys.argv[1]), int(sys.argv[2]))
19
20         while True:
21                 motor1, = struct.unpack(">B", i2c_read_reg(0x50, 0x2, 1))
22                 motor2, = struct.unpack(">B", i2c_read_reg(0x50, 0x4, 1))
23                 motor3, = struct.unpack(">B", i2c_read_reg(0x50, 0x6, 1))
24                 motor4, = struct.unpack(">B", i2c_read_reg(0x50, 0x8, 1))
25                 speed1, speed2, speed3, speed4 = struct.unpack(">hhhh", i2c_read_reg(0x50, 0x30, 8))
26                 error,  = struct.unpack(">B", i2c_read_reg(0x50, 0xA1, 1))
27                 print "PWM:", motor1, motor2, motor3, motor4, "Speed:", speed1, speed2, speed3, speed4, "Error:", error
28                 sleep(0.1)