diff options
| author | Edvin <[email protected]> | 2025-05-06 14:23:48 +0200 |
|---|---|---|
| committer | Edvin <[email protected]> | 2025-05-06 14:23:48 +0200 |
| commit | 45acee6bf8339ec01f06fe3701a391d0275186db (patch) | |
| tree | f7d6974dfc3a8bedb73c1615b73301073d8350ff /main.py | |
| parent | 8a4fd87622cc13ca4f501b98502585ca2b2aaddd (diff) | |
Added mean of position
Diffstat (limited to 'main.py')
| -rwxr-xr-x | main.py | 35 |
1 files changed, 11 insertions, 24 deletions
@@ -57,12 +57,8 @@ if bto.find("Connected") != -1: # LIDAR Process Code LIDARProcess = subprocess.Popen(["/home/pi/TNE107-RPI/LIDARProg", "--channel", "--serial", "/dev/ttyUSB0", "460800"], stdout=open(os.devnull, 'wb')) print(f"LIDAR PID: {LIDARProcess.pid}") - - - sleep(5) while bto != "1000": - #print(GPIO.input(PT)) btReady, _, _ = select.select([BluetoothProcess.stdout], [], [], 0.0005) if btReady: @@ -90,14 +86,10 @@ if bto.find("Connected") != -1: # Store current position => old pos forward = True backward = False - oldX = x - oldY = y NANO.write(b"Forward\n") elif bto == "22": forward = False backward = True - oldX = x - oldY = y # Store current position => old pos NANO.write(b"Backward\n") elif bto == "33": @@ -144,27 +136,22 @@ if bto.find("Connected") != -1: print("reset") desDir = 0 elif bto == "0": - # Store current position => cur pos - # curX = float(x) * 1000 - # curY = float(y) * 1000 - - # oldDir = curDir - - # curDir = (math.atan2(curY - oldY, curX - oldX) + math.pi) * (180/math.pi) - # if backward == True: - # a = a - 180 - NANO.write(b"Stop\n") - curDir = math.atan2(y - oldY, x - oldX) - # if curDir < desDir: + curDir = math.atan2(y - oldY, x - oldX) * (180/math.pi) + 180 + if curDir < 0: + curDir = curDir + 360 + if curDir >= 360: + curDir = curDir - 360 + + # if curDir < desDir: # if curDir > desDir: - if forward: - NANO.write(b"Fowrad\n") + # if forward: + # NANO.write(b"Fowrad\n") - if backward: - NANO.write(b"Backward\n") + # if backward: + # NANO.write(b"Backward\n") sleep(0.1) |
