self.bus_id = bus_id self.radio_id = radio_id self.bus = smbus.SMBus(self.bus_id) def red_chanel(self, ch_id): w = self.bus.read_word_data(self.radio_id, ch_id) return w if __name__ == "__main__": m0 = Motor(0) m1 = Motor(1, -1) rc = Rcradio(2, 0x10) offset = 698 try: while 1: speed = offset - rc.red_chanel(0) if abs(speed) < 3: speed = 0 print(speed) m0.set_voltage(speed) m1.set_voltage(speed) time.sleep(0.1) except KeyboardInterrupt: m0.close() m1.close() pass
while c != 'q' and c != 'Q': t0 = time.time() r0 = m0.get_radians() c = getch() t1 = time.time() r1 = m0.get_radians() print("{0}, {1}".format(voltage, (r1 - r0)/(t1 - t0))) if ord(c) == 27: c = getch() if ord(c) == 91: c = getch() if ord(c) in key_map.keys(): print(key_map[ord(c)]) if key_map[ord(c)] == 'up': voltage += voltage_step elif key_map[ord(c)] == 'down': voltage -= voltage_step elif ord(c) == 32: pass else: print(ord(c)) if voltage > 100: volate = 100 if voltage < -100: voltage = -100 m0.get_radians() m0.set_voltage(voltage) m0.set_encoder(0) m0.close()