Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@

# Initialize setpoint override client (UDP port 5007)
app.config["SETPOINT_OVERRIDE"] = init_setpoint_override(resource_monitor=app.config["RESOURCE"])
app.config["CONTROLLER"].set_setpoint_client(app.config["SETPOINT_OVERRIDE"])
app.config["CONTROLLER"].set_pid_rates(_config.get_section("pid_setpoint_rates") or {})

# Start control loop telemetry receiver (UDP port 5005)
app.config["CONTROL_TELEM"] = init_control_telemetry(port=5005)
Expand Down
22 changes: 16 additions & 6 deletions data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@
"z": -50.0
},
"imu_axes": {
"yaw": "+yaw",
"pitch": "+pitch",
"roll": "+roll"
"yaw": "-yaw",
"pitch": "-pitch",
"roll": "-roll"
},
"accel_axes": {
"x": "+x",
"y": "+y",
"z": "+z"
},
"ip_camera": {
"active_ip": "10.77.0.4",
"presets": []
"active_ip": "10.77.0.3",
"presets": [
{
"name": "Main IP-camera",
"ip": "10.77.0.3"
}
]
},
"pid_setpoint_rates": {
"roll": 20.0,
"pitch": 20.0,
"yaw": 90.0
}
}
}
28 changes: 14 additions & 14 deletions data/data.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"imu": {
"yaw": 35.51,
"pitch": 4.75,
"roll": -179.7,
"yr": 0.05,
"pr": 0.01,
"rr": 0.12,
"ax": 0.002,
"ay": 0.001,
"az": -0.001
"yaw": -67.08,
"pitch": -1.1,
"roll": 179.3,
"yr": 0.18,
"pr": 0.15,
"rr": 0.3,
"ax": 0.085,
"ay": -0.004,
"az": -0.042
},
"9dof": {
"acceleration": {
Expand Down Expand Up @@ -74,14 +74,14 @@
"dptSet": 0.0
},
"resources": {
"sequence": 137,
"uptime_ms": 139172,
"cpu_percent": 4,
"sequence": 49,
"uptime_ms": 50908,
"cpu_percent": 5,
"heap_used_percent": 2,
"heap_free_kb": 502,
"heap_free_kb": 501,
"heap_total_kb": 512,
"thread_count": 20,
"udp_rx_count": 2695,
"udp_rx_count": 900,
"udp_rx_errors": 0
},
"control_telemetry": {
Expand Down
82 changes: 25 additions & 57 deletions data/pid_configs.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
{
"rollPitchRough": {
"surge": {
"kp": 0,
"ki": 0,
"kd": 0
},
"sway": {
"kp": 0,
"ki": 0,
"kd": 0
},
"heave": {
"kp": 0,
"ki": 0,
"kd": 0
},
"roll": {
"kp": 0.035,
"ki": 0,
"kd": 0.0015
},
"pitch": {
"kp": 0.05,
"ki": 0,
"kd": 0.001
},
"yaw": {
"kp": 0,
"ki": 0,
"kd": 0
}
},
"rollPitchRough2": {
"rollPitchYawRough": {
"surge": {
"kp": 0,
"ki": 0,
Expand All @@ -58,12 +26,12 @@
"kd": 0.001
},
"yaw": {
"kp": 0,
"kp": -0.05,
"ki": 0,
"kd": 0
}
},
"rollPitchYawRough": {
"rollPitchYawPrecise": {
"surge": {
"kp": 0,
"ki": 0,
Expand All @@ -82,49 +50,49 @@
"roll": {
"kp": 0.03,
"ki": 0,
"kd": 0.0015
"kd": 0.003
},
"pitch": {
"kp": 0.045,
"ki": 0,
"kd": 0.001
"kd": 0.006
},
"yaw": {
"kp": -0.05,
"kp": -0.15,
"ki": 0,
"kd": 0
}
},
"rollPitchYawPrecise": {
"manipulator-rough": {
"surge": {
"kp": 0,
"ki": 0,
"kd": 0
"kp": 0.0,
"ki": 0.0,
"kd": 0.0
},
"sway": {
"kp": 0,
"ki": 0,
"kd": 0
"kp": 0.0,
"ki": 0.0,
"kd": 0.0
},
"heave": {
"kp": 0,
"ki": 0,
"kd": 0
"kp": 0.0,
"ki": 0.0,
"kd": 0.0
},
"roll": {
"kp": 0.03,
"ki": 0,
"kd": 0.003
"kp": 0.012,
"ki": 0.0,
"kd": 0.0
},
"pitch": {
"kp": 0.045,
"ki": 0,
"kd": 0.006
"kp": 0.012,
"ki": 0.0,
"kd": 0.0
},
"yaw": {
"kp": -0.15,
"ki": 0,
"kd": 0
"kp": 0.008,
"ki": 0.0,
"kd": 0.0075
}
}
}
20 changes: 17 additions & 3 deletions lib/bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self, host=NUCLEO_HOST, port=NUCLEO_PORT, rate_hz=DEFAULT_RATE_HZ,
self._last_ack_count = None
self._watchdog_timeout = watchdog_timeout
self._watchdog_resends = 0
self._last_watchdog_resend_time = 0.0
self._last_command_snapshot: dict | None = None

def start(self):
Expand All @@ -85,7 +86,8 @@ def start(self):
self._sender = UdpSender(self.host, self.port)
self._stop.clear()
with self._status_lock:
self._last_ack_time = time.monotonic()
self._last_ack_time = 0.0
self._last_ack_count = None
self._thread.start()
self._watchdog_thread.start()

Expand Down Expand Up @@ -117,14 +119,22 @@ def get_uplink_status(self) -> dict:
now = time.monotonic()
send_age = None if self._last_send_time == 0 else max(0.0, now - self._last_send_time) * 1000.0
ack_age = None if self._last_ack_time == 0 else max(0.0, now - self._last_ack_time) * 1000.0
resend_age = (
None
if self._last_watchdog_resend_time == 0
else max(0.0, now - self._last_watchdog_resend_time) * 1000.0
)
return {
"sequence": self._seq,
"last_send_age_ms": send_age,
"last_send_timestamp": None if self._last_send_time == 0 else self._last_send_time,
"last_ack_age_ms": ack_age,
"last_ack_count": self._last_ack_count,
"watchdog_timeout": self._watchdog_timeout,
"watchdog_resends": self._watchdog_resends,
"last_watchdog_resend_age_ms": resend_age,
"last_command": self._last_command_snapshot or {},
"last_packet_hex": self._last_packet.hex() if self._last_packet else None,
}

# convenience: set from normalized axes
Expand Down Expand Up @@ -179,20 +189,24 @@ def _watchdog_loop(self):
udp_rx_count, _errors = counters()
now = time.monotonic()
with self._status_lock:
if self._last_ack_count is None:
self._last_ack_count = udp_rx_count
continue
if udp_rx_count != self._last_ack_count:
self._last_ack_count = udp_rx_count
self._last_ack_time = now
continue
# No new acks yet
if self._last_packet and (now - self._last_ack_time) > self._watchdog_timeout:
resend_due = (now - self._last_watchdog_resend_time) > self._watchdog_timeout
if self._last_packet and (now - self._last_ack_time) > self._watchdog_timeout and resend_due:
sender = self._sender
if sender:
try:
sender.send(self._last_packet)
self._watchdog_resends += 1
self._last_watchdog_resend_time = now
except Exception:
pass
self._last_ack_time = now


# simple initializer
Expand Down
Loading
Loading