Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions teleop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,31 @@
import transforms3d as t3d
import numpy as np
import json
import subprocess

TF_RUB2FLU = np.array([[0, 0, -1, 0], [-1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
THIS_DIR = os.path.dirname(os.path.realpath(__file__))


def get_local_ip():
def get_local_ip() -> str:
# Try connecting to an external address first (requires default route / gateway)
try:
# Connect to an external address (doesn't actually send data)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)) # Google DNS as a dummy target
# Doesn't actually send data, but forces OS to choose an interface with a route
s.connect(("8.8.8.8", 80))
local_ip = s.getsockname()[0]
s.close()
return local_ip
except Exception as e:
return f"Error: {e}"
except Exception:
pass

# Offline/hotspot fallback using 'hostname -I' (Linux-only)
try:
ips = subprocess.check_output(["hostname", "-I"]).decode().strip().split()
return ips[0] if ips else "127.0.0.1"
except Exception:
return "127.0.0.1"



def are_close(a, b=None, lin_tol=1e-9, ang_tol=1e-9):
Expand Down