对齐控制方法

This commit is contained in:
cyy_mac
2026-06-20 21:50:17 +08:00
parent 228efaa361
commit 61e1be28c0
2 changed files with 17 additions and 29 deletions

25
main.py
View File

@@ -211,20 +211,17 @@ class HTTPHandler(BaseHTTPRequestHandler):
length = int(self.headers.get("Content-Length", 0))
body = json.loads(self.rfile.read(length))
with shared_lock:
# Ackermann mode: {"speed": v, "steer": angle}
if "speed" in body or "steer" in body:
shared["cmd_speed"] = float(body.get("speed", 0))
shared["cmd_steer"] = float(body.get("steer", 0))
# Differential mode: {"vx":, "vy":, "wz":} → mapped to speed/steer
elif "vx" in body:
vx = float(body.get("vx", 0))
wz = float(body.get("wz", 0))
shared["cmd_speed"] = vx
# Convert angular.z to steer via bike model (wheelbase ≈ 0.17m)
if abs(vx) > 0.01:
shared["cmd_steer"] = math.atan(wz * L / vx)
else:
shared["cmd_steer"] = 0.0
vx = float(body.get("vx", 0))
wz = float(body.get("wz", 0))
shared["cmd_speed"] = vx
# Bicycle model Vz→steer (matches firmware Vz_to_Akm_Angle)
# Axle_spacing=0.158, Wheel_spacing=0.162
if abs(vx) > 0.01 and abs(wz) > 1e-6:
R_turn = vx / wz
steer = math.atan(0.158 / (R_turn + 0.05 * 0.162))
shared["cmd_steer"] = steer if wz >= 0 else -steer
else:
shared["cmd_steer"] = 0.0
self.send_response(200)
self.end_headers()
else: