def wheel_com_init(): global Device1, Device2 Device1 = BLEDevice("DD:43:89:16:43:81") #right wheel Device2 = BLEDevice("F4:82:B3:50:ED:55") #left wheel Device1.writereq(0xd, '54524F5F0D0A') #RUN_flag Device1.notify() Device2.writereq(0xd, '54524F5F0D0A') #RUN_flag Device2.notify() Device1.writereq(0xd, '544443790D0A') #FRONT Device1.notify() Device2.writereq(0xd, '544443790D0A') #FRONT Device2.notify() desired_speed1(10) desired_speed2(10) time.sleep(2) desired_speed1(0) desired_speed2(0) global state state = STOP
import sys, time import threading import keyboard import numpy as np from bledevice import scanble, BLEDevice Device1 = BLEDevice("DD:43:89:16:43:81") Device2 = BLEDevice("F4:82:B3:50:ED:55") Device1.writereq(0xd, '54524F5F0D0A') #RUN_flag Device1.notify() Device2.writereq(0xd, '54524F5F0D0A') #RUN_flag Device2.notify() Device1.writereq(0xd, '544443790D0A') #FRONT Device1.notify() Device2.writereq(0xd, '544443790D0A') #FRONT Device2.notify() desired = 0 flag = 1 now_velocity1 = 0 now_velocity2 = 0 STOP = 0 IDLE = 1 FWD = 2 LEFT = 3 RIGHT = 4 ROTATE = 6 direction1 = 1 direction2 = 1
#!/usr/bin/env python import sys, time from bledevice import scanble, BLEDevice if len(sys.argv) != 2: print "Usage: python blecomm.py <ble address>" print "Scan devices are as follows:" print scanble(timeout=3) sys.exit(1) hm10 = BLEDevice(sys.argv[1]) while True: vh = hm10.getvaluehandle("ffe1") hm10.writecmd(vh, "test\r\n".encode('hex')) data = hm10.notify() if data is not None: print "Received: ", data time.sleep(1)
#!/usr/bin/env python import sys, time from bledevice import scanble, BLEDevice if len(sys.argv) != 2: print "Usage: python blecomm.py <ble address>" print "Scan devices are as follows:" print scanble(timeout=3) sys.exit(1) hm10 = BLEDevice(sys.argv[1]) while True: vh = hm10.getvaluehandle("ffe1") hm10.writecmd(vh, "test\r\n".encode("hex")) data = hm10.notify() if data is not None: print "Received: ", data time.sleep(1)
def M_FWD_LEFT(Device1, Device2): print("\nM_FWD_LEFT") #vh=Device1.getvaluehandle(b"0000ffe1") Device1.writereq(0xd, '54524F5F0D0A') Device2.writereq(0xd, '54524F5F0D0A') time.sleep(0.5) sum_time = 0 mean_time = 0 count = 0 while True: count = count + 1 start = time.time() data = Device1.notify() sum_time = sum_time + time.time() - start mean_time = sum_time / count print( "time :", time.time() - start, "mean_time : ", mean_time, "\n", ) print(data) print("\n") ''' while True: #vh=hm10.getvaluehandle("ffe1") #hm10.writecmd(vh, "hello\r\n".encode('hex'))