GPS neustart eingebaut
This commit is contained in:
@@ -286,6 +286,8 @@ var motorCommandsListener = null;
|
||||
var gpsFixListener = null;
|
||||
var gpsStatusListener = null;
|
||||
var gpsDiagnosticsListener = null;
|
||||
var rosReconnectTimer = null;
|
||||
var rosDisconnectTimer = null;
|
||||
var publishTimer = null;
|
||||
var statusTimer = null;
|
||||
var axes = [0, 0, 0, 0, 0, 0];
|
||||
@@ -317,6 +319,7 @@ var pageConnection = {
|
||||
apiOk: false,
|
||||
apiLastAt: 0,
|
||||
rosOk: false,
|
||||
rosLastAt: 0,
|
||||
gpsLastAt: 0,
|
||||
state: "offline"
|
||||
};
|
||||
@@ -633,6 +636,14 @@ function setGpsAccuracyState(label, tone) {
|
||||
}
|
||||
}
|
||||
|
||||
function setGpsSatelliteSummary(value, connected) {
|
||||
if (connected && typeof value === "number" && isFinite(value) && value >= 0) {
|
||||
setText("gps-state", String(Math.round(value)) + " Sat");
|
||||
return;
|
||||
}
|
||||
setText("gps-state", "Offline");
|
||||
}
|
||||
|
||||
function updateGpsAccuracyFromDiagnostics() {
|
||||
if (!lastGpsDiagnostics || !lastGpsDiagnostics.connected || !lastGpsDiagnostics.valid) {
|
||||
setGpsAccuracyState("--", "");
|
||||
@@ -674,6 +685,7 @@ function updateGpsAccuracyFromDiagnostics() {
|
||||
|
||||
function updateGpsOverlayFromFix(message) {
|
||||
if (!message) return;
|
||||
markRosFresh();
|
||||
markGpsFresh();
|
||||
|
||||
var hasFix = message.status && message.status.status >= 0;
|
||||
@@ -685,22 +697,35 @@ function updateGpsOverlayFromFix(message) {
|
||||
}
|
||||
|
||||
updateGpsAccuracyFromDiagnostics();
|
||||
if (lastGpsDiagnostics && lastGpsDiagnostics.connected) {
|
||||
setGpsSatelliteSummary(Number(lastGpsDiagnostics.satellites_used || lastGpsDiagnostics.satellites_visible || 0), true);
|
||||
}
|
||||
setText("gps-lat", formatNumber(Number(message.latitude || 0), 5));
|
||||
setText("gps-lon", formatNumber(Number(message.longitude || 0), 5));
|
||||
}
|
||||
|
||||
function updateGpsOverlayFromStatus(text) {
|
||||
var value = String(text || "Offline");
|
||||
markRosFresh();
|
||||
markGpsFresh();
|
||||
setText("gps-state", value);
|
||||
var match = String(text || "").match(/(\d+)\s*Sat/i);
|
||||
if (match) {
|
||||
setGpsSatelliteSummary(Number(match[1]), true);
|
||||
} else if (String(text || "").trim()) {
|
||||
setGpsSatelliteSummary(0, true);
|
||||
}
|
||||
}
|
||||
|
||||
function updateGpsOverlayFromDiagnostics(text) {
|
||||
markRosFresh();
|
||||
markGpsFresh();
|
||||
try {
|
||||
lastGpsDiagnostics = JSON.parse(String(text || "{}"));
|
||||
} catch (error) {
|
||||
lastGpsDiagnostics = null;
|
||||
}
|
||||
if (lastGpsDiagnostics && lastGpsDiagnostics.connected) {
|
||||
setGpsSatelliteSummary(Number(lastGpsDiagnostics.satellites_used || lastGpsDiagnostics.satellites_visible || 0), true);
|
||||
}
|
||||
updateGpsAccuracyFromDiagnostics();
|
||||
}
|
||||
|
||||
@@ -795,14 +820,6 @@ function clearSystemStatusDisplay() {
|
||||
}
|
||||
|
||||
function clearRosLiveDisplay() {
|
||||
setRosStatus("Offline");
|
||||
setText("cam-state", "Offline");
|
||||
setText("cam-host", "--");
|
||||
setText("cam-live-text", "OFFLINE");
|
||||
var liveIndicator = document.getElementById("cam-live-indicator");
|
||||
if (liveIndicator) {
|
||||
liveIndicator.classList.add("is-offline");
|
||||
}
|
||||
setText("gps-state", "Offline");
|
||||
setGpsAccuracyState("--", "");
|
||||
setText("gps-lat", "--");
|
||||
@@ -814,18 +831,18 @@ function clearRosLiveDisplay() {
|
||||
function setPageConnectionState() {
|
||||
var now = Date.now();
|
||||
var apiFresh = pageConnection.apiOk && (now - pageConnection.apiLastAt) < 15000;
|
||||
var rosFresh = !!pageConnection.rosOk;
|
||||
var gpsFresh = pageConnection.gpsLastAt && (now - pageConnection.gpsLastAt) < 12000;
|
||||
var rosSocketOpen = !!(ros && ros.socket && ros.socket.readyState === 1);
|
||||
var rosConnected = rosSocketOpen || !!pageConnection.rosOk;
|
||||
var state = "offline";
|
||||
var cunoTitle = "Cuno offline";
|
||||
|
||||
if (apiFresh && rosFresh) {
|
||||
state = gpsFresh || !pageConnection.gpsLastAt ? "online" : "degraded";
|
||||
} else if (apiFresh || rosFresh) {
|
||||
if (apiFresh && rosConnected) {
|
||||
state = "online";
|
||||
} else if (apiFresh || rosConnected) {
|
||||
state = "degraded";
|
||||
}
|
||||
|
||||
cunoTitle = state === "online" ? "Cuno online" : "Cuno offline";
|
||||
cunoTitle = state === "online" ? "Cuno online" : (state === "degraded" ? "Cuno eingeschränkt" : "Cuno offline");
|
||||
pageConnection.state = state;
|
||||
document.body.classList.toggle("page-connection-online", state === "online");
|
||||
document.body.classList.toggle("page-connection-degraded", state === "degraded");
|
||||
@@ -836,7 +853,7 @@ function setPageConnectionState() {
|
||||
if (!apiFresh) {
|
||||
clearSystemStatusDisplay();
|
||||
}
|
||||
if (!rosFresh) {
|
||||
if (!rosConnected) {
|
||||
clearRosLiveDisplay();
|
||||
}
|
||||
}
|
||||
@@ -851,6 +868,15 @@ function markApiConnection(ok) {
|
||||
|
||||
function markRosConnection(ok) {
|
||||
pageConnection.rosOk = !!ok;
|
||||
if (ok) {
|
||||
pageConnection.rosLastAt = Date.now();
|
||||
}
|
||||
setPageConnectionState();
|
||||
}
|
||||
|
||||
function markRosFresh() {
|
||||
pageConnection.rosOk = true;
|
||||
pageConnection.rosLastAt = Date.now();
|
||||
setPageConnectionState();
|
||||
}
|
||||
|
||||
@@ -859,6 +885,47 @@ function markGpsFresh() {
|
||||
setPageConnectionState();
|
||||
}
|
||||
|
||||
function scheduleRosReconnect() {
|
||||
if (rosReconnectTimer) return;
|
||||
rosReconnectTimer = window.setTimeout(function () {
|
||||
rosReconnectTimer = null;
|
||||
if (!ros || typeof ros.connect !== "function") return;
|
||||
setRosStatus("Verbinde...");
|
||||
try {
|
||||
ros.connect("ws://" + hostUrl + ":9090");
|
||||
} catch (error) {}
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function clearPendingRosDisconnect() {
|
||||
if (!rosDisconnectTimer) return;
|
||||
window.clearTimeout(rosDisconnectTimer);
|
||||
rosDisconnectTimer = null;
|
||||
}
|
||||
|
||||
function scheduleRosDisconnect() {
|
||||
if (rosDisconnectTimer) return;
|
||||
rosDisconnectTimer = window.setTimeout(function () {
|
||||
rosDisconnectTimer = null;
|
||||
var rosSocketOpen = !!(ros && ros.socket && ros.socket.readyState === 1);
|
||||
if (rosSocketOpen) {
|
||||
markRosConnection(true);
|
||||
setRosStatus("Verbunden");
|
||||
return;
|
||||
}
|
||||
markRosConnection(false);
|
||||
setRosStatus("Getrennt");
|
||||
}, 8000);
|
||||
}
|
||||
|
||||
function refreshRosSocketState() {
|
||||
if (!ros || !ros.socket) return;
|
||||
if (ros.socket.readyState === 1) {
|
||||
clearPendingRosDisconnect();
|
||||
markRosConnection(true);
|
||||
}
|
||||
}
|
||||
|
||||
function updateUndervoltageDisplay(text, state) {
|
||||
var el = document.getElementById("stat-undervoltage");
|
||||
if (!el) {
|
||||
@@ -1157,11 +1224,13 @@ window.addEventListener("load", function () {
|
||||
updateClocks();
|
||||
window.setInterval(updateClocks, 1000);
|
||||
fetchSystemStatus();
|
||||
refreshRosSocketState();
|
||||
setPageConnectionState();
|
||||
fetchDriveEstimatorData();
|
||||
renderDriveEstimatorOverlay();
|
||||
renderTrajectoryOverlay();
|
||||
statusTimer = window.setInterval(fetchSystemStatus, 5000);
|
||||
window.setInterval(refreshRosSocketState, 1000);
|
||||
window.setInterval(setPageConnectionState, 1000);
|
||||
window.setInterval(renderDriveEstimatorOverlay, 250);
|
||||
window.setInterval(renderTrajectoryOverlay, 250);
|
||||
@@ -1217,18 +1286,25 @@ window.addEventListener("load", function () {
|
||||
});
|
||||
|
||||
ros.on("connection", function () {
|
||||
if (rosReconnectTimer) {
|
||||
window.clearTimeout(rosReconnectTimer);
|
||||
rosReconnectTimer = null;
|
||||
}
|
||||
clearPendingRosDisconnect();
|
||||
markRosConnection(true);
|
||||
setRosStatus("Verbunden");
|
||||
});
|
||||
|
||||
ros.on("error", function () {
|
||||
markRosConnection(false);
|
||||
setRosStatus("Fehler");
|
||||
setRosStatus("Verbinde...");
|
||||
scheduleRosDisconnect();
|
||||
scheduleRosReconnect();
|
||||
});
|
||||
|
||||
ros.on("close", function () {
|
||||
markRosConnection(false);
|
||||
setRosStatus("Getrennt");
|
||||
setRosStatus("Verbinde...");
|
||||
scheduleRosDisconnect();
|
||||
scheduleRosReconnect();
|
||||
});
|
||||
|
||||
joyListener = new ROSLIB.Topic({
|
||||
@@ -1244,6 +1320,9 @@ window.addEventListener("load", function () {
|
||||
});
|
||||
|
||||
roverCommandListener.subscribe(function (message) {
|
||||
clearPendingRosDisconnect();
|
||||
markRosFresh();
|
||||
setRosStatus("Verbunden");
|
||||
applyDriveMode(locomotionModeToUi(message.locomotion_mode), true);
|
||||
motorsEnabled = !!message.motors_enabled;
|
||||
driveEstimator.motorsEnabled = !!message.motors_enabled;
|
||||
@@ -1261,6 +1340,9 @@ window.addEventListener("load", function () {
|
||||
messageType: "exomy/MotorCommands"
|
||||
});
|
||||
motorCommandsListener.subscribe(function (message) {
|
||||
clearPendingRosDisconnect();
|
||||
markRosFresh();
|
||||
setRosStatus("Verbunden");
|
||||
driveEstimator.motorSpeeds = Array.isArray(message.motor_speeds) ? message.motor_speeds.map(Number) : [0, 0, 0, 0, 0, 0];
|
||||
renderDriveEstimatorOverlay();
|
||||
renderTrajectoryOverlay();
|
||||
@@ -1297,6 +1379,7 @@ window.addEventListener("load", function () {
|
||||
messageType: "sensor_msgs/Joy"
|
||||
});
|
||||
joySubscriber.subscribe(function (message) {
|
||||
clearPendingRosDisconnect();
|
||||
markRosConnection(true);
|
||||
if (message.header.frame_id === "webgui") return;
|
||||
var x = (message.axes[0] || 0);
|
||||
|
||||
Reference in New Issue
Block a user