From 3bc8d7f92277a953cfcee5781d5875f040d7f028 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Wed, 13 Jul 2016 10:00:53 +0200 Subject: [PATCH] motor_ctrl: pid tuning --- avr/motor_ctrl/main.c | 6 +- avr/motor_ctrl/main.hex | 1209 ++++++++++++++++++------------------ scripts/engine_man_test.py | 27 + 3 files changed, 628 insertions(+), 614 deletions(-) create mode 100755 scripts/engine_man_test.py diff --git a/avr/motor_ctrl/main.c b/avr/motor_ctrl/main.c index d25271f..5c6a667 100644 --- a/avr/motor_ctrl/main.c +++ b/avr/motor_ctrl/main.c @@ -101,9 +101,9 @@ #define TWI_RESET TWCR &= ~((1 << TWSTO) | (1 << TWEN)); TWI_ACK #define TWI_NAK TWCR = (1<h", left)) + i2c_write_reg(0x50, 0x3, struct.pack(">h", left)) + i2c_write_reg(0x50, 0x5, struct.pack(">h", right)) + i2c_write_reg(0x50, 0x7, struct.pack(">h", right)) + +if __name__ == "__main__": + set_pwm(int(sys.argv[1]), int(sys.argv[2])) + + while True: + motor1, = struct.unpack(">B", i2c_read_reg(0x50, 0x2, 1)) + motor2, = struct.unpack(">B", i2c_read_reg(0x50, 0x4, 1)) + motor3, = struct.unpack(">B", i2c_read_reg(0x50, 0x6, 1)) + motor4, = struct.unpack(">B", i2c_read_reg(0x50, 0x8, 1)) + speed1, speed2, speed3, speed4 = struct.unpack(">hhhh", i2c_read_reg(0x50, 0x30, 8)) + error, = struct.unpack(">B", i2c_read_reg(0x50, 0xA1, 1)) + print "PWM:", motor1, motor2, motor3, motor4, "Speed:", speed1, speed2, speed3, speed4, "Error:", error + sleep(0.1) -- 2.39.5